dts-universal-report-module 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +5759 -5652
- package/dist/index.js +25 -25
- 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
|
-
`)?`"${
|
|
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"),p=require("react"),ks=require("xlsx"),k=require("@mui/icons-material"),r=require("@mui/material"),di=require("react-dom"),Ts=require("@emotion/react"),wt=require("react-dnd"),Xo=require("react-dnd-html5-backend");function ui(t){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(o,n,i.get?i:{enumerable:!0,get:()=>t[n]})}}return o.default=t,Object.freeze(o)}const fo=ui(p),Qr=ui(ks),Ue={sort:{maxLevels:5},filter:{maxConditions:10,allowedOperators:["equals","contains","startsWith","endsWith","gt","lt","gte","lte","isTrue","isFalse","NULL","NOT_NULL"]},columns:{maxVisible:20,minColumnWidth:60,maxColumnWidth:800},grouping:{maxLevels:3,allowNested:!0,allowCollapse:!0},export:{allowedFormats:["csv","excel","json"]},views:{maxViews:10,isAdmin:!1},dates:{displayFormat:null},display:{showDevPanel:!1}},pi="urm_dev_config";function Is(){try{const t=localStorage.getItem(pi);if(!t)return Ue;const o=JSON.parse(t),n={sort:{...Ue.sort,...o.sort},filter:{...Ue.filter,...o.filter},columns:{...Ue.columns,...o.columns},grouping:{...Ue.grouping,...o.grouping},export:{...Ue.export,...o.export},views:{...Ue.views,...o.views},dates:{...Ue.dates,...o.dates},display:{...Ue.display,...o.display}};return n.sort.maxLevels=Math.min(5,Math.max(1,n.sort.maxLevels)),n}catch{return Ue}}function zs(t){try{localStorage.setItem(pi,JSON.stringify(t))}catch{}}function Es(t,o,n){if(!n||!o)return t;const i={sort:{...t.sort,...o.sort},filter:{...t.filter,...o.filter},columns:{...t.columns,...o.columns},grouping:{...t.grouping,...o.grouping},export:{...t.export,...o.export},views:{...t.views,...o.views},dates:{...t.dates,...o.dates},display:{...t.display,...o.display}};return i.sort.maxLevels=Math.min(5,Math.max(1,i.sort.maxLevels)),i}const xi=p.createContext(Ue);function Gt(){return p.useContext(xi)}const Bs=/^\d{4}-\d{2}-\d{2}$/,Ds=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/,Os=/^(\d{1,2})[\/\-\.](\d{1,2})[\/\-\.](\d{2,4})$|^([A-Za-z]+)\s+\d{1,2},?\s+\d{4}$/,As=9783072e5,Ms=41024448e5,_s=978307200,$s=4102444800;function Ws(t){return t==null||t===""?"unknown":typeof t=="number"?Number.isInteger(t)&&t>=As&&t<=Ms?"timestamp_ms":Number.isInteger(t)&&t>=_s&&t<=$s?"timestamp_s":"unknown":typeof t!="string"?"unknown":Ds.test(t)||Bs.test(t)?"iso":Os.test(t.trim())?"locale_string":"unknown"}function Rs(t,o){const n=o.map(d=>d[t]).filter(d=>d!=null&&d!=="");if(n.length===0)return"unknown";const i={iso:0,timestamp_ms:0,timestamp_s:0,locale_string:0,unknown:0};for(const d of n){const l=Ws(d);i[l]++}const s=n.length,c=.7;for(const d of["iso","timestamp_ms","timestamp_s","locale_string"])if(i[d]/s>=c)return d;return"unknown"}function Ps(t,o){if(t==null||t==="")return null;try{switch(o){case"timestamp_ms":{const n=new Date(Number(t));return isNaN(n.getTime())?null:n}case"timestamp_s":{const n=new Date(Number(t)*1e3);return isNaN(n.getTime())?null:n}case"iso":{const n=new Date(String(t));return isNaN(n.getTime())?null:n}case"locale_string":{const n=new Date(String(t));return isNaN(n.getTime())?null:n}default:return null}}catch{return null}}const mn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Ns=["January","February","March","April","May","June","July","August","September","October","November","December"];function Oe(t){return String(t).padStart(2,"0")}function Ls(t){const o=Date.now()-t.getTime(),n=Math.abs(o),i=o>0,s=Math.floor(n/1e3),c=Math.floor(s/60),d=Math.floor(c/60),l=Math.floor(d/24),u=Math.floor(l/7),m=Math.floor(l/30),h=Math.floor(l/365);let b;return s<60?b="just now":c<60?b=`${c} minute${c!==1?"s":""}`:d<24?b=`${d} hour${d!==1?"s":""}`:l<7?b=`${l} day${l!==1?"s":""}`:u<5?b=`${u} week${u!==1?"s":""}`:m<12?b=`${m} month${m!==1?"s":""}`:b=`${h} year${h!==1?"s":""}`,s<60?b:i?`${b} ago`:`in ${b}`}function Fs(t,o){const n=t.getFullYear(),i=t.getMonth(),s=t.getDate(),c=t.getHours(),d=t.getMinutes();switch(o){case"YYYY-MM-DD":return`${n}-${Oe(i+1)}-${Oe(s)}`;case"DD/MM/YYYY":return`${Oe(s)}/${Oe(i+1)}/${n}`;case"MM/DD/YYYY":return`${Oe(i+1)}/${Oe(s)}/${n}`;case"MMM DD, YYYY":return`${mn[i]} ${Oe(s)}, ${n}`;case"DD MMM YYYY":return`${Oe(s)} ${mn[i]} ${n}`;case"MMMM D, YYYY":return`${Ns[i]} ${s}, ${n}`;case"YYYY-MM-DD HH:mm":return`${n}-${Oe(i+1)}-${Oe(s)} ${Oe(c)}:${Oe(d)}`;case"DD/MM/YYYY HH:mm":return`${Oe(s)}/${Oe(i+1)}/${n} ${Oe(c)}:${Oe(d)}`;case"MM/DD/YYYY HH:mm":return`${Oe(i+1)}/${Oe(s)}/${n} ${Oe(c)}:${Oe(d)}`;case"relative":return Ls(t);case"locale":return t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});default:return t.toLocaleDateString()}}function Vs(t,o,n){if(!n||o==="unknown")return String(t);const i=Ps(t,o);return!i||isNaN(i.getTime())?String(t):Fs(i,n)}function Hs(t){return t==null?"null":Array.isArray(t)?"array":typeof t=="object"?"object":typeof t=="number"?"number":typeof t=="boolean"?"boolean":typeof t=="string"?"string":"mixed"}function mi(t,o="",n=0){if(n>2)return{[o]:t};const i={};for(const s of Object.keys(t)){const c=o?`${o}.${s}`:s,d=t[s];d!==null&&typeof d=="object"&&!Array.isArray(d)&&n<2?Object.assign(i,mi(d,c,n+1)):i[c]=d}return i}function ao(t){return t.map(o=>typeof o!="object"||o===null||Array.isArray(o)?o:mi(o))}function Wr(t){if(!Array.isArray(t)||t.length===0)return[];const o=ao(t),n=new Set;o.forEach(d=>{typeof d=="object"&&d!==null&&Object.keys(d).forEach(l=>n.add(l))});const i=[];n.forEach(d=>{const l=new Set;let u=0;o.forEach(f=>{typeof f=="object"&&f!==null&&d in f&&(u++,l.add(Hs(f[d])))});const m=u===o.length,h=l.size>1&&!l.has("null");let b="mixed";if(l.size===1)b=Array.from(l)[0];else if(l.size===2&&l.has("null")){const f=Array.from(l).filter(g=>g!=="null");f.length===1&&(b=f[0])}i.push({name:d,type:b,required:m,hasConflict:h})});const c=o.slice(0,50);for(const d of i){if(d.type!=="string"&&d.type!=="number")continue;const l=Rs(d.name,c);l!=="unknown"&&(d.type="date",d.dateFormat=l)}return i}function Us(t){return t.some(o=>o.hasConflict)}function Ge(t){if(!t)return"";const n=t.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return n.charAt(0).toUpperCase()+n.slice(1)}function fn(t){return t==null}function Ys(t){return(o,n,i)=>{const s=fn(o),c=fn(n);if(s&&c)return 0;if(s)return 1;if(c)return-1;let d=0;switch(t){case"number":const l=Number(o),u=Number(n);d=l-u;break;case"boolean":d=(o?1:0)-(n?1:0);break;case"string":d=String(o).localeCompare(String(n));break;case"array":case"object":d=JSON.stringify(o).localeCompare(JSON.stringify(n));break;case"mixed":case"null":default:d=String(o).localeCompare(String(n));break}return i==="asc"?d:-d}}function Gs(t,o,n){if(!n||n.length===0)return t;const i=[...n].sort((s,c)=>s.priority-c.priority);return[...t].sort((s,c)=>{for(const d of i){const l=o.find(h=>h.name===d.column);if(!l)continue;const m=Ys(l.type)(s[d.column],c[d.column],d.direction);if(m!==0)return m}return 0})}function qs(t){return t===null?"asc":t==="asc"?"desc":null}function Js(t){return t==="string"||t==="boolean"}function Ks(t){return t.filter(o=>Js(o.type))}function Xs(t,o){const n={};return o.forEach(i=>{if(i.type==="number"){const s=t.map(c=>c[i.name]).filter(c=>typeof c=="number");s.length>0&&(n[i.name]=s.reduce((c,d)=>c+d,0))}}),n}function Zs(t,o,n){if(!n.enabled||n.levels.length===0)return t;const i=fi(t,n.levels,o);return hi(i,n.collapsedGroups||[])}function fi(t,o,n,i="",s=0){if(s>=o.length)return t;const c=o[s].column,d=new Map;t.forEach(m=>{const h=m[c],b=h==null?"(empty)":String(h);d.has(b)||d.set(b,[]),d.get(b).push(m)});const l=[];return Array.from(d.keys()).sort().forEach(m=>{const h=d.get(m),b=`${c}:${m}`,f=i?`${i}|${b}`:b,g=Xs(h,n),T=s<o.length-1?fi(h,o,n,f,s+1):h,y={key:f,level:s,column:c,value:m,rowCount:h.length,aggregates:g,children:T};l.push(y)}),l}function hi(t,o,n=[]){for(const i of t)if("key"in i&&"level"in i&&"children"in i){const s=o.includes(i.key);n.push({isGroupHeader:!0,groupKey:i.key,groupLevel:i.level,groupColumn:i.column,groupValue:i.value,rowCount:i.rowCount,aggregates:i.aggregates,isCollapsed:s}),!s&&i.children&&hi(i.children,o,n)}else n.push(i);return n}function Qs(t,o){const n=t.collapsedGroups||[],i=n.includes(o)?n.filter(s=>s!==o):[...n,o];return{...t,collapsedGroups:i}}function gi(t,o){return t==null?"":typeof t=="number"?`Σ ${t.toLocaleString()}`:String(t)}function yi(t,o,n){return`${o}: ${n}`}function Fr(t,o){if(!o||!o.enabled||!o.levels||o.levels.length===0)return[...t];const n=o.levels.map(s=>s.column),i=t.filter(s=>!n.includes(s));return[...n,...i]}function bi(t,o,n){if(!o||!o.enabled||!o.levels||o.levels.length===0)return[...t];const i=o.levels.map(c=>c.column),s=t.filter(c=>!i.includes(c));if(n){const c=[],d=new Set(i),l=new Set(s);let u=0;for(const m of n)d.has(m)?c.push(m):l.has(m)&&u<s.length?(c.push(s[u]),u++):l.has(m)||c.push(m);for(let m=u;m<s.length;m++)c.includes(s[m])||c.push(s[m]);return c}return[...t]}function Mo(t){const o={},n=[],i={};return t.forEach(s=>{o[s.name]=!0,n.push(s.name),i[s.name]=150}),{id:"default-view",name:"Default View",description:"Unfiltered, unsorted baseline view",isDefault:!0,snapshot:{filters:[],sortStack:[],columnVisibility:o,columnOrder:n,columnWidths:i,grouping:null}}}function ea(t,o,n,i,s,c,d,l){const u={},m=[],h={};n.forEach(g=>{u[g.name]=!0,m.push(g.name),h[g.name]=150});const f=bi(s||m,d||null,l||m);return{filters:t||[],sortStack:o||[],columnVisibility:i||u,columnOrder:f,columnWidths:c||h,grouping:d||null}}function ta(t,o){const n=u=>{if(u==null)return u;if(Array.isArray(u))return u.map(m=>n(m));if(typeof u=="object"){const m={};return Object.keys(u).sort().forEach(h=>{m[h]=n(u[h])}),m}return u},i=u=>JSON.stringify(n(u));if(i(t.filters)!==i(o.filters)||i(t.sortStack)!==i(o.sortStack)||i(t.columnVisibility)!==i(o.columnVisibility))return!0;const s=[...t.columnOrder||[]].sort().join(","),c=[...o.columnOrder||[]].sort().join(",");if(s!==c)return!1;const d=[...o.columnOrder||[]].sort().join(",");if((o.columnOrder||[]).join(",")!==d){if((t.columnOrder||[]).join(",")!==(o.columnOrder||[]).join(","))return!0}else{const u=[...t.columnOrder||[]].sort().join(",");if((t.columnOrder||[]).join(",")!==u)return!0}return i(t.columnWidths)!==i(o.columnWidths)||i(t.grouping)!==i(o.grouping)}function ra(t){return!t||t.length===0?"None":t.sort((o,n)=>o.priority-n.priority).map(o=>`${o.column} ${o.direction==="asc"?"↑":"↓"}`).join(", ")}function oa(t,o){var y,w,v;const n=[],i=JSON.stringify(t.filters),s=JSON.stringify(o.filters);if(i!==s){const j=t.filters.length,S=o.filters.length;j>S?n.push({category:"filters",label:"Filters Added",description:`${j-S} new filter${j-S>1?"s":""} added`}):j<S?n.push({category:"filters",label:"Filters Removed",description:`${S-j} filter${S-j>1?"s":""} removed`}):n.push({category:"filters",label:"Filters Modified",description:"Filter conditions have been changed"})}const c=JSON.stringify(t.sortStack),d=JSON.stringify(o.sortStack);if(c!==d){const j=t.sortStack.length,S=o.sortStack.length;j>S?n.push({category:"sorting",label:"Sorting Added",description:`${j-S} new sort rule${j-S>1?"s":""} added`}):j<S?n.push({category:"sorting",label:"Sorting Removed",description:`${S-j} sort rule${S-j>1?"s":""} removed`}):n.push({category:"sorting",label:"Sorting Modified",description:"Sort rules or order have been changed"})}const l=JSON.stringify(t.columnVisibility),u=JSON.stringify(o.columnVisibility);if(l!==u){const j=Object.values(t.columnVisibility).filter(I=>I).length,S=Object.values(o.columnVisibility).filter(I=>I).length;j>S?n.push({category:"visibility",label:"Columns Shown",description:`${j-S} column${j-S>1?"s":""} made visible`}):j<S?n.push({category:"visibility",label:"Columns Hidden",description:`${S-j} column${S-j>1?"s":""} hidden`}):n.push({category:"visibility",label:"Column Visibility Changed",description:"Column visibility settings have been modified"})}const m=JSON.stringify(t.columnOrder),h=JSON.stringify(o.columnOrder);m!==h&&n.push({category:"order",label:"Column Order Changed",description:"Columns have been reordered"});const b=JSON.stringify(t.columnWidths),f=JSON.stringify(o.columnWidths);if(b!==f){const j=Object.keys(t.columnWidths).filter(S=>t.columnWidths[S]!==o.columnWidths[S]).length;n.push({category:"widths",label:"Column Widths Adjusted",description:`${j} column width${j>1?"s":""} modified`})}const g=JSON.stringify(t.grouping),T=JSON.stringify(o.grouping);if(g!==T){const j=(y=t.grouping)==null?void 0:y.enabled,S=(w=o.grouping)==null?void 0:w.enabled;if(j&&!S){const I=((v=t.grouping)==null?void 0:v.levels.length)||0;n.push({category:"grouping",label:"Grouping Applied",description:`${I} grouping level${I>1?"s":""} added`})}else!j&&S?n.push({category:"grouping",label:"Grouping Removed",description:"All grouping has been cleared"}):n.push({category:"grouping",label:"Grouping Modified",description:"Grouping configuration has been changed"})}return n}function hn(){try{return localStorage.getItem("urm:debug")==="true"}catch{return!1}}function gn(t){return`[${t}]`}const Ut={warn(t,o,...n){hn()&&console.warn(gn(t),o,...n)},error(t,o,...n){hn()&&console.error(gn(t),o,...n)}},vi="urm_report_";function na(t,o){try{const n=`${vi}${t}`;localStorage.setItem(n,JSON.stringify(o))}catch(n){Ut.error("urm:persistence","Failed to save report state",n)}}function ia(t){try{const o=`${vi}${t}`,n=localStorage.getItem(o);return n?JSON.parse(n):null}catch(o){return Ut.error("urm:persistence","Failed to load report state",o),null}}function ho(t,o,n=0){const i=[];for(const s of t){const c=o.includes(s.key);if(i.push({type:"group",key:s.key,level:n,column:s.column,value:s.value,rowCount:s.rowCount,aggregates:s.aggregates,collapsed:c}),!c&&s.children&&s.children.length>0){const d=s.children[0];if(sa(d)){const l=s.children,u=ho(l,o,n+1);i.push(...u)}else{const l=s.children;for(const u of l)i.push({type:"row",parentGroupKey:s.key,level:n+1,data:u})}}}return i}function sa(t){return t&&typeof t=="object"&&"key"in t&&"level"in t&&"column"in t&&"value"in t&&"rowCount"in t&&"aggregates"in t&&"children"in t}function Zo(t){return t.filter(o=>o.type==="row").map(o=>o.type==="row"?o.data:null).filter(o=>o!==null)}function Qo(t,o){const n=new Date,i=n.getFullYear(),s=String(n.getMonth()+1).padStart(2,"0"),c=String(n.getDate()).padStart(2,"0"),d=`${i}-${s}-${c}`;return`${t.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")}_${d}.${o}`}function co(t,o,n,i,s,c,d){let l,u;c?(l={...c},u=d||o.map(h=>h.name)):s?(l={...s.snapshot.columnVisibility},u=d||[...s.snapshot.columnOrder]):(l={},u=[],o.forEach(h=>{l[h.name]=!0,u.push(h.name)}));const m=Object.entries(l).filter(([h,b])=>!b).map(([h,b])=>h);return{data:t,schema:o,appliedFilters:n,appliedSortStack:i,columnVisibility:l,columnOrder:u,grouping:(s==null?void 0:s.snapshot.grouping)??null,hiddenColumns:m,viewMeta:s?{id:s.id,name:s.name,isDefault:s.isDefault}:void 0}}function uo(t,o="export",n){const{data:i,columnOrder:s,grouping:c}=t,d=s.filter(b=>t.columnVisibility[b]);let l;if(c&&c.enabled){const b=ho(i);l=Zo(b)}else l=i;const u=d.join(","),m=l.map(b=>d.map(f=>{const g=b[f];if(g==null)return"";const T=String(g);return T.includes(",")||T.includes('"')||T.includes(`
|
|
2
|
+
`)?`"${T.replace(/"/g,'""')}"`:T}).join(",")),h=[u,...m].join(`
|
|
3
|
+
`);Si(h,Qo(o,"csv"),"text/csv;charset=utf-8;")}function po(t,o="export",n){const{data:i,columnOrder:s,grouping:c}=t,d=s.filter(b=>t.columnVisibility[b]);let l;if(c&&c.enabled){const b=ho(i);l=Zo(b)}else l=i;const u=[d,...l.map(b=>d.map(f=>b[f]??""))],m=Qr.utils.aoa_to_sheet(u),h=Qr.utils.book_new();Qr.utils.book_append_sheet(h,m,"Data"),Qr.writeFile(h,Qo(o,"xlsx"))}function xo(t,o="export",n){const{data:i,appliedFilters:s,appliedSortStack:c,viewMeta:d,hiddenColumns:l,columnOrder:u,grouping:m}=t;let h;if(m&&m.enabled){const g=ho(i);h=Zo(g)}else h=i;const b={meta:{exportedAt:new Date().toISOString(),reportName:o,view:(d==null?void 0:d.name)||"Default View",filters:s.map(g=>({field:g.column,operator:g.operator,value:g.value})),sortStack:c.map(g=>({field:g.column,direction:g.direction,priority:g.priority})),grouping:m||{},hiddenColumns:l,columnOrder:u,exportConfig:n||{scope:"visible"}},data:h},f=JSON.stringify(b,null,2);Si(f,Qo(o,"json"),"application/json;charset=utf-8;")}function Si(t,o,n){const i=new Blob([t],{type:n}),s=URL.createObjectURL(i),c=document.createElement("a");c.href=s,c.download=o,document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(s)}const yn=10;function aa(t,o){const n=o.trim();if(!n)return t;const i=t.findIndex(c=>c.query.toLowerCase()===n.toLowerCase());let s;return i!==-1?s=[{...t[i],lastUsed:Date.now()},...t.slice(0,i),...t.slice(i+1)]:s=[{query:n,isFavourite:!1,lastUsed:Date.now()},...t],s.length>yn&&(s=[...s].sort((d,l)=>d.isFavourite&&!l.isFavourite?-1:!d.isFavourite&&l.isFavourite?1:l.lastUsed-d.lastUsed).slice(0,yn)),s}function la(t,o){return t.map(n=>n.query===o?{...n,isFavourite:!n.isFavourite}:n)}function ca(t,o){return t.filter(n=>n.query!==o)}function da(t){const o=t.filter(i=>i.isFavourite).sort((i,s)=>s.lastUsed-i.lastUsed),n=t.filter(i=>!i.isFavourite).sort((i,s)=>s.lastUsed-i.lastUsed);return[...o,...n]}const ua={owner:["view_report","edit_columns","edit_filters","edit_sorting","edit_views","create_views","delete_views","delete_report","export_data","promote_global_view"],editor:["view_report","edit_columns","edit_filters","edit_sorting","edit_views","create_views","delete_views","export_data"],viewer:["view_report","export_data"]};function pa(t,o){return!t||t.owner===o?"owner":t.editors.includes(o)?"editor":(t.viewers.includes(o),"viewer")}function pt(t,o){return ua[o].includes(t)}function xt(t){return`You do not have permission to ${{view_report:"view this report",edit_columns:"modify columns",edit_filters:"modify filters",edit_sorting:"modify sorting",edit_views:"edit views",create_views:"create views",delete_views:"delete views",delete_report:"delete this report",export_data:"export data",promote_global_view:"promote views to global"}[t]||"perform this action"}.`}function xa(t){return t==="viewer"}const bn=1e3;function Uo(t){return t&&t.charAt(0).toUpperCase()+t.slice(1)}function ht(t){if(!t)return"";const n=t.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return Uo(n)}const ma={equals:"equals",contains:"contains",startsWith:"starts with",endsWith:"ends with",gt:"is greater than",lt:"is less than",gte:"is greater than or equal to",lte:"is less than or equal to",isTrue:"is true",isFalse:"is false",NULL:"is empty",NOT_NULL:"is not empty"};function _o(t){if(!t||!t.column)return"a filter";const o=ht(t.column),n=ma[t.operator]??t.operator;return["isTrue","isFalse","NULL","NOT_NULL"].includes(t.operator)?`"${o}" ${n}`:`"${o}" ${n} "${t.value}"`}function vn(t){return!t||!t.enabled||t.levels.length===0?"grouping removed":`grouped by ${t.levels.map(n=>`"${ht(n.column)}"`).join(", ")}`}function fa(t){var s,c,d;const{action:o,previousState:n,newState:i}=t;switch(o){case"filter_added":{const l=i&&Array.isArray(i)?i[i.length-1]:i;return{summary:`Filter added: ${_o(l)}`}}case"filter_removed":return{summary:`Filter removed: ${_o(n)}`};case"filter_updated":{const l=n,u=i;return(l==null?void 0:l.column)!==(u==null?void 0:u.column)?{summary:`Filter changed on "${ht(u==null?void 0:u.column)}"`,detail:`Previously filtered "${ht(l==null?void 0:l.column)}"`}:{summary:`Filter updated: ${_o(u)}`}}case"filter_cleared":{const l=Array.isArray(n)?n.length:0;return{summary:l>0?`All filters cleared (${l} filter${l!==1?"s":""} removed)`:"All filters cleared"}}case"sort_level_added":{const l=i!=null&&i.column?ht(i.column):"",u=(i==null?void 0:i.direction)==="asc"?"ascending":"descending";return{summary:l?`Sort added: "${l}" ${u}`:"Sort level added"}}case"sort_level_removed":{const l=n!=null&&n.column?ht(n.column):"";return{summary:l?`Sort removed: "${l}"`:"Sort level removed"}}case"sort_reordered":return{summary:"Sort order changed"};case"sort_cleared":return{summary:"All sorting cleared"};case"group_level_added":return{summary:`Grouping applied: ${vn(i)}`};case"group_level_removed":{const l=n,u=(c=(s=l==null?void 0:l.levels)==null?void 0:s[0])!=null&&c.column?ht(l.levels[0].column):"";return{summary:u?`Group level removed: "${u}"`:"Group level removed"}}case"group_reordered":return{summary:`Grouping updated: ${vn(i)}`};case"group_cleared":return{summary:"Grouping removed"};case"column_hidden":{const l=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:l?`Column hidden: "${ht(l)}"`:"Column hidden"}}case"column_shown":{const l=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:l?`Column shown: "${ht(l)}"`:"Column made visible"}}case"column_reordered":{const l=Array.isArray(n)?n:[],u=Array.isArray(i)?i:[];return l.length>0&&u.length>0?{summary:"Column order changed",detail:`${u.length} column${u.length!==1?"s":""} reordered`}:{summary:"Columns reordered"}}case"column_resized":{const l=(i==null?void 0:i.column)??"",u=(i==null?void 0:i.width)??"";return{summary:l?`Column resized: "${ht(l)}"`:"Column resized",detail:u?`New width: ${u}px`:void 0}}case"view_created":{const l=(i==null?void 0:i.name)??(i==null?void 0:i.viewName)??"";return{summary:l?`View created: "${l}"`:"New view created"}}case"view_updated":{const l=(i==null?void 0:i.name)??(n==null?void 0:n.name)??"";return{summary:l?`View updated: "${l}"`:"View updated"}}case"view_deleted":{const l=(n==null?void 0:n.name)??(n==null?void 0:n.viewName)??"";return{summary:l?`View deleted: "${l}"`:"View deleted"}}case"view_set_default":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Default view set to "${l}"`:"Default view changed"}}case"view_switched":{const l=(n==null?void 0:n.name)??"",u=(i==null?void 0:i.name)??"";return l&&u?{summary:`Switched to view "${u}"`,detail:`From "${l}"`}:u?{summary:`Switched to view "${u}"`}:{summary:"View switched"}}case"export_csv":case"export_excel":case"export_json":{const l=o==="export_csv"?"CSV":o==="export_excel"?"Excel":"JSON",u=i==null?void 0:i.rowCount,m=(i==null?void 0:i.scope)==="all"?"all rows":"filtered rows",h=(i==null?void 0:i.viewName)??"",b=typeof u=="number"?` (${u.toLocaleString()} rows)`:"";return{summary:`Exported as ${l}${b}`,detail:h?`${Uo(m)} · View: "${h}"`:Uo(m)}}case"export_triggered":{const l=((d=i==null?void 0:i.format)==null?void 0:d.toUpperCase())??"";return{summary:l?`Export triggered: ${l}`:"Export triggered"}}case"preset_created":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset created: "${l}"`:"New preset created"}}case"preset_applied":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset applied: "${l}"`:"Preset applied"}}case"preset_deleted":{const l=(n==null?void 0:n.name)??"";return{summary:l?`Preset deleted: "${l}"`:"Preset deleted"}}case"preset_link_copied":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset link copied: "${l}"`:"Preset link copied to clipboard"}}case"theme_changed":{const l=typeof n=="string"?n:(n==null?void 0:n.theme)??"",u=typeof i=="string"?i:(i==null?void 0:i.theme)??"";return l&&u?{summary:`Theme changed from "${l}" to "${u}"`}:u?{summary:`Theme changed to "${u}"`}:{summary:"Theme changed"}}case"error_occurred":{const l=(i==null?void 0:i.message)??(i==null?void 0:i.error)??typeof i=="string"?i:"";return{summary:"An error was recorded",detail:l?`Details: ${String(l).slice(0,120)}`:void 0}}default:return{summary:ga(o)}}}function ha(){return`EVT_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function ji(t,o,n,i,s,c){return{id:ha(),user:o,reportId:t,feature:n,action:i,timestamp:new Date().toISOString(),previousState:s,newState:c}}function Ci(t,o){const n=[o,...t];return n.length>bn?n.slice(0,bn):n}function ga(t){return{filter_added:"Filter Added",filter_removed:"Filter Removed",filter_updated:"Filter Updated",filter_cleared:"All Filters Cleared",sort_level_added:"Sort Level Added",sort_level_removed:"Sort Level Removed",sort_reordered:"Sort Reordered",sort_cleared:"All Sorting Cleared",group_level_added:"Group Level Added",group_level_removed:"Group Level Removed",group_reordered:"Group Reordered",group_cleared:"All Grouping Cleared",column_hidden:"Column Hidden",column_shown:"Column Shown",column_reordered:"Columns Reordered",column_resized:"Column Resized",view_created:"View Created",view_updated:"View Updated",view_deleted:"View Deleted",view_set_default:"View Set as Default",view_switched:"View Switched",theme_changed:"Theme Changed",export_triggered:"Export Triggered",export_csv:"Exported as CSV",export_excel:"Exported as Excel",export_json:"Exported as JSON",preset_created:"Preset Created",preset_applied:"Preset Applied",preset_deleted:"Preset Deleted",preset_link_copied:"Preset Link Copied",error_occurred:"Error Occurred"}[t]||t}function ya(t){return{filters:"Filters",sorting:"Sorting",grouping:"Grouping",columns:"Columns",views:"Views",theme:"Theme",export:"Export",presets:"Presets",system:"System"}[t]||t}function ba(t){return{filters:"#1976d2",sorting:"#7b1fa2",grouping:"#2e7d32",columns:"#e65100",views:"#c2185b",theme:"#546e7a",export:"#00838f",presets:"#303f9f",system:"#c62828"}[t]||"#546e7a"}function va(t){const o=new Date(t),i=new Date().getTime()-o.getTime(),s=Math.floor(i/6e4),c=Math.floor(i/36e5),d=Math.floor(i/864e5);return s<1?"Just now":s<60?`${s} minute${s>1?"s":""} ago`:c<24?`${c} hour${c>1?"s":""} ago`:d<7?`${d} day${d>1?"s":""} ago`:o.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}const Sn=100;function Sa(){return`preset_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function ja(t){var c;const o=(c=t.views)==null?void 0:c.find(d=>d.id===t.activeViewId),n=o==null?void 0:o.snapshot.columnOrder,i=t.columnOrder||[],s=bi(i,t.grouping||null,n);return{filters:t.filters?[...t.filters]:[],sortStack:t.sortStack?[...t.sortStack]:[],columnVisibility:t.columnVisibility?{...t.columnVisibility}:{},columnOrder:s,columnWidths:t.columnWidths?{...t.columnWidths}:{},grouping:t.grouping?{...t.grouping}:null,activeViewId:t.activeViewId}}function Ca(t,o,n,i){return{id:Sa(),name:t,description:o,createdBy:n,createdAt:Date.now(),config:i}}function wa(t,o){const n=t||[];if(n.length>=Sn)throw new Error(`Maximum of ${Sn} presets reached. Please delete old presets first.`);return[...n,o]}function ka(t,o){return(t||[]).filter(i=>i.id!==o)}function jn(t,o){if(t)return t.find(n=>n.id===o)}function Ta(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("preset")}function Ia(t){const o=t.columnOrder,n=Fr(o,t.grouping);return{filters:t.filters.length>0?[...t.filters]:void 0,sortStack:t.sortStack.length>0?[...t.sortStack]:void 0,columnVisibility:{...t.columnVisibility},columnOrder:n,columnWidths:{...t.columnWidths},grouping:t.grouping?{...t.grouping}:null,activeViewId:t.activeViewId}}function za(t,o){return{totalRows:t.length,totalColumns:o.length}}const Ea={MAX_CACHE_ENTRIES:3};function Ba(t,o){let n=null;return function(...s){const c=()=>{n=null,t(...s)};n&&clearTimeout(n),n=setTimeout(c,o)}}class eo{constructor(o=Ea.MAX_CACHE_ENTRIES){this.cache=new Map,this.maxEntries=o}get(o){const n=this.cache.get(o);return n?n.value:null}set(o,n){var i;if(this.cache.size>=this.maxEntries&&!this.cache.has(o)){const s=(i=Array.from(this.cache.entries()).sort((c,d)=>c[1].timestamp-d[1].timestamp)[0])==null?void 0:i[0];s&&this.cache.delete(s)}this.cache.set(o,{key:o,value:n,timestamp:Date.now()})}has(o){return this.cache.has(o)}clear(){this.cache.clear()}size(){return this.cache.size}}class Da{constructor(){this.metrics=new Map}start(o){this.metrics.set(o,performance.now())}end(o){const n=this.metrics.get(o);if(!n)return 0;const i=performance.now()-n;return this.metrics.delete(o),i}measure(o,n){this.start(o);const i=n(),s=this.end(o);return{result:i,duration:s}}async measureAsync(o,n){this.start(o);const i=await n(),s=this.end(o);return{result:i,duration:s}}}function Ct(t,o,n,i){const s=n instanceof Error?n.message:n,c={type:t,context:o,message:s,details:i,timestamp:Date.now(),recoverable:Oa(t,o)};return process.env.NODE_ENV==="development"&&Ut.error("urm:error-handling","[Report Error]",{type:t,context:o,message:s,details:i}),c}function Oa(t,o){return t==="ui"||t==="processing"&&["filters","sorting","grouping","columns"].includes(o)?!0:t!=="system"}function Aa(t){const n={filters:"There was an issue applying filters",sorting:"Sorting could not be applied",grouping:"Grouping configuration failed",columns:"Column configuration could not be updated",views:"View operation failed",presets:"Preset could not be applied",export:"Export failed",upload:"File upload failed",search:"Search operation failed"}[t.context]||"An error occurred";return t.recoverable?`${n}. Your previous state has been restored.`:`${n}. Please refresh the page.`}function Ma(t){return{filters:t.filters?[...t.filters]:void 0,sortStack:t.sortStack?[...t.sortStack]:void 0,grouping:t.grouping?{...t.grouping}:void 0,columnVisibility:t.columnVisibility?{...t.columnVisibility}:void 0,columnOrder:t.columnOrder?[...t.columnOrder]:void 0,columnWidths:t.columnWidths?{...t.columnWidths}:void 0,activeViewId:t.activeViewId}}function _a(t,o,n){n(t.id,{filters:o.filters,sortStack:o.sortStack,grouping:o.grouping,columnVisibility:o.columnVisibility,columnOrder:o.columnOrder,columnWidths:o.columnWidths,activeViewId:o.activeViewId})}function $a(t,o,n){return["equals","contains","starts_with","ends_with","gt","gte","lt","lte"].includes(o)&&(n==null||n==="")?{isValid:!1,errorMessage:"Value is required for this operator"}:t==="number"&&["gt","gte","lt","lte","equals"].includes(o)&&isNaN(Number(n))?{isValid:!1,errorMessage:"Value must be a valid number"}:t==="date"&&n&&isNaN(Date.parse(n))?{isValid:!1,errorMessage:"Value must be a valid date"}:{isValid:!0}}function wi(t,o){const n=[],i=[],s=new Set(o.map(c=>c.name));return t.forEach(c=>{s.has(c.column)?n.push(c):i.push(c.column)}),{validRules:n,invalidColumns:i}}function ki(t,o){if(!t||!t.levels||t.levels.length===0)return{validGrouping:null,invalidColumns:[]};const n=new Set(o.map(c=>c.name)),i=[],s=[];return t.levels.forEach(c=>{n.has(c.column)?i.push(c):s.push(c.column)}),i.length===0?{validGrouping:null,invalidColumns:s}:{validGrouping:{...t,levels:i},invalidColumns:s}}function Wa(t,o){const n=[],i=new Set(o.map(c=>c.name)),s={...t};if(s.filters&&Array.isArray(s.filters)){const c=s.filters.filter(d=>{const l=i.has(d.column);return l||n.push(`Filter for column "${d.column}" ignored (column not found)`),l});s.filters=c.length>0?c:void 0}if(s.sortStack&&Array.isArray(s.sortStack)){const{validRules:c,invalidColumns:d}=wi(s.sortStack,o);d.length>0&&n.push(`Sort rules for columns ignored: ${d.join(", ")}`),s.sortStack=c.length>0?c:void 0}if(s.grouping){const{validGrouping:c,invalidColumns:d}=ki(s.grouping,o);d.length>0&&n.push(`Grouping for columns ignored: ${d.join(", ")}`),s.grouping=c}if(s.columnVisibility){const c={};Object.entries(s.columnVisibility).forEach(([d,l])=>{i.has(d)?c[d]=l:n.push(`Column visibility for "${d}" ignored (column not found)`)}),s.columnVisibility=Object.keys(c).length>0?c:void 0}if(s.columnOrder&&Array.isArray(s.columnOrder)){const c=s.columnOrder.filter(d=>{const l=i.has(d);return l||n.push(`Column "${d}" in order ignored (column not found)`),l});s.columnOrder=c.length>0?c:void 0}if(s.columnWidths){const c={};Object.entries(s.columnWidths).forEach(([d,l])=>{i.has(d)?c[d]=l:n.push(`Column width for "${d}" ignored (column not found)`)}),s.columnWidths=Object.keys(c).length>0?c:void 0}return{sanitizedConfig:s,warnings:n}}function Ra(t,o){return Ct("processing","export",t,{retryAvailable:!!(o!=null&&o.onRetry)})}function Cn(t,o,n,i){const s=ji(t,o,"system","error_occurred",null,{errorType:n.type,errorContext:n.context,errorMessage:n.message,recoverable:n.recoverable,timestamp:n.timestamp});return Ci(i||[],s)}function Pa(t){return t==null}function Na(t,o){const{operator:n,value:i}=o;if(n==="NULL")return t==null;if(n==="NOT_NULL")return t!=null;if(Pa(t))return!1;switch(n){case"equals":return String(t)===String(i);case"contains":return String(t).toLowerCase().includes(String(i).toLowerCase());case"startsWith":return String(t).toLowerCase().startsWith(String(i).toLowerCase());case"endsWith":return String(t).toLowerCase().endsWith(String(i).toLowerCase());case"gt":return Number(t)>Number(i);case"lt":return Number(t)<Number(i);case"gte":return Number(t)>=Number(i);case"lte":return Number(t)<=Number(i);case"isTrue":return t===!0;case"isFalse":return t===!1;default:return!0}}function La(t,o){return!o||o.length===0?t:t.filter(n=>o.every(i=>Na(n[i.column],i)))}function wn(t){switch(t){case"string":return[{value:"equals",label:"Equals"},{value:"contains",label:"Contains"},{value:"startsWith",label:"Starts with"},{value:"endsWith",label:"Ends with"},{value:"NULL",label:"Is NULL"},{value:"NOT_NULL",label:"Is NOT NULL"}];case"number":return[{value:"equals",label:"="},{value:"gt",label:">"},{value:"lt",label:"<"},{value:"gte",label:"≥"},{value:"lte",label:"≤"}];case"boolean":return[{value:"isTrue",label:"Is true"},{value:"isFalse",label:"Is false"},{value:"NULL",label:"Is NULL"},{value:"NOT_NULL",label:"Is NOT NULL"}];case"mixed":case"null":case"array":case"object":default:return[]}}function to(t){return t!=="isTrue"&&t!=="isFalse"&&t!=="NULL"&&t!=="NOT_NULL"}function Fa({data:t,filters:o}){return{filteredData:p.useMemo(()=>!o||o.length===0?t:La(t,o),[t,o])}}function Va(t,o,n,i){if(!n||n.trim()==="")return t;const s=n.toLowerCase().trim(),c=o.filter(d=>i.includes(d.name));return t.filter(d=>c.some(l=>{const u=d[l.name];return u==null?!1:String(u).toLowerCase().includes(s)}))}function Ha({data:t,searchQuery:o,schema:n,visibleColumns:i}){return{searchedData:p.useMemo(()=>!o||o.trim()===""?t:Va(t,n,o,i),[t,o,n,i])}}function Ua({data:t,sortStack:o,schema:n}){return{sortedData:p.useMemo(()=>!o||o.length===0?t:Gs(t,n,o),[t,o,n])}}function Ya({data:t,grouping:o,schema:n}){const i=p.useMemo(()=>!o||!o.enabled||o.levels.length===0?t:Zs(t,n,o),[t,o,n]),s=(o==null?void 0:o.enabled)&&((o==null?void 0:o.levels.length)||0)>0;return{groupedData:i,isGrouped:s}}function Ga({schema:t,columnVisibility:o,columnOrder:n}){const i=p.useMemo(()=>n.filter(l=>o[l]!==!1),[n,o]),s=p.useMemo(()=>Object.entries(o).filter(([l,u])=>!u).map(([l,u])=>l),[o]),c=p.useMemo(()=>n.map(l=>t.find(m=>m.name===l)||{name:l,type:"string"}),[n,t]),d=p.useMemo(()=>i.map(l=>t.find(m=>m.name===l)||{name:l,type:"string"}),[i,t]);return{visibleColumns:i,hiddenColumns:s,allColumns:c,visibleColumnSchemas:d,hiddenCount:s.length}}function qa({views:t,activeViewId:o,currentState:n}){const i=p.useMemo(()=>t.find(m=>m.id===o),[t,o]),s=p.useMemo(()=>i?ta(n,i.snapshot):!1,[i,n]),c=p.useMemo(()=>t.find(m=>m.isDefault),[t]),d=p.useMemo(()=>t.filter(m=>!m.isDefault&&!m.isDeleted),[t]),l=p.useMemo(()=>t.filter(m=>m.isFavorite&&!m.isDeleted),[t]),u=p.useMemo(()=>t.filter(m=>m.isDeleted),[t]);return{activeView:i,isDirty:s,defaultView:c,customViews:d,favoriteViews:l,deletedViews:u,isDefaultView:(i==null?void 0:i.isDefault)||!1}}function Ja({data:t,enabled:o=!1,pageSize:n=100,initialPage:i=1}){const[s,c]=p.useState(i),d=t.length,l=Math.ceil(d/n),u=p.useMemo(()=>{if(!o)return t;const g=(s-1)*n,T=g+n;return t.slice(g,T)},[t,o,s,n]),m=p.useCallback(g=>{const T=Math.max(1,Math.min(g,l));c(T)},[l]),h=p.useCallback(()=>{s<l&&c(s+1)},[s,l]),b=p.useCallback(()=>{s>1&&c(s-1)},[s]),f=p.useCallback(()=>{c(1)},[]);return{paginatedData:u,currentPage:s,totalPages:l,pageSize:n,totalRows:d,goToPage:m,nextPage:h,prevPage:b,resetPage:f,hasNextPage:s<l,hasPrevPage:s>1}}function Ka(t){const{rawData:o,schema:n,filters:i,sortStack:s,grouping:c,searchQuery:d,columnVisibility:l,columnOrder:u,columnWidths:m,views:h,activeViewId:b,pagination:f}=t,g=p.useMemo(()=>({filters:i,sortStack:s,grouping:c,columnVisibility:l,columnOrder:u,columnWidths:m}),[i,s,c,l,u,m]),T=qa({views:h,activeViewId:b,currentState:g}),y=Ga({schema:n,columnVisibility:l,columnOrder:u}),{filteredData:w}=Fa({data:o,filters:i}),{sortedData:v}=Ua({data:w,sortStack:s,schema:n}),{groupedData:j,isGrouped:S}=Ya({data:v,grouping:c,schema:n}),{searchedData:I}=Ha({data:j,searchQuery:d,schema:n,visibleColumns:y.visibleColumns}),a=Ja({data:I,enabled:(f==null?void 0:f.enabled)||!1,pageSize:(f==null?void 0:f.pageSize)||100,initialPage:(f==null?void 0:f.currentPage)||1}),A=f!=null&&f.enabled?a.paginatedData:I,B=p.useMemo(()=>({totalRows:o.length,filteredRows:w.length,sortedRows:v.length,groupedRows:S?j.length:v.length,searchedRows:I.length,visibleRows:A.length,hiddenColumns:y.hiddenCount,activeFilters:i.length,activeSorts:s.length,isGrouped:S}),[o.length,w.length,v.length,j.length,I.length,A.length,y.hiddenCount,i.length,s.length,S]);return{data:A,filteredData:w,sortedData:v,groupedData:j,searchedData:I,viewEngine:T,columnEngine:y,paginationEngine:a,metrics:B,isGrouped:S,isPaginated:(f==null?void 0:f.enabled)||!1}}let Xa=0;function Za(t){t!=null&&t.__urm_row_id__===void 0&&Object.defineProperty(t,"__urm_row_id__",{value:Xa++,writable:!1,enumerable:!1,configurable:!1})}const mt="user-demo-001";function Qa(t={}){var ln,cn,dn,un,pn;const{mode:o="builder",autoLoad:n=!0,initialData:i,dataSource:s,reportName:c,sharedReportId:d,config:l={}}=t,[u,m]=p.useState([]),h=Gt(),[b,f]=p.useState(""),[g,T]=p.useState(!1),[y,w]=p.useState(!1),[v,j]=p.useState({message:"",severity:"info",open:!1}),S=(C,z="info")=>{j({message:C,severity:z,open:!0})},I=()=>j(C=>({...C,open:!1})),a=u.find(C=>C.id===b),[A,B]=p.useState("idle"),[$,Y]=p.useState(!1),[Q,te]=p.useState(!1),[x,N]=p.useState(!1),[W,H]=p.useState(!1),[J,ue]=p.useState(!1),[pe,re]=p.useState(!1),[O,F]=p.useState(void 0),[G,se]=p.useState(null),[ee,le]=p.useState(null),[ae,P]=p.useState(!1),[ne,ce]=p.useState(!1),[ie,he]=p.useState(null),[q,Ae]=p.useState(!1),[We,tt]=p.useState(!1),[Kt,hr]=p.useState({enabled:!1,levels:[],collapsedGroups:[]}),[At,it]=p.useState(""),[Re,Ee]=p.useState(new Set),[gt,st]=p.useState(1),[rt,Je]=p.useState(15),[It,Xt]=p.useState(!1),[at,Ke]=p.useState(!1),[Pe,Zt]=p.useState(!1),[yt,zt]=p.useState(null),[Qt,lt]=p.useState(!1),[gr,yr]=p.useState(null),[br,Mt]=p.useState(null);p.useRef(new Da),p.useRef(new eo),p.useRef(new eo),p.useRef(new eo),p.useRef(new eo);const[vr,Sr]=p.useState(null),Xe=p.useRef(null),ve=p.useMemo(()=>a?pa(a.permissions,mt):"owner",[a]),jr=xa(ve),er=p.useMemo(()=>!(a!=null&&a.uploadedData)||!(a!=null&&a.schema)?{totalRows:0,totalColumns:0}:za(a.uploadedData,a.schema),[a==null?void 0:a.uploadedData,a==null?void 0:a.schema]),ot=p.useCallback(()=>{a&&(Xe.current=Ma(a))},[a]),L=p.useCallback((C,z)=>{m(_=>_.map(D=>D.id===C?{...D,...z}:D))},[]),Ne=p.useCallback(C=>{if(!a)return;Sr(C);const z=Cn(a.id,mt,C,a.auditHistory||[]);L(a.id,{auditHistory:z}),S(C.message,"error"),C.recoverable&&Xe.current&&setTimeout(()=>{_a(a,Xe.current,L),S("Previous state restored","success")},100)},[a,L]),Se=p.useCallback((C,z,_,D)=>{if(!a)return;const U=ji(a.id,mt,C,z,_,D),V=a.auditHistory||[],xe=Ci(V,U);setTimeout(()=>{L(a.id,{auditHistory:xe})},0)},[a,L]);p.useEffect(()=>{if(a!=null&&a.schemaLocked&&a.schema&&(!a.views||a.views.length===0)){const C=Mo(a.schema);(()=>{try{const z=localStorage.getItem("urm_dev_config");return z?JSON.parse(z):null}catch{return null}})(),L(a.id,{views:[C],activeViewId:C.id,filters:C.snapshot.filters,sortStack:C.snapshot.sortStack,columnVisibility:C.snapshot.columnVisibility,columnOrder:C.snapshot.columnOrder,columnWidths:C.snapshot.columnWidths,grouping:C.snapshot.grouping})}},[a==null?void 0:a.schemaLocked,a==null?void 0:a.schema,a==null?void 0:a.id,L]),p.useEffect(()=>{if(i&&n&&!y&&u.length===0){const C=ao(i),z={id:`auto-report-${Date.now()}`,name:c||(o==="viewer"?"Data View":"Imported Data"),description:"Auto-generated from external data",schemaLocked:!0,uploadedData:C,schema:Wr(C),permissions:{owner:mt,editors:[],viewers:[]}};m([z]),f(z.id),w(!0),B("confirmed")}},[i,n,y,u.length,o,c]),p.useEffect(()=>{if(!s||y)return;let C=!1,z=null;const _=async()=>{try{B("uploading");let D;if(s.type==="api"){const V=await fetch(s.url,{headers:s.headers||{}});if(!V.ok)throw new Error(`HTTP ${V.status}: ${V.statusText}`);D=await V.json()}else D=await s.fetch();if(C)return;if(!Array.isArray(D))throw new Error("Data source must return an array of objects");const U=Wr(D);if(y)m(V=>V.map(xe=>xe.id===b?{...xe,uploadedData:D}:xe)),B("confirmed");else{const V={id:`auto-report-${Date.now()}`,name:c||(o==="viewer"?"Data View":"Imported Data"),description:`Loaded from ${s.type==="api"?s.url:"callback"}`,schemaLocked:!0,uploadedData:ao(D),schema:Wr(ao(D)),permissions:{owner:mt,editors:[],viewers:[]}};m([V]),f(V.id),w(!0),B("confirmed")}}catch(D){C||(B("error"),a&&L(a.id,{uploadError:(D==null?void 0:D.message)||"Failed to load data from source"}))}};return _(),s.refreshInterval&&s.refreshInterval>0&&(z=setInterval(_,s.refreshInterval)),()=>{C=!0,z&&clearInterval(z)}},[s,c,o]);const _e=(ln=a==null?void 0:a.views)==null?void 0:ln.find(C=>C.id===a.activeViewId),Cr=p.useMemo(()=>a!=null&&a.uploadedData?(a.uploadedData.forEach(Za),a.showFavoritesOnly?!a.favoriteRowIndices||a.favoriteRowIndices.length===0?[]:a.uploadedData.filter((C,z)=>a.favoriteRowIndices.includes(z)):a.uploadedData):[],[a==null?void 0:a.uploadedData,a==null?void 0:a.showFavoritesOnly,a==null?void 0:a.favoriteRowIndices]),_t=p.useMemo(()=>{var z;if(!(a!=null&&a.uploadedData)||!((z=a==null?void 0:a.favoriteRowIndices)!=null&&z.length))return new Set;const C=new Set;return a.favoriteRowIndices.forEach(_=>{const D=a.uploadedData[_];D!==void 0&&C.add(D)}),C},[a==null?void 0:a.uploadedData,a==null?void 0:a.showFavoritesOnly,a==null?void 0:a.favoriteRowIndices]),bt=Ka({rawData:Cr,schema:(a==null?void 0:a.schema)||[],filters:(a==null?void 0:a.filters)||[],sortStack:(a==null?void 0:a.sortStack)||[],grouping:(a==null?void 0:a.grouping)||null,searchQuery:At||"",columnVisibility:(a==null?void 0:a.columnVisibility)||(_e==null?void 0:_e.snapshot.columnVisibility)||{},columnOrder:(a==null?void 0:a.columnOrder)||(_e==null?void 0:_e.snapshot.columnOrder)||[],columnWidths:(a==null?void 0:a.columnWidths)||(_e==null?void 0:_e.snapshot.columnWidths)||{},views:(a==null?void 0:a.views)||[],activeViewId:(a==null?void 0:a.activeViewId)||"",pagination:{enabled:!0,pageSize:rt,currentPage:gt}}),{data:$t=[],searchedData:Wt=[],groupedData:Et=[],metrics:wr={totalRows:0,searchedRows:0,isGrouped:!1},isGrouped:Rt=!1,paginationEngine:De}=bt||{},X=((cn=bt.viewEngine)==null?void 0:cn.activeView)||_e,vt=((dn=bt.viewEngine)==null?void 0:dn.isDirty)||!1;p.useEffect(()=>{if(!(!X||!a)&&!a.columnOrder){const C=X.snapshot.columnOrder,z=Fr(C,X.snapshot.grouping);L(a.id,{columnOrder:z})}},[a==null?void 0:a.activeViewId]);const ge=p.useMemo(()=>!(a!=null&&a.schema)||!X?null:ea(a.filters||[],a.sortStack||[],a.schema,a.columnVisibility,a.columnOrder,a.columnWidths,a.grouping,X.snapshot.columnOrder),[a==null?void 0:a.filters,a==null?void 0:a.sortStack,a==null?void 0:a.schema,a==null?void 0:a.columnVisibility,a==null?void 0:a.columnOrder,a==null?void 0:a.columnWidths,a==null?void 0:a.grouping,X]),je=p.useMemo(()=>!X||!ge||!vt?[]:oa(ge,X.snapshot),[X,ge,vt]),Ze=p.useCallback((C,z,_)=>{const D={id:`report-${Date.now()}`,name:C,description:z,schemaLocked:!1,permissions:{owner:mt,editors:[],viewers:[]}};if(_&&Array.isArray(_)&&_.length>0){const U=Wr(_),V=Mo(U);D.uploadedData=_,D.schema=U,D.schemaLocked=!0,D.views=[V],D.activeViewId=V.id,D.sortStack=V.snapshot.sortStack,D.filters=V.snapshot.filters,D.columnVisibility=V.snapshot.columnVisibility,D.columnOrder=V.snapshot.columnOrder,D.columnWidths=V.snapshot.columnWidths,D.grouping=V.snapshot.grouping}m(U=>[...U,D]),f(D.id),T(!1),B("confirmed")},[]),kr=p.useCallback(C=>{a&&(B("uploading"),setTimeout(()=>{const z=Wr(C);L(a.id,{uploadedData:C,schema:z,uploadError:void 0}),B("preview")},500))},[a,L]),St=p.useCallback(C=>{a&&(L(a.id,{uploadError:C}),B("idle"))},[a,L]),$e=p.useCallback(()=>{a&&(L(a.id,{uploadError:void 0,uploadedData:void 0,schema:void 0}),B("idle"))},[a,L]),tr=p.useCallback(()=>{a&&(L(a.id,{schemaLocked:!0}),B("confirmed"))},[a,L]),Tr=p.useCallback(C=>{if(!a)return;if(!pt("edit_sorting",ve)){S(xt("edit_sorting"),"error");return}const z=a.sortStack??[],_=z.find(D=>D.column===C);if(_){const D=qs(_.direction);if(D===null){const U=z.filter(V=>V.column!==C).map((V,xe)=>({...V,priority:xe+1}));L(a.id,{sortStack:U.length>0?U:void 0})}else{const U=z.map(V=>V.column===C?{...V,direction:D}:V);L(a.id,{sortStack:U})}}else{if(z.length>=h.sort.maxLevels)return;const D={column:C,direction:"asc",priority:z.length+1};L(a.id,{sortStack:[...z,D]})}},[a,ve,L]),rr=p.useCallback(C=>{if(a)if(a.schema){const{validRules:z,invalidColumns:_}=wi(C,a.schema);_.length>0&&S(`Removed invalid sort columns: ${_.join(", ")}`),ot();try{L(a.id,{sortStack:z.length>0?z:void 0})}catch(D){const U=Ct("processing","sorting",D);Ne(U)}}else L(a.id,{sortStack:C.length>0?C:void 0})},[a,L,ot,Ne]),or=p.useCallback(C=>{if(!a)return;const z=a.sortStack??[],_=z.find(D=>D.column===C);if(!(_&&_.direction==="asc"))if(_){const D=z.map(U=>U.column===C?{...U,direction:"asc"}:U);L(a.id,{sortStack:D})}else{if(z.length>=h.sort.maxLevels)return;const D={column:C,direction:"asc",priority:z.length+1};L(a.id,{sortStack:[...z,D]})}},[a,L]),Ir=p.useCallback(C=>{if(!a)return;const z=a.sortStack??[],_=z.find(D=>D.column===C);if(!(_&&_.direction==="desc"))if(_){const D=z.map(U=>U.column===C?{...U,direction:"desc"}:U);L(a.id,{sortStack:D})}else{if(z.length>=h.sort.maxLevels)return;const D={column:C,direction:"desc",priority:z.length+1};L(a.id,{sortStack:[...z,D]})}},[a,L]),nr=p.useCallback(C=>{var _;if(!a)return;if(!pt("edit_filters",ve)){S(xt("edit_filters"),"error");return}const z=(_=a.schema)==null?void 0:_.find(D=>D.name===C.column);if(z&&C.value!==void 0){const D=$a(z.type,C.operator,C.value);if(!D.isValid){S(D.errorMessage||"Invalid filter value","error");return}}ot();try{const D=a.filters??[];Se("filters","filter_added",D,[...D,C]),L(a.id,{filters:[...D,C]})}catch(D){const U=Ct("processing","filters",D);Ne(U)}},[a,ve,L,ot,Ne,Se]),ir=p.useCallback((C,z)=>{if(!a)return;if(!pt("edit_filters",ve)){S(xt("edit_filters"),"error");return}const _=a.filters??[],D=[..._];Se("filters","filter_updated",_[C],z),D[C]=z,L(a.id,{filters:D})},[a,ve,L,Se]),Le=p.useCallback(C=>{if(!a)return;if(!pt("edit_filters",ve)){S(xt("edit_filters"),"error");return}const z=a.filters??[],_=z.filter((D,U)=>U!==C);Se("filters","filter_removed",z[C],null),L(a.id,{filters:_.length>0?_:void 0})},[a,ve,L,Se]),ct=p.useCallback(()=>{if(!a)return;if(!pt("edit_filters",ve)){S(xt("edit_filters"),"error");return}const C=a.filters??[];Se("filters","filter_cleared",C,null),L(a.id,{filters:void 0})},[a,ve,L,Se]),dt=p.useCallback(C=>{if(!a)return;if(!pt("edit_filters",ve)){S(xt("edit_filters"),"error");return}const z=a.filters??[];Se("filters","filter_cleared",z,C),L(a.id,{filters:C.length>0?C:void 0})},[a,ve,L,Se]),Fe=p.useCallback(C=>{var U;if(!a)return;const z=(U=a.views)==null?void 0:U.find(V=>V.id===C);if(!z)return;const _=z.snapshot.columnOrder,D=Fr(_,z.snapshot.grouping);L(a.id,{filters:z.snapshot.filters.length>0?[...z.snapshot.filters]:void 0,sortStack:z.snapshot.sortStack.length>0?[...z.snapshot.sortStack]:void 0,columnVisibility:{...z.snapshot.columnVisibility},columnOrder:D,columnWidths:{...z.snapshot.columnWidths},grouping:z.snapshot.grouping,activeViewId:C}),Ee(new Set),N(!1)},[a,L]),sr=p.useCallback((C,z,_)=>{var xn;if(!(a!=null&&a.schema)||!ge)return;const D=a.views??[],U=D.filter(Ao=>!Ao.isDeleted).length,V=((xn=h.views)==null?void 0:xn.maxViews)??10;if(U>=V){S(`View limit reached — you can have at most ${V} saved views. Delete an existing view to create a new one.`,"error");return}const xe={id:`view-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:C,description:z||void 0,isDefault:_,isFavorite:!1,isDeleted:!1,scope:"personal",createdBy:mt,createdAt:Date.now(),updatedAt:Date.now(),snapshot:{...ge}},ke=_?D.map(Ao=>({...Ao,isDefault:!1})):D;L(a.id,{views:[...ke,xe],activeViewId:xe.id}),S(`"${C}" view created`,"success")},[a,ge,L]),Pt=p.useCallback(()=>{var z;if(!X||!ge||X.isDefault||!a)return;const C=(z=a.views)==null?void 0:z.map(_=>_.id===X.id?{..._,snapshot:{...ge}}:_);L(a.id,{views:C}),S(`"${X.name}" view updated`,"success")},[X,ge,a,L]),zr=p.useCallback(C=>{var D;if(!X||!ge||!a)return;const z=C??ge.columnWidths,_=(D=a.views)==null?void 0:D.map(U=>U.id===X.id?{...U,snapshot:{...U.snapshot,columnVisibility:ge.columnVisibility,columnOrder:ge.columnOrder,columnWidths:z},updatedAt:Date.now()}:U);L(a.id,{views:_,columnWidths:z}),S(`Column configuration saved to "${X.name}"`,"success")},[X,ge,a,L]),Er=p.useCallback(C=>{var V,xe;if(!ge||!a||!X)return;const z=C??ge.columnWidths,_={...X,snapshot:{...X.snapshot,columnVisibility:ge.columnVisibility,columnOrder:ge.columnOrder,columnWidths:z},updatedAt:Date.now()},D=(V=a.views)==null?void 0:V.map(ke=>ke.id===X.id?_:{...ke,snapshot:{...ke.snapshot,columnVisibility:ge.columnVisibility,columnOrder:ge.columnOrder,columnWidths:z},updatedAt:Date.now()});L(a.id,{views:D,columnWidths:z});const U=(((xe=a.views)==null?void 0:xe.length)||0)-1;S(`Column configuration saved to current view and ${U} other view${U===1?"":"s"}`,"success")},[ge,a,X,L]),Br=p.useCallback(()=>{H(!0)},[]),Dr=p.useCallback(()=>{if(!X||!a)return;const C=X.snapshot.columnOrder,z=Fr(C,X.snapshot.grouping);L(a.id,{filters:X.snapshot.filters.length>0?[...X.snapshot.filters]:void 0,sortStack:X.snapshot.sortStack.length>0?[...X.snapshot.sortStack]:void 0,columnVisibility:{...X.snapshot.columnVisibility},columnOrder:z,columnWidths:{...X.snapshot.columnWidths},grouping:X.snapshot.grouping}),S("Changes reverted to last saved state","success")},[X,a,L]),Or=p.useCallback(C=>{if(!(a!=null&&a.views))return;const z=a.views.map(D=>({...D,isDefault:D.id===C}));L(a.id,{views:z});const _=a.views.find(D=>D.id===C);_&&S(`"${_.name}" set as default view`,"success")},[a,L]),Ar=p.useCallback(C=>{if(!(a!=null&&a.views))return;const z=a.views.map(D=>D.id===C?{...D,isFavorite:!D.isFavorite,updatedAt:Date.now()}:D);L(a.id,{views:z});const _=a.views.find(D=>D.id===C);_&&!_.isFavorite?S(`"${_.name}" added to favorites`,"success"):_&&S(`"${_.name}" removed from favorites`,"info")},[a,L]),Nt=p.useCallback(C=>{if(!(a!=null&&a.views))return;const z=a.views.map(V=>V.id===C?{...V,isDeleted:!0,updatedAt:Date.now()}:V),_=a.activeViewId===C,D=z.find(V=>V.isDefault&&!V.isDeleted);L(a.id,{views:z,activeViewId:_&&D?D.id:a.activeViewId,filters:_&&D?D.snapshot.filters.length>0?D.snapshot.filters:void 0:a.filters,sortStack:_&&D?D.snapshot.sortStack.length>0?D.snapshot.sortStack:void 0:a.sortStack});const U=a.views.find(V=>V.id===C);U&&S(`"${U.name}" moved to Recently Deleted`,"info")},[a,L]),Mr=p.useCallback(C=>{if(!(a!=null&&a.views))return;const z=a.views.map(D=>D.id===C?{...D,isDeleted:!1,updatedAt:Date.now()}:D);L(a.id,{views:z});const _=a.views.find(D=>D.id===C);_&&S(`"${_.name}" restored`,"success")},[a,L]),_r=p.useCallback(C=>{if(!(a!=null&&a.views))return;const z=a.views.find(ke=>ke.id===C),_=a.views.filter(ke=>!ke.isDeleted||ke.id===C);if((z==null?void 0:z.isDefault)&&_.filter(ke=>ke.isDefault).length===1){S("Cannot delete the last default view","error");return}const U=a.views.filter(ke=>ke.id!==C),V=a.activeViewId===C,xe=U.find(ke=>ke.isDefault&&!ke.isDeleted);L(a.id,{views:U,activeViewId:V&&xe?xe.id:a.activeViewId,filters:V&&xe?xe.snapshot.filters.length>0?xe.snapshot.filters:void 0:a.filters,sortStack:V&&xe?xe.snapshot.sortStack.length>0?xe.snapshot.sortStack:void 0:a.sortStack}),z&&S(`"${z.name}" permanently deleted`,"success")},[a,L]),Me=p.useCallback(C=>{se(C),ue(!0),N(!1)},[]),Ve=p.useCallback((C,z)=>{if(!G||!(a!=null&&a.views))return;const _=a.views.map(D=>D.id===G?{...D,name:C,description:z||void 0}:D);L(a.id,{views:_}),se(null)},[G,a,L]),ar=p.useCallback(C=>{le(C),re(!0),N(!1)},[]),Kr=p.useCallback(()=>{if(!ee||!(a!=null&&a.views))return;const C=a.views.filter(D=>D.id!==ee),z=a.activeViewId===ee,_=C.find(D=>D.isDefault);L(a.id,{views:C,activeViewId:z&&_?_.id:a.activeViewId,filters:z&&_?_.snapshot.filters.length>0?_.snapshot.filters:void 0:a.filters,sortStack:z&&_?_.snapshot.sortStack.length>0?_.snapshot.sortStack:void 0:a.sortStack}),le(null),re(!1)},[ee,a,L]),ut=p.useCallback(C=>{var U;if(!(a!=null&&a.views))return;if(!(((U=h.views)==null?void 0:U.isAdmin)??!1)){S("Only administrators can promote views to Global.","error");return}const _=a.views.find(V=>V.id===C);if(!_)return;if(_.scope==="global"){S(`"${_.name}" is already a Global View.`,"info");return}const D=a.views.map(V=>V.id===C?{...V,scope:"global",isDefault:!0,updatedAt:Date.now()}:V.scope==="global"&&V.isDefault?{...V,isDefault:!1}:V);L(a.id,{views:D}),S(`"${_.name}" promoted to Global View and set as default.`,"success")},[a,h,L]);p.useEffect(()=>{De!=null&&De.resetPage?De.resetPage():st(1)},[a==null?void 0:a.filters,At,a==null?void 0:a.activeViewId]),p.useEffect(()=>{De&&De.currentPage!==gt&&st(De.currentPage)},[De==null?void 0:De.currentPage]);const lr=p.useCallback(C=>{De!=null&&De.goToPage&&De.goToPage(C),st(C)},[De]),Lt=p.useCallback(C=>{const z=(gt-1)*rt,_=Math.floor(z/C)+1;Je(C),st(_)},[gt,rt]),Ft=p.useCallback((C,z)=>{if(!a)return;if(!pt("edit_columns",ve)){S(xt("edit_columns"),"error");return}const D={...a.columnVisibility||(X==null?void 0:X.snapshot.columnVisibility)||{},[C]:z};L(a.id,{columnVisibility:D})},[a,X,ve,L]),M=p.useCallback(C=>{if(a){if(!pt("edit_columns",ve)){S(xt("edit_columns"),"error");return}L(a.id,{columnOrder:C})}},[a,ve,L]),Z=p.useCallback((C,z)=>{if(!a)return;if(!pt("edit_columns",ve)){S(xt("edit_columns"),"error");return}const D={...a.columnWidths||(X==null?void 0:X.snapshot.columnWidths)||{},[C]:z};L(a.id,{columnWidths:D})},[a,X,ve,L]),K=p.useCallback(C=>{if(!a)return;const _=(a.filters??[]).filter(D=>D.column!==C);L(a.id,{filters:_.length>0?_:void 0})},[a,L]),de=p.useCallback(()=>{if(!X||!(a!=null&&a.schema))return;const C={},z=[],_={};a.schema.forEach(D=>{C[D.name]=!0,z.push(D.name),_[D.name]=150}),L(a.id,{columnVisibility:C,columnOrder:z,columnWidths:_,filters:void 0,sortStack:void 0}),S("Reset to default layout - all filters and sorts cleared","success")},[X,a,L]),oe=p.useCallback(Ba(C=>{it(C)},300),[]),He=p.useCallback(C=>{oe(C)},[oe]),nt=p.useCallback(C=>{if(!C.trim()||!a)return;const z=a.searchHistory||[],_=aa(z,C);L(a.id,{searchHistory:_})},[a,L]),Xr=p.useCallback(C=>{if(!a)return;const z=a.searchHistory||[],_=la(z,C);L(a.id,{searchHistory:_})},[a,L]),Oo=p.useCallback(C=>{if(!a)return;const z=a.searchHistory||[],_=ca(z,C);L(a.id,{searchHistory:_})},[a,L]),$r=p.useCallback(C=>{const z=C==null?void 0:C.__urm_row_id__;Ee(_=>{const D=new Set(_);if(z!==void 0){const U=Array.from(D).find(V=>(V==null?void 0:V.__urm_row_id__)===z);U!==void 0?D.delete(U):D.add(C)}else D.has(C)?D.delete(C):D.add(C);return D})},[]),ts=p.useCallback((C,z)=>{Ee(_=>{const D=new Set(_);for(const U of z)C?D.add(U):D.delete(U);return D})},[]),rs=p.useCallback((C,z,_)=>{Ee(D=>{const U=new Set(D),V=Math.min(C,z),xe=Math.max(C,z);for(let ke=V;ke<=xe;ke++)_[ke]!==void 0&&U.add(_[ke]);return U})},[]),os=p.useCallback(()=>{Ee(new Set)},[]),ns=p.useCallback(C=>{const z=C==null?void 0:C.__urm_row_id__;Ee(_=>{const D=new Set(_);if(z!==void 0){const U=Array.from(D).find(V=>(V==null?void 0:V.__urm_row_id__)===z);U!==void 0&&D.delete(U)}else D.delete(C);return D})},[]),is=p.useCallback(C=>{if(!(a!=null&&a.uploadedData))return;const z=a.uploadedData.indexOf(C);if(z===-1)return;const _=a.favoriteRowIndices||[],U=_.includes(z)?_.filter(V=>V!==z):[..._,z];L(a.id,{favoriteRowIndices:U})},[a,L]),ss=p.useCallback((C,z)=>{if(!(a!=null&&a.uploadedData))return;const _=a.favoriteRowIndices||[],D=C.map(V=>a.uploadedData.indexOf(V)).filter(V=>V!==-1),U=z?[..._,...D.filter(V=>!_.includes(V))]:_.filter(V=>!D.includes(V));L(a.id,{favoriteRowIndices:U})},[a,L]),as=p.useCallback(()=>{if(!a)return;const C=a.favoriteRowIndices||[],z=!a.showFavoritesOnly;if(z&&C.length===0){S("No rows marked as favorite","warning");return}if(L(a.id,{showFavoritesOnly:z}),z&&Re.size>0){const _=new Set(C.map(U=>{var V,xe;return(xe=(V=a.uploadedData)==null?void 0:V[U])==null?void 0:xe.__urm_row_id__}).filter(U=>U!==void 0)),D=new Set(Array.from(Re).filter(U=>(U==null?void 0:U.__urm_row_id__)!==void 0&&_.has(U.__urm_row_id__)));Ee(D)}S(z?`Showing ${C.length} favorite row${C.length===1?"":"s"}`:"Showing all data","info")},[a,L,Re]),ls=p.useCallback(C=>{if(a){if(!pt("edit_columns",ve)){S(xt("edit_columns"),"error");return}if(C&&a.schema){const{validGrouping:z,invalidColumns:_}=ki(C,a.schema);_.length>0&&S(`Removed invalid grouping columns: ${_.join(", ")}`,"warning"),ot();try{const D=a.grouping;z===null?Se("grouping","group_cleared",D,null):D?Se("grouping","group_reordered",D,z):Se("grouping","group_level_added",null,z);const U=(X==null?void 0:X.snapshot.columnOrder)||a.columnOrder||[],V=Fr(U,z);L(a.id,{grouping:z,columnOrder:V}),JSON.stringify(V)!==JSON.stringify(a.columnOrder)&&Se("columns","column_reordered",a.columnOrder,V),tt(!1)}catch(D){const U=Ct("processing","grouping",D);Ne(U)}}else{const z=a.grouping;Se("grouping","group_cleared",z,null);const _=(X==null?void 0:X.snapshot.columnOrder)||a.columnOrder||[];L(a.id,{grouping:C,columnOrder:[..._]}),JSON.stringify(_)!==JSON.stringify(a.columnOrder)&&Se("columns","column_reordered",a.columnOrder,_),tt(!1)}}},[a,X,ve,L,ot,Ne,Se]),cs=p.useCallback(C=>{if(!a)return;const z=a.grouping;if(!z)return;const _=Qs(z,C);L(a.id,{grouping:_})},[a,L]),ds=p.useCallback(()=>{lt(!0)},[]),cr=p.useCallback(C=>{a!=null&&a.schema&&(P(!0),setTimeout(()=>{try{let z;C.scope==="visible"?z=Wt:z=a.uploadedData||[];let _;C.columnScope==="all"?(_={},a.schema.forEach(ke=>{_[ke.name]=!0})):_=a.columnVisibility||(X==null?void 0:X.snapshot.columnVisibility)||{};const D=a.columnOrder||(X==null?void 0:X.snapshot.columnOrder),U=co(z,a.schema,a.filters??[],a.sortStack??[],X,_,D),V=a.name;let xe;switch(C.format){case"csv":uo(U,V,C),xe="export_csv";break;case"excel":po(U,V,C),xe="export_excel";break;case"json":xo(U,V,C),xe="export_json";break}Se("export",xe,null,{format:C.format,scope:C.scope,columnScope:C.columnScope,rowCount:z.length,viewName:(X==null?void 0:X.name)||"Default View"}),S(`Export completed successfully (${C.format.toUpperCase()})`,"success")}catch(z){const _=Ra(z,{onRetry:()=>cr(C)});S(`Export failed: ${_.message}`,{action:{label:"Retry",onClick:()=>cr(C)}});const D=Cn(a.id,mt,_,a.auditHistory||[]);L(a.id,{auditHistory:D}),Ut.error("urm:report-engine","Export failed",z)}finally{P(!1)}},500))},[a,X,Wt,L,Se]),us=p.useCallback(C=>{if(a!=null&&a.schema){if(vt&&X&&!X.isDefault){he(C.format),ce(!0),lt(!1);return}cr(C),lt(!1)}},[a,X,vt,cr]),Zr=p.useCallback(C=>{cr({format:C,scope:"visible",columnScope:"visible"})},[cr]),ps=p.useCallback(()=>{ie&&Zr(ie),ce(!1),he(null)},[ie,Zr]),xs=p.useCallback(()=>{Pt(),ie&&Zr(ie),ce(!1),he(null)},[Pt,ie,Zr]),ms=p.useCallback(()=>{ce(!1),he(null)},[]),fs=p.useCallback(C=>{!(a!=null&&a.schema)||Re.size===0||(P(!0),setTimeout(()=>{try{const z=Array.from(Re),_=co(z,a.schema,a.filters??[],a.sortStack??[],X),D=`${a.name.toLowerCase().replace(/\s+/g,"_")}_selected_export`;switch(C){case"csv":uo(_,D);break;case"excel":po(_,D);break;case"json":xo(_,D);break}S(`Exported ${z.length} selected rows`,"info")}catch(z){S("Export failed. Please try again.","error"),Ut.error("urm:report-engine","Bulk export failed",z)}finally{P(!1)}},500))},[a,X,Re,Et]),hs=p.useCallback((C,z)=>{if(a)try{const _=ja(a),D=Ca(C,z,mt,_),U=wa(a.presets,D);L(a.id,{presets:U}),Se("presets","preset_created",null,{presetId:D.id,name:D.name}),Ke(!1),S(`Preset "${C}" saved successfully`,"success")}catch(_){S(_ instanceof Error?_.message:"Failed to create preset","error")}},[a,L,Se]),gs=p.useCallback(()=>{zt(null),S("Exited preset view","info")},[]),ys=p.useCallback(()=>{Zt(!0)},[]),bs=p.useCallback((C,z)=>{if(!a)return;const _=ka(a.presets,C);L(a.id,{presets:_}),Se("presets","preset_deleted",{presetId:C,name:z},null),yt===C&&zt(null),S(`Preset "${z}" deleted`,"success")},[a,yt,L,Se]);p.useEffect(()=>{if(!d||u.length===0)return;const C=u.find(z=>z.id===d);C&&C.id!==b&&f(C.id)},[d,u,b]),p.useEffect(()=>{if(!a)return;const C=Ta();if(C&&a.presets&&a.schemaLocked&&a.schema){const z=jn(a.presets,C);if(z){const{sanitizedConfig:_,warnings:D}=Wa(z.config,a.schema);D.length>0&&D.forEach(V=>S(V,"warning"));const U=Ia(_);L(a.id,U),zt(C),Se("presets","preset_applied",null,{presetId:z.id,name:z.name}),S(`Loaded preset: ${z.name}`,"info")}else S("Preset not found","info")}},[a==null?void 0:a.schemaLocked]);const vs=yt?jn(a==null?void 0:a.presets,yt):void 0;p.useEffect(()=>{a!=null&&a.views&&a.views.length>0&&a.activeViewId&&na(a.id,{views:a.views,activeViewId:a.activeViewId})},[a==null?void 0:a.views,a==null?void 0:a.activeViewId,a==null?void 0:a.id]),p.useEffect(()=>{if(a!=null&&a.schemaLocked&&a.schema&&(!a.views||a.views.length===0)){const C=ia(a.id);if(C&&C.views.length>0){const z=C.views.find(_=>_.id===C.activeViewId);if(z)L(a.id,{views:C.views,activeViewId:C.activeViewId,filters:z.snapshot.filters.length>0?z.snapshot.filters:void 0,sortStack:z.snapshot.sortStack.length>0?z.snapshot.sortStack:void 0});else{const _=C.views.find(D=>D.isDefault)||Mo(a.schema);L(a.id,{views:C.views,activeViewId:_.id,filters:_.snapshot.filters.length>0?_.snapshot.filters:void 0,sortStack:_.snapshot.sortStack.length>0?_.snapshot.sortStack:void 0})}}}},[a==null?void 0:a.schemaLocked,a==null?void 0:a.schema,a==null?void 0:a.id]);const Ss=p.useCallback(C=>{F(C),Y(!0)},[]),js=p.useCallback(()=>{Y(!1),F(void 0)},[]),Cs=(un=a==null?void 0:a.views)==null?void 0:un.find(C=>C.id===G),ws=(pn=a==null?void 0:a.views)==null?void 0:pn.find(C=>C.id===ee);return{reports:u,activeReport:a,activeReportId:b,setActiveReportId:f,isModalOpen:g,setIsModalOpen:T,createReport:Ze,updateReport:L,uploadState:A,handleFileUpload:kr,handleUploadError:St,handleRetry:$e,handleConfirm:tr,paginatedData:$t,processedData:Wt,displayData:Et,tableMetrics:wr,isGrouped:Rt,tableEngine:bt,activeView:X,isDirty:vt,currentTableState:ge,viewChanges:je,filters:a==null?void 0:a.filters,showFilterPanel:$,setShowFilterPanel:Y,filterFocusColumn:O,handleAddFilter:nr,handleUpdateFilter:ir,handleRemoveFilter:Le,handleClearAllFilters:ct,handleReplaceFilters:dt,handleOpenFilterForColumn:Ss,handleCloseFilterPanel:js,handleClearFiltersForColumn:K,sortStack:a==null?void 0:a.sortStack,showSortPanel:Q,setShowSortPanel:te,handleSort:Tr,handleUpdateSortStack:rr,handleSortAscending:or,handleSortDescending:Ir,views:a==null?void 0:a.views,showManageViews:x,setShowManageViews:N,showCreateViewModal:W,setShowCreateViewModal:H,showEditViewModal:J,setShowEditViewModal:ue,showDeleteConfirmation:pe,setShowDeleteConfirmation:re,editingView:Cs,deletingView:ws,editingViewId:G,deletingViewId:ee,handleSelectView:Fe,handleCreateView:sr,handleUpdateCurrentView:Pt,handleSaveColumnConfigToCurrentView:zr,handleSaveColumnConfigToAllViews:Er,handleSaveAsNewView:Br,handleRevertChanges:Dr,handleToggleDefault:Or,handleToggleFavorite:Ar,handleSoftDelete:Nt,handleRestoreView:Mr,handlePermanentDelete:_r,handleEditView:Me,handleSaveEditView:Ve,handleDeleteView:ar,handleConfirmDelete:Kr,handlePromoteToGlobal:ut,showManageColumns:q,setShowManageColumns:Ae,columnVisibility:a==null?void 0:a.columnVisibility,columnOrder:a==null?void 0:a.columnOrder,columnWidths:a==null?void 0:a.columnWidths,handleUpdateColumnVisibility:Ft,handleUpdateColumnOrder:M,handleUpdateColumnWidth:Z,handleResetColumnLayout:de,showGroupPanel:We,setShowGroupPanel:tt,grouping:a==null?void 0:a.grouping,groupingState:Kt,handleGroup:ls,handleToggleGroupCollapse:cs,searchQuery:At,searchHistory:da((a==null?void 0:a.searchHistory)||[]),handleSearchChange:He,handleAddToSearchHistory:nt,handleToggleSearchFavourite:Xr,handleDeleteSearchHistory:Oo,selectedRowIds:Re,handleToggleRowSelection:$r,handleToggleAllRows:ts,handleRangeSelection:rs,handleClearSelection:os,handleUpdateSelectionAfterDelete:ns,favoriteRowIndices:(a==null?void 0:a.favoriteRowIndices)||[],resolvedFavoritesSet:_t,showFavoritesOnly:(a==null?void 0:a.showFavoritesOnly)||!1,handleToggleRowFavorite:is,handleBulkSetFavorites:ss,handleToggleFavoritesFilter:as,currentPage:gt,pageSize:rt,paginationEngine:De,handlePageChange:lr,handlePageSizeChange:Lt,isExporting:ae,showExportModal:Qt,setShowExportModal:lt,showDirtyExportWarning:ne,handleExport:ds,handleExportWithConfig:us,handleExportSelected:fs,handleExportAnyway:ps,handleSaveAndExport:xs,handleCancelExport:ms,showAuditHistory:It,setShowAuditHistory:Xt,auditHistory:a==null?void 0:a.auditHistory,showCreatePreset:at,setShowCreatePreset:Ke,showManagePresets:Pe,setShowManagePresets:Zt,activePreset:vs,activePresetId:yt,handleOpenManagePresets:ys,handleCreatePreset:hs,handleClearActivePreset:gs,handleDeletePresetById:bs,userRole:ve,isViewerRole:jr,currentUserId:mt,featureLimitWarning:br,setFeatureLimitWarning:Mt,datasetMeta:er,reportError:vr,setReportError:Sr,handleError:Ne,schema:a==null?void 0:a.schema,hasSchemaConflicts:a!=null&&a.schema?Us(a.schema):!1,snack:v,handleSnackClose:I,showSnack:S}}const Ti=p.createContext(void 0);function en(t){const{children:o,initialData:n,data:i,reportName:s,dataSource:c,mode:d="builder",autoLoad:l=!0,config:u,devConfig:m,showDevPanel:h=!1,sharedReportId:b}=t,g=Qa({mode:d,autoLoad:l,initialData:i||n,dataSource:c,reportName:s,sharedReportId:b,config:u}),[T,y]=p.useState(()=>Is()),w=(()=>{const I=Es(T,m,!!m);return{...I,display:{...I.display,showDevPanel:h||I.display.showDevPanel}}})(),v=p.useCallback(S=>{y(S),zs(S)},[]),j={...g,activeDevConfig:w,handleDevConfigChange:v};return e.jsx(xi.Provider,{value:w,children:e.jsx(Ti.Provider,{value:j,children:o})})}function go(){const t=p.useContext(Ti);if(t===void 0)throw new Error("useReportContext must be used within a ReportProvider. Wrap your component tree with <ReportProvider>...</ReportProvider>");return t}function el({onCreateReport:t,reports:o=[],activeReportId:n,onReportClick:i}){const s=o.find(c=>c.id===n);return e.jsx(r.Box,{component:"header",sx:{position:"sticky",top:0,zIndex:50,borderBottom:"1px solid",borderColor:"divider",bgcolor:"background.paper"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,height:64},children:[e.jsxs(r.Breadcrumbs,{separator:e.jsx(k.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}),sx:{display:"flex",alignItems:"center"},children:[e.jsx(r.Typography,{variant:"h6",component:"h1",sx:{fontWeight:500,fontSize:"1.375rem",color:"text.primary",letterSpacing:"-0.01em",cursor:o.length>0&&s?"pointer":"default","&:hover":o.length>0&&s?{color:"primary.main"}:{}},onClick:()=>{o.length>0},children:"Reports"}),s&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"1.125rem",color:"primary.main",cursor:"pointer","&:hover":{textDecoration:"underline"}},onClick:()=>i==null?void 0:i(s.id),children:s.name}),e.jsx(r.Tooltip,{title:s.description||"No description",arrow:!0,placement:"bottom",children:e.jsx(k.InfoOutlined,{sx:{fontSize:18,color:"text.secondary",opacity:.7,cursor:"help","&:hover":{opacity:1}}})})]})]}),e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:e.jsx(r.Button,{variant:"contained",startIcon:e.jsx(k.Add,{sx:{fontSize:18}}),onClick:t,sx:{borderRadius:"20px",px:3,textTransform:"none",fontWeight:500,fontSize:"0.875rem",py:.75},children:"New Report"})})]})})}function Yt(t,...o){const n=new URL(`https://mui.com/production-error/?code=${t}`);return o.forEach(i=>n.searchParams.append("args[]",i)),`Minified MUI error #${t}; visit ${n} for the full message.`}const tl="$$material";function rl(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var ro={exports:{}},oo={exports:{}},me={};/** @license React v16.13.1
|
|
4
4
|
* react-is.production.min.js
|
|
5
5
|
*
|
|
6
6
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7
7
|
*
|
|
8
8
|
* This source code is licensed under the MIT license found in the
|
|
9
9
|
* LICENSE file in the root directory of this source tree.
|
|
10
|
-
*/var
|
|
10
|
+
*/var kn;function ol(){if(kn)return me;kn=1;var t=typeof Symbol=="function"&&Symbol.for,o=t?Symbol.for("react.element"):60103,n=t?Symbol.for("react.portal"):60106,i=t?Symbol.for("react.fragment"):60107,s=t?Symbol.for("react.strict_mode"):60108,c=t?Symbol.for("react.profiler"):60114,d=t?Symbol.for("react.provider"):60109,l=t?Symbol.for("react.context"):60110,u=t?Symbol.for("react.async_mode"):60111,m=t?Symbol.for("react.concurrent_mode"):60111,h=t?Symbol.for("react.forward_ref"):60112,b=t?Symbol.for("react.suspense"):60113,f=t?Symbol.for("react.suspense_list"):60120,g=t?Symbol.for("react.memo"):60115,T=t?Symbol.for("react.lazy"):60116,y=t?Symbol.for("react.block"):60121,w=t?Symbol.for("react.fundamental"):60117,v=t?Symbol.for("react.responder"):60118,j=t?Symbol.for("react.scope"):60119;function S(a){if(typeof a=="object"&&a!==null){var A=a.$$typeof;switch(A){case o:switch(a=a.type,a){case u:case m:case i:case c:case s:case b:return a;default:switch(a=a&&a.$$typeof,a){case l:case h:case T:case g:case d:return a;default:return A}}case n:return A}}}function I(a){return S(a)===m}return me.AsyncMode=u,me.ConcurrentMode=m,me.ContextConsumer=l,me.ContextProvider=d,me.Element=o,me.ForwardRef=h,me.Fragment=i,me.Lazy=T,me.Memo=g,me.Portal=n,me.Profiler=c,me.StrictMode=s,me.Suspense=b,me.isAsyncMode=function(a){return I(a)||S(a)===u},me.isConcurrentMode=I,me.isContextConsumer=function(a){return S(a)===l},me.isContextProvider=function(a){return S(a)===d},me.isElement=function(a){return typeof a=="object"&&a!==null&&a.$$typeof===o},me.isForwardRef=function(a){return S(a)===h},me.isFragment=function(a){return S(a)===i},me.isLazy=function(a){return S(a)===T},me.isMemo=function(a){return S(a)===g},me.isPortal=function(a){return S(a)===n},me.isProfiler=function(a){return S(a)===c},me.isStrictMode=function(a){return S(a)===s},me.isSuspense=function(a){return S(a)===b},me.isValidElementType=function(a){return typeof a=="string"||typeof a=="function"||a===i||a===m||a===c||a===s||a===b||a===f||typeof a=="object"&&a!==null&&(a.$$typeof===T||a.$$typeof===g||a.$$typeof===d||a.$$typeof===l||a.$$typeof===h||a.$$typeof===w||a.$$typeof===v||a.$$typeof===j||a.$$typeof===y)},me.typeOf=S,me}var fe={};/** @license React v16.13.1
|
|
11
11
|
* react-is.development.js
|
|
12
12
|
*
|
|
13
13
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
17
|
+
*/var Tn;function nl(){return Tn||(Tn=1,process.env.NODE_ENV!=="production"&&(function(){var t=typeof Symbol=="function"&&Symbol.for,o=t?Symbol.for("react.element"):60103,n=t?Symbol.for("react.portal"):60106,i=t?Symbol.for("react.fragment"):60107,s=t?Symbol.for("react.strict_mode"):60108,c=t?Symbol.for("react.profiler"):60114,d=t?Symbol.for("react.provider"):60109,l=t?Symbol.for("react.context"):60110,u=t?Symbol.for("react.async_mode"):60111,m=t?Symbol.for("react.concurrent_mode"):60111,h=t?Symbol.for("react.forward_ref"):60112,b=t?Symbol.for("react.suspense"):60113,f=t?Symbol.for("react.suspense_list"):60120,g=t?Symbol.for("react.memo"):60115,T=t?Symbol.for("react.lazy"):60116,y=t?Symbol.for("react.block"):60121,w=t?Symbol.for("react.fundamental"):60117,v=t?Symbol.for("react.responder"):60118,j=t?Symbol.for("react.scope"):60119;function S(q){return typeof q=="string"||typeof q=="function"||q===i||q===m||q===c||q===s||q===b||q===f||typeof q=="object"&&q!==null&&(q.$$typeof===T||q.$$typeof===g||q.$$typeof===d||q.$$typeof===l||q.$$typeof===h||q.$$typeof===w||q.$$typeof===v||q.$$typeof===j||q.$$typeof===y)}function I(q){if(typeof q=="object"&&q!==null){var Ae=q.$$typeof;switch(Ae){case o:var We=q.type;switch(We){case u:case m:case i:case c:case s:case b:return We;default:var tt=We&&We.$$typeof;switch(tt){case l:case h:case T:case g:case d:return tt;default:return Ae}}case n:return Ae}}}var a=u,A=m,B=l,$=d,Y=o,Q=h,te=i,x=T,N=g,W=n,H=c,J=s,ue=b,pe=!1;function re(q){return pe||(pe=!0,console.warn("The ReactIs.isAsyncMode() alias has been deprecated, and will be removed in React 17+. Update your code to use ReactIs.isConcurrentMode() instead. It has the exact same API.")),O(q)||I(q)===u}function O(q){return I(q)===m}function F(q){return I(q)===l}function G(q){return I(q)===d}function se(q){return typeof q=="object"&&q!==null&&q.$$typeof===o}function ee(q){return I(q)===h}function le(q){return I(q)===i}function ae(q){return I(q)===T}function P(q){return I(q)===g}function ne(q){return I(q)===n}function ce(q){return I(q)===c}function ie(q){return I(q)===s}function he(q){return I(q)===b}fe.AsyncMode=a,fe.ConcurrentMode=A,fe.ContextConsumer=B,fe.ContextProvider=$,fe.Element=Y,fe.ForwardRef=Q,fe.Fragment=te,fe.Lazy=x,fe.Memo=N,fe.Portal=W,fe.Profiler=H,fe.StrictMode=J,fe.Suspense=ue,fe.isAsyncMode=re,fe.isConcurrentMode=O,fe.isContextConsumer=F,fe.isContextProvider=G,fe.isElement=se,fe.isForwardRef=ee,fe.isFragment=le,fe.isLazy=ae,fe.isMemo=P,fe.isPortal=ne,fe.isProfiler=ce,fe.isStrictMode=ie,fe.isSuspense=he,fe.isValidElementType=S,fe.typeOf=I})()),fe}var In;function Ii(){return In||(In=1,process.env.NODE_ENV==="production"?oo.exports=ol():oo.exports=nl()),oo.exports}/*
|
|
18
18
|
object-assign
|
|
19
19
|
(c) Sindre Sorhus
|
|
20
20
|
@license MIT
|
|
21
|
-
*/var
|
|
22
|
-
Valid keys: `+JSON.stringify(Object.keys(
|
|
21
|
+
*/var $o,zn;function il(){if(zn)return $o;zn=1;var t=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;function i(c){if(c==null)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(c)}function s(){try{if(!Object.assign)return!1;var c=new String("abc");if(c[5]="de",Object.getOwnPropertyNames(c)[0]==="5")return!1;for(var d={},l=0;l<10;l++)d["_"+String.fromCharCode(l)]=l;var u=Object.getOwnPropertyNames(d).map(function(h){return d[h]});if(u.join("")!=="0123456789")return!1;var m={};return"abcdefghijklmnopqrst".split("").forEach(function(h){m[h]=h}),Object.keys(Object.assign({},m)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}return $o=s()?Object.assign:function(c,d){for(var l,u=i(c),m,h=1;h<arguments.length;h++){l=Object(arguments[h]);for(var b in l)o.call(l,b)&&(u[b]=l[b]);if(t){m=t(l);for(var f=0;f<m.length;f++)n.call(l,m[f])&&(u[m[f]]=l[m[f]])}}return u},$o}var Wo,En;function tn(){if(En)return Wo;En=1;var t="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return Wo=t,Wo}var Ro,Bn;function zi(){return Bn||(Bn=1,Ro=Function.call.bind(Object.prototype.hasOwnProperty)),Ro}var Po,Dn;function sl(){if(Dn)return Po;Dn=1;var t=function(){};if(process.env.NODE_ENV!=="production"){var o=tn(),n={},i=zi();t=function(c){var d="Warning: "+c;typeof console<"u"&&console.error(d);try{throw new Error(d)}catch{}}}function s(c,d,l,u,m){if(process.env.NODE_ENV!=="production"){for(var h in c)if(i(c,h)){var b;try{if(typeof c[h]!="function"){var f=Error((u||"React class")+": "+l+" type `"+h+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof c[h]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw f.name="Invariant Violation",f}b=c[h](d,h,u,l,null,o)}catch(T){b=T}if(b&&!(b instanceof Error)&&t((u||"React class")+": type specification of "+l+" `"+h+"` is invalid; the type checker function must return `null` or an `Error` but returned a "+typeof b+". You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument)."),b instanceof Error&&!(b.message in n)){n[b.message]=!0;var g=m?m():"";t("Failed "+l+" type: "+b.message+(g??""))}}}}return s.resetWarningCache=function(){process.env.NODE_ENV!=="production"&&(n={})},Po=s,Po}var No,On;function al(){if(On)return No;On=1;var t=Ii(),o=il(),n=tn(),i=zi(),s=sl(),c=function(){};process.env.NODE_ENV!=="production"&&(c=function(l){var u="Warning: "+l;typeof console<"u"&&console.error(u);try{throw new Error(u)}catch{}});function d(){return null}return No=function(l,u){var m=typeof Symbol=="function"&&Symbol.iterator,h="@@iterator";function b(O){var F=O&&(m&&O[m]||O[h]);if(typeof F=="function")return F}var f="<<anonymous>>",g={array:v("array"),bigint:v("bigint"),bool:v("boolean"),func:v("function"),number:v("number"),object:v("object"),string:v("string"),symbol:v("symbol"),any:j(),arrayOf:S,element:I(),elementType:a(),instanceOf:A,node:Q(),objectOf:$,oneOf:B,oneOfType:Y,shape:x,exact:N};function T(O,F){return O===F?O!==0||1/O===1/F:O!==O&&F!==F}function y(O,F){this.message=O,this.data=F&&typeof F=="object"?F:{},this.stack=""}y.prototype=Error.prototype;function w(O){if(process.env.NODE_ENV!=="production")var F={},G=0;function se(le,ae,P,ne,ce,ie,he){if(ne=ne||f,ie=ie||P,he!==n){if(u){var q=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use `PropTypes.checkPropTypes()` to call them. Read more at http://fb.me/use-check-prop-types");throw q.name="Invariant Violation",q}else if(process.env.NODE_ENV!=="production"&&typeof console<"u"){var Ae=ne+":"+P;!F[Ae]&&G<3&&(c("You are manually calling a React.PropTypes validation function for the `"+ie+"` prop on `"+ne+"`. This is deprecated and will throw in the standalone `prop-types` package. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details."),F[Ae]=!0,G++)}}return ae[P]==null?le?ae[P]===null?new y("The "+ce+" `"+ie+"` is marked as required "+("in `"+ne+"`, but its value is `null`.")):new y("The "+ce+" `"+ie+"` is marked as required in "+("`"+ne+"`, but its value is `undefined`.")):null:O(ae,P,ne,ce,ie)}var ee=se.bind(null,!1);return ee.isRequired=se.bind(null,!0),ee}function v(O){function F(G,se,ee,le,ae,P){var ne=G[se],ce=J(ne);if(ce!==O){var ie=ue(ne);return new y("Invalid "+le+" `"+ae+"` of type "+("`"+ie+"` supplied to `"+ee+"`, expected ")+("`"+O+"`."),{expectedType:O})}return null}return w(F)}function j(){return w(d)}function S(O){function F(G,se,ee,le,ae){if(typeof O!="function")return new y("Property `"+ae+"` of component `"+ee+"` has invalid PropType notation inside arrayOf.");var P=G[se];if(!Array.isArray(P)){var ne=J(P);return new y("Invalid "+le+" `"+ae+"` of type "+("`"+ne+"` supplied to `"+ee+"`, expected an array."))}for(var ce=0;ce<P.length;ce++){var ie=O(P,ce,ee,le,ae+"["+ce+"]",n);if(ie instanceof Error)return ie}return null}return w(F)}function I(){function O(F,G,se,ee,le){var ae=F[G];if(!l(ae)){var P=J(ae);return new y("Invalid "+ee+" `"+le+"` of type "+("`"+P+"` supplied to `"+se+"`, expected a single ReactElement."))}return null}return w(O)}function a(){function O(F,G,se,ee,le){var ae=F[G];if(!t.isValidElementType(ae)){var P=J(ae);return new y("Invalid "+ee+" `"+le+"` of type "+("`"+P+"` supplied to `"+se+"`, expected a single ReactElement type."))}return null}return w(O)}function A(O){function F(G,se,ee,le,ae){if(!(G[se]instanceof O)){var P=O.name||f,ne=re(G[se]);return new y("Invalid "+le+" `"+ae+"` of type "+("`"+ne+"` supplied to `"+ee+"`, expected ")+("instance of `"+P+"`."))}return null}return w(F)}function B(O){if(!Array.isArray(O))return process.env.NODE_ENV!=="production"&&(arguments.length>1?c("Invalid arguments supplied to oneOf, expected an array, got "+arguments.length+" arguments. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z])."):c("Invalid argument supplied to oneOf, expected an array.")),d;function F(G,se,ee,le,ae){for(var P=G[se],ne=0;ne<O.length;ne++)if(T(P,O[ne]))return null;var ce=JSON.stringify(O,function(he,q){var Ae=ue(q);return Ae==="symbol"?String(q):q});return new y("Invalid "+le+" `"+ae+"` of value `"+String(P)+"` "+("supplied to `"+ee+"`, expected one of "+ce+"."))}return w(F)}function $(O){function F(G,se,ee,le,ae){if(typeof O!="function")return new y("Property `"+ae+"` of component `"+ee+"` has invalid PropType notation inside objectOf.");var P=G[se],ne=J(P);if(ne!=="object")return new y("Invalid "+le+" `"+ae+"` of type "+("`"+ne+"` supplied to `"+ee+"`, expected an object."));for(var ce in P)if(i(P,ce)){var ie=O(P,ce,ee,le,ae+"."+ce,n);if(ie instanceof Error)return ie}return null}return w(F)}function Y(O){if(!Array.isArray(O))return process.env.NODE_ENV!=="production"&&c("Invalid argument supplied to oneOfType, expected an instance of array."),d;for(var F=0;F<O.length;F++){var G=O[F];if(typeof G!="function")return c("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+pe(G)+" at index "+F+"."),d}function se(ee,le,ae,P,ne){for(var ce=[],ie=0;ie<O.length;ie++){var he=O[ie],q=he(ee,le,ae,P,ne,n);if(q==null)return null;q.data&&i(q.data,"expectedType")&&ce.push(q.data.expectedType)}var Ae=ce.length>0?", expected one of type ["+ce.join(", ")+"]":"";return new y("Invalid "+P+" `"+ne+"` supplied to "+("`"+ae+"`"+Ae+"."))}return w(se)}function Q(){function O(F,G,se,ee,le){return W(F[G])?null:new y("Invalid "+ee+" `"+le+"` supplied to "+("`"+se+"`, expected a ReactNode."))}return w(O)}function te(O,F,G,se,ee){return new y((O||"React class")+": "+F+" type `"+G+"."+se+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+ee+"`.")}function x(O){function F(G,se,ee,le,ae){var P=G[se],ne=J(P);if(ne!=="object")return new y("Invalid "+le+" `"+ae+"` of type `"+ne+"` "+("supplied to `"+ee+"`, expected `object`."));for(var ce in O){var ie=O[ce];if(typeof ie!="function")return te(ee,le,ae,ce,ue(ie));var he=ie(P,ce,ee,le,ae+"."+ce,n);if(he)return he}return null}return w(F)}function N(O){function F(G,se,ee,le,ae){var P=G[se],ne=J(P);if(ne!=="object")return new y("Invalid "+le+" `"+ae+"` of type `"+ne+"` "+("supplied to `"+ee+"`, expected `object`."));var ce=o({},G[se],O);for(var ie in ce){var he=O[ie];if(i(O,ie)&&typeof he!="function")return te(ee,le,ae,ie,ue(he));if(!he)return new y("Invalid "+le+" `"+ae+"` key `"+ie+"` supplied to `"+ee+"`.\nBad object: "+JSON.stringify(G[se],null," ")+`
|
|
22
|
+
Valid keys: `+JSON.stringify(Object.keys(O),null," "));var q=he(P,ie,ee,le,ae+"."+ie,n);if(q)return q}return null}return w(F)}function W(O){switch(typeof O){case"number":case"string":case"undefined":return!0;case"boolean":return!O;case"object":if(Array.isArray(O))return O.every(W);if(O===null||l(O))return!0;var F=b(O);if(F){var G=F.call(O),se;if(F!==O.entries){for(;!(se=G.next()).done;)if(!W(se.value))return!1}else for(;!(se=G.next()).done;){var ee=se.value;if(ee&&!W(ee[1]))return!1}}else return!1;return!0;default:return!1}}function H(O,F){return O==="symbol"?!0:F?F["@@toStringTag"]==="Symbol"||typeof Symbol=="function"&&F instanceof Symbol:!1}function J(O){var F=typeof O;return Array.isArray(O)?"array":O instanceof RegExp?"object":H(F,O)?"symbol":F}function ue(O){if(typeof O>"u"||O===null)return""+O;var F=J(O);if(F==="object"){if(O instanceof Date)return"date";if(O instanceof RegExp)return"regexp"}return F}function pe(O){var F=ue(O);switch(F){case"array":case"object":return"an "+F;case"boolean":case"date":case"regexp":return"a "+F;default:return F}}function re(O){return!O.constructor||!O.constructor.name?f:O.constructor.name}return g.checkPropTypes=s,g.resetWarningCache=s.resetWarningCache,g.PropTypes=g,g},No}var Lo,An;function ll(){if(An)return Lo;An=1;var t=tn();function o(){}function n(){}return n.resetWarningCache=o,Lo=function(){function i(d,l,u,m,h,b){if(b!==t){var f=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw f.name="Invariant Violation",f}}i.isRequired=i;function s(){return i}var c={array:i,bigint:i,bool:i,func:i,number:i,object:i,string:i,symbol:i,any:i,arrayOf:s,element:i,elementType:i,instanceOf:s,node:i,objectOf:s,oneOf:s,oneOfType:s,shape:s,exact:s,checkPropTypes:n,resetWarningCache:o};return c.PropTypes=c,c},Lo}var Mn;function cl(){if(Mn)return ro.exports;if(Mn=1,process.env.NODE_ENV!=="production"){var t=Ii(),o=!0;ro.exports=al()(t.isElement,o)}else ro.exports=ll()();return ro.exports}var dl=cl();const Rr=rl(dl);var no={exports:{}},Ce={};/**
|
|
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
|
|
30
|
+
*/var _n;function ul(){if(_n)return Ce;_n=1;var t=Symbol.for("react.transitional.element"),o=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),c=Symbol.for("react.consumer"),d=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),m=Symbol.for("react.suspense_list"),h=Symbol.for("react.memo"),b=Symbol.for("react.lazy"),f=Symbol.for("react.view_transition"),g=Symbol.for("react.client.reference");function T(y){if(typeof y=="object"&&y!==null){var w=y.$$typeof;switch(w){case t:switch(y=y.type,y){case n:case s:case i:case u:case m:case f:return y;default:switch(y=y&&y.$$typeof,y){case d:case l:case b:case h:return y;case c:return y;default:return w}}case o:return w}}}return Ce.ContextConsumer=c,Ce.ContextProvider=d,Ce.Element=t,Ce.ForwardRef=l,Ce.Fragment=n,Ce.Lazy=b,Ce.Memo=h,Ce.Portal=o,Ce.Profiler=s,Ce.StrictMode=i,Ce.Suspense=u,Ce.SuspenseList=m,Ce.isContextConsumer=function(y){return T(y)===c},Ce.isContextProvider=function(y){return T(y)===d},Ce.isElement=function(y){return typeof y=="object"&&y!==null&&y.$$typeof===t},Ce.isForwardRef=function(y){return T(y)===l},Ce.isFragment=function(y){return T(y)===n},Ce.isLazy=function(y){return T(y)===b},Ce.isMemo=function(y){return T(y)===h},Ce.isPortal=function(y){return T(y)===o},Ce.isProfiler=function(y){return T(y)===s},Ce.isStrictMode=function(y){return T(y)===i},Ce.isSuspense=function(y){return T(y)===u},Ce.isSuspenseList=function(y){return T(y)===m},Ce.isValidElementType=function(y){return typeof y=="string"||typeof y=="function"||y===n||y===s||y===i||y===u||y===m||typeof y=="object"&&y!==null&&(y.$$typeof===b||y.$$typeof===h||y.$$typeof===d||y.$$typeof===c||y.$$typeof===l||y.$$typeof===g||y.getModuleId!==void 0)},Ce.typeOf=T,Ce}var we={};/**
|
|
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
|
|
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
|
|
38
|
+
*/var $n;function pl(){return $n||($n=1,process.env.NODE_ENV!=="production"&&(function(){function t(y){if(typeof y=="object"&&y!==null){var w=y.$$typeof;switch(w){case o:switch(y=y.type,y){case i:case c:case s:case m:case h:case g:return y;default:switch(y=y&&y.$$typeof,y){case l:case u:case f:case b:return y;case d:return y;default:return w}}case n:return w}}}var o=Symbol.for("react.transitional.element"),n=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),d=Symbol.for("react.consumer"),l=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),m=Symbol.for("react.suspense"),h=Symbol.for("react.suspense_list"),b=Symbol.for("react.memo"),f=Symbol.for("react.lazy"),g=Symbol.for("react.view_transition"),T=Symbol.for("react.client.reference");we.ContextConsumer=d,we.ContextProvider=l,we.Element=o,we.ForwardRef=u,we.Fragment=i,we.Lazy=f,we.Memo=b,we.Portal=n,we.Profiler=c,we.StrictMode=s,we.Suspense=m,we.SuspenseList=h,we.isContextConsumer=function(y){return t(y)===d},we.isContextProvider=function(y){return t(y)===l},we.isElement=function(y){return typeof y=="object"&&y!==null&&y.$$typeof===o},we.isForwardRef=function(y){return t(y)===u},we.isFragment=function(y){return t(y)===i},we.isLazy=function(y){return t(y)===f},we.isMemo=function(y){return t(y)===b},we.isPortal=function(y){return t(y)===n},we.isProfiler=function(y){return t(y)===c},we.isStrictMode=function(y){return t(y)===s},we.isSuspense=function(y){return t(y)===m},we.isSuspenseList=function(y){return t(y)===h},we.isValidElementType=function(y){return typeof y=="string"||typeof y=="function"||y===i||y===c||y===s||y===m||y===h||typeof y=="object"&&y!==null&&(y.$$typeof===f||y.$$typeof===b||y.$$typeof===l||y.$$typeof===d||y.$$typeof===u||y.$$typeof===T||y.getModuleId!==void 0)},we.typeOf=t})()),we}var Wn;function xl(){return Wn||(Wn=1,process.env.NODE_ENV==="production"?no.exports=ul():no.exports=pl()),no.exports}var Ei=xl();function Bt(t){if(typeof t!="object"||t===null)return!1;const o=Object.getPrototypeOf(t);return(o===null||o===Object.prototype||Object.getPrototypeOf(o)===null)&&!(Symbol.toStringTag in t)&&!(Symbol.iterator in t)}function Bi(t){if(fo.isValidElement(t)||Ei.isValidElementType(t)||!Bt(t))return t;const o={};return Object.keys(t).forEach(n=>{o[n]=Bi(t[n])}),o}function qe(t,o,n={clone:!0}){const i=n.clone?{...t}:t;return Bt(t)&&Bt(o)&&Object.keys(o).forEach(s=>{fo.isValidElement(o[s])||Ei.isValidElementType(o[s])?i[s]=o[s]:Bt(o[s])&&Object.prototype.hasOwnProperty.call(t,s)&&Bt(t[s])?i[s]=qe(t[s],o[s],n):n.clone?i[s]=Bt(o[s])?Bi(o[s]):o[s]:i[s]=o[s]}),i}const ml=t=>{const o=Object.keys(t).map(n=>({key:n,val:t[n]}))||[];return o.sort((n,i)=>n.val-i.val),o.reduce((n,i)=>({...n,[i.key]:i.val}),{})};function fl(t){const{values:o={xs:0,sm:600,md:900,lg:1200,xl:1536},unit:n="px",step:i=5,...s}=t,c=ml(o),d=Object.keys(c);function l(f){return`@media (min-width:${typeof o[f]=="number"?o[f]:f}${n})`}function u(f){return`@media (max-width:${(typeof o[f]=="number"?o[f]:f)-i/100}${n})`}function m(f,g){const T=d.indexOf(g);return`@media (min-width:${typeof o[f]=="number"?o[f]:f}${n}) and (max-width:${(T!==-1&&typeof o[d[T]]=="number"?o[d[T]]:g)-i/100}${n})`}function h(f){return d.indexOf(f)+1<d.length?m(f,d[d.indexOf(f)+1]):l(f)}function b(f){const g=d.indexOf(f);return g===0?l(d[1]):g===d.length-1?u(d[g]):m(f,d[d.indexOf(f)+1]).replace("@media","@media not all and")}return{keys:d,values:c,up:l,down:u,between:m,only:h,not:b,unit:n,...s}}function Rn(t,o){if(!t.containerQueries)return o;const n=Object.keys(o).filter(i=>i.startsWith("@container")).sort((i,s)=>{var d,l;const c=/min-width:\s*([0-9.]+)/;return+(((d=i.match(c))==null?void 0:d[1])||0)-+(((l=s.match(c))==null?void 0:l[1])||0)});return n.length?n.reduce((i,s)=>{const c=o[s];return delete i[s],i[s]=c,i},{...o}):o}function hl(t,o){return o==="@"||o.startsWith("@")&&(t.some(n=>o.startsWith(`@${n}`))||!!o.match(/^@\d/))}function gl(t,o){const n=o.match(/^@([^/]+)?\/?(.+)?$/);if(!n){if(process.env.NODE_ENV!=="production")throw new Error(`MUI: The provided shorthand ${`(${o})`} is invalid. The format should be \`@<breakpoint | number>\` or \`@<breakpoint | number>/<container>\`.
|
|
39
|
+
For example, \`@sm\` or \`@600\` or \`@40rem/sidebar\`.`);return null}const[,i,s]=n,c=Number.isNaN(+i)?i||0:+i;return t.containerQueries(s).up(c)}function yl(t){const o=(c,d)=>c.replace("@media",d?`@container ${d}`:"@container");function n(c,d){c.up=(...l)=>o(t.breakpoints.up(...l),d),c.down=(...l)=>o(t.breakpoints.down(...l),d),c.between=(...l)=>o(t.breakpoints.between(...l),d),c.only=(...l)=>o(t.breakpoints.only(...l),d),c.not=(...l)=>{const u=o(t.breakpoints.not(...l),d);return u.includes("not all and")?u.replace("not all and ","").replace("min-width:","width<").replace("max-width:","width>").replace("and","or"):u}}const i={},s=c=>(n(i,c),i);return n(s),{...t,containerQueries:s}}const bl={borderRadius:4},Ot=process.env.NODE_ENV!=="production"?Rr.oneOfType([Rr.number,Rr.string,Rr.object,Rr.array]):{};function Yr(t,o){return o?qe(t,o,{clone:!1}):t}const yo={xs:0,sm:600,md:900,lg:1200,xl:1536},Pn={keys:["xs","sm","md","lg","xl"],up:t=>`@media (min-width:${yo[t]}px)`},vl={containerQueries:t=>({up:o=>{let n=typeof o=="number"?o:yo[o]||o;return typeof n=="number"&&(n=`${n}px`),t?`@container ${t} (min-width:${n})`:`@container (min-width:${n})`}})};function kt(t,o,n){const i=t.theme||{};if(Array.isArray(o)){const c=i.breakpoints||Pn;return o.reduce((d,l,u)=>(d[c.up(c.keys[u])]=n(o[u]),d),{})}if(typeof o=="object"){const c=i.breakpoints||Pn;return Object.keys(o).reduce((d,l)=>{if(hl(c.keys,l)){const u=gl(i.containerQueries?i:vl,l);u&&(d[u]=n(o[l],l))}else if(Object.keys(c.values||yo).includes(l)){const u=c.up(l);d[u]=n(o[l],l)}else{const u=l;d[u]=o[u]}return d},{})}return n(o)}function Sl(t={}){var n;return((n=t.keys)==null?void 0:n.reduce((i,s)=>{const c=t.up(s);return i[c]={},i},{}))||{}}function Nn(t,o){return t.reduce((n,i)=>{const s=n[i];return(!s||Object.keys(s).length===0)&&delete n[i],n},o)}function Di(t){if(typeof t!="string")throw new Error(process.env.NODE_ENV!=="production"?"MUI: `capitalize(string)` expects a string argument.":Yt(7));return t.charAt(0).toUpperCase()+t.slice(1)}function bo(t,o,n=!0){if(!o||typeof o!="string")return null;if(t&&t.vars&&n){const i=`vars.${o}`.split(".").reduce((s,c)=>s&&s[c]?s[c]:null,t);if(i!=null)return i}return o.split(".").reduce((i,s)=>i&&i[s]!=null?i[s]:null,t)}function mo(t,o,n,i=n){let s;return typeof t=="function"?s=t(n):Array.isArray(t)?s=t[n]||i:s=bo(t,n)||i,o&&(s=o(s,i,t)),s}function Be(t){const{prop:o,cssProperty:n=t.prop,themeKey:i,transform:s}=t,c=d=>{if(d[o]==null)return null;const l=d[o],u=d.theme,m=bo(u,i)||{};return kt(d,l,b=>{let f=mo(m,s,b);return b===f&&typeof b=="string"&&(f=mo(m,s,`${o}${b==="default"?"":Di(b)}`,b)),n===!1?f:{[n]:f}})};return c.propTypes=process.env.NODE_ENV!=="production"?{[o]:Ot}:{},c.filterProps=[o],c}function jl(t){const o={};return n=>(o[n]===void 0&&(o[n]=t(n)),o[n])}const Cl={m:"margin",p:"padding"},wl={t:"Top",r:"Right",b:"Bottom",l:"Left",x:["Left","Right"],y:["Top","Bottom"]},Ln={marginX:"mx",marginY:"my",paddingX:"px",paddingY:"py"},kl=jl(t=>{if(t.length>2)if(Ln[t])t=Ln[t];else return[t];const[o,n]=t.split(""),i=Cl[o],s=wl[n]||"";return Array.isArray(s)?s.map(c=>i+c):[i+s]}),vo=["m","mt","mr","mb","ml","mx","my","margin","marginTop","marginRight","marginBottom","marginLeft","marginX","marginY","marginInline","marginInlineStart","marginInlineEnd","marginBlock","marginBlockStart","marginBlockEnd"],So=["p","pt","pr","pb","pl","px","py","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","paddingX","paddingY","paddingInline","paddingInlineStart","paddingInlineEnd","paddingBlock","paddingBlockStart","paddingBlockEnd"],Tl=[...vo,...So];function qr(t,o,n,i){const s=bo(t,o,!0)??n;return typeof s=="number"||typeof s=="string"?c=>typeof c=="string"?c:(process.env.NODE_ENV!=="production"&&typeof c!="number"&&console.error(`MUI: Expected ${i} argument to be a number or a string, got ${c}.`),typeof s=="string"?s.startsWith("var(")&&c===0?0:s.startsWith("var(")&&c===1?s:`calc(${c} * ${s})`:s*c):Array.isArray(s)?c=>{if(typeof c=="string")return c;const d=Math.abs(c);process.env.NODE_ENV!=="production"&&(Number.isInteger(d)?d>s.length-1&&console.error([`MUI: The value provided (${d}) overflows.`,`The supported values are: ${JSON.stringify(s)}.`,`${d} > ${s.length-1}, you need to add the missing values.`].join(`
|
|
40
40
|
`)):console.error([`MUI: The \`theme.${o}\` array type cannot be combined with non integer values.You should either use an integer value that can be used as index, or define the \`theme.${o}\` as a number.`].join(`
|
|
41
41
|
`)));const l=s[d];return c>=0?l:typeof l=="number"?-l:typeof l=="string"&&l.startsWith("var(")?`calc(-1 * ${l})`:`-${l}`}:typeof s=="function"?s:(process.env.NODE_ENV!=="production"&&console.error([`MUI: The \`theme.${o}\` value (${s}) is invalid.`,"It should be a number, an array or a function."].join(`
|
|
42
|
-
`)),()=>{})}function 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().`:
|
|
44
|
-
The following color spaces are supported: srgb, display-p3, a98-rgb, prophoto-rgb, rec-2020.`:
|
|
45
|
-
`))}return
|
|
46
|
-
The color object needs to have a \`main\` property or a \`${
|
|
47
|
-
\`color.main\` should be a string, but \`${JSON.stringify(
|
|
42
|
+
`)),()=>{})}function rn(t){return qr(t,"spacing",8,"spacing")}function Jr(t,o){return typeof o=="string"||o==null?o:t(o)}function Il(t,o){return n=>t.reduce((i,s)=>(i[s]=Jr(o,n),i),{})}function zl(t,o,n,i){if(!o.includes(n))return null;const s=kl(n),c=Il(s,i),d=t[n];return kt(t,d,c)}function Oi(t,o){const n=rn(t.theme);return Object.keys(t).map(i=>zl(t,o,i,n)).reduce(Yr,{})}function Ie(t){return Oi(t,vo)}Ie.propTypes=process.env.NODE_ENV!=="production"?vo.reduce((t,o)=>(t[o]=Ot,t),{}):{};Ie.filterProps=vo;function ze(t){return Oi(t,So)}ze.propTypes=process.env.NODE_ENV!=="production"?So.reduce((t,o)=>(t[o]=Ot,t),{}):{};ze.filterProps=So;process.env.NODE_ENV!=="production"&&Tl.reduce((t,o)=>(t[o]=Ot,t),{});function Ai(t=8,o=rn({spacing:t})){if(t.mui)return t;const n=(...i)=>(process.env.NODE_ENV!=="production"&&(i.length<=4||console.error(`MUI: Too many arguments provided, expected between 0 and 4, got ${i.length}`)),(i.length===0?[1]:i).map(c=>{const d=o(c);return typeof d=="number"?`${d}px`:d}).join(" "));return n.mui=!0,n}function jo(...t){const o=t.reduce((i,s)=>(s.filterProps.forEach(c=>{i[c]=s}),i),{}),n=i=>Object.keys(i).reduce((s,c)=>o[c]?Yr(s,o[c](i)):s,{});return n.propTypes=process.env.NODE_ENV!=="production"?t.reduce((i,s)=>Object.assign(i,s.propTypes),{}):{},n.filterProps=t.reduce((i,s)=>i.concat(s.filterProps),[]),n}function Qe(t){return typeof t!="number"?t:`${t}px solid`}function et(t,o){return Be({prop:t,themeKey:"borders",transform:o})}const El=et("border",Qe),Bl=et("borderTop",Qe),Dl=et("borderRight",Qe),Ol=et("borderBottom",Qe),Al=et("borderLeft",Qe),Ml=et("borderColor"),_l=et("borderTopColor"),$l=et("borderRightColor"),Wl=et("borderBottomColor"),Rl=et("borderLeftColor"),Pl=et("outline",Qe),Nl=et("outlineColor"),Co=t=>{if(t.borderRadius!==void 0&&t.borderRadius!==null){const o=qr(t.theme,"shape.borderRadius",4,"borderRadius"),n=i=>({borderRadius:Jr(o,i)});return kt(t,t.borderRadius,n)}return null};Co.propTypes=process.env.NODE_ENV!=="production"?{borderRadius:Ot}:{};Co.filterProps=["borderRadius"];jo(El,Bl,Dl,Ol,Al,Ml,_l,$l,Wl,Rl,Co,Pl,Nl);const wo=t=>{if(t.gap!==void 0&&t.gap!==null){const o=qr(t.theme,"spacing",8,"gap"),n=i=>({gap:Jr(o,i)});return kt(t,t.gap,n)}return null};wo.propTypes=process.env.NODE_ENV!=="production"?{gap:Ot}:{};wo.filterProps=["gap"];const ko=t=>{if(t.columnGap!==void 0&&t.columnGap!==null){const o=qr(t.theme,"spacing",8,"columnGap"),n=i=>({columnGap:Jr(o,i)});return kt(t,t.columnGap,n)}return null};ko.propTypes=process.env.NODE_ENV!=="production"?{columnGap:Ot}:{};ko.filterProps=["columnGap"];const To=t=>{if(t.rowGap!==void 0&&t.rowGap!==null){const o=qr(t.theme,"spacing",8,"rowGap"),n=i=>({rowGap:Jr(o,i)});return kt(t,t.rowGap,n)}return null};To.propTypes=process.env.NODE_ENV!=="production"?{rowGap:Ot}:{};To.filterProps=["rowGap"];const Ll=Be({prop:"gridColumn"}),Fl=Be({prop:"gridRow"}),Vl=Be({prop:"gridAutoFlow"}),Hl=Be({prop:"gridAutoColumns"}),Ul=Be({prop:"gridAutoRows"}),Yl=Be({prop:"gridTemplateColumns"}),Gl=Be({prop:"gridTemplateRows"}),ql=Be({prop:"gridTemplateAreas"}),Jl=Be({prop:"gridArea"});jo(wo,ko,To,Ll,Fl,Vl,Hl,Ul,Yl,Gl,ql,Jl);function fr(t,o){return o==="grey"?o:t}const Kl=Be({prop:"color",themeKey:"palette",transform:fr}),Xl=Be({prop:"bgcolor",cssProperty:"backgroundColor",themeKey:"palette",transform:fr}),Zl=Be({prop:"backgroundColor",themeKey:"palette",transform:fr});jo(Kl,Xl,Zl);function Ye(t){return t<=1&&t!==0?`${t*100}%`:t}const Ql=Be({prop:"width",transform:Ye}),on=t=>{if(t.maxWidth!==void 0&&t.maxWidth!==null){const o=n=>{var s,c,d,l,u;const i=((d=(c=(s=t.theme)==null?void 0:s.breakpoints)==null?void 0:c.values)==null?void 0:d[n])||yo[n];return i?((u=(l=t.theme)==null?void 0:l.breakpoints)==null?void 0:u.unit)!=="px"?{maxWidth:`${i}${t.theme.breakpoints.unit}`}:{maxWidth:i}:{maxWidth:Ye(n)}};return kt(t,t.maxWidth,o)}return null};on.filterProps=["maxWidth"];const ec=Be({prop:"minWidth",transform:Ye}),tc=Be({prop:"height",transform:Ye}),rc=Be({prop:"maxHeight",transform:Ye}),oc=Be({prop:"minHeight",transform:Ye});Be({prop:"size",cssProperty:"width",transform:Ye});Be({prop:"size",cssProperty:"height",transform:Ye});const nc=Be({prop:"boxSizing"});jo(Ql,on,ec,tc,rc,oc,nc);const Io={border:{themeKey:"borders",transform:Qe},borderTop:{themeKey:"borders",transform:Qe},borderRight:{themeKey:"borders",transform:Qe},borderBottom:{themeKey:"borders",transform:Qe},borderLeft:{themeKey:"borders",transform:Qe},borderColor:{themeKey:"palette"},borderTopColor:{themeKey:"palette"},borderRightColor:{themeKey:"palette"},borderBottomColor:{themeKey:"palette"},borderLeftColor:{themeKey:"palette"},outline:{themeKey:"borders",transform:Qe},outlineColor:{themeKey:"palette"},borderRadius:{themeKey:"shape.borderRadius",style:Co},color:{themeKey:"palette",transform:fr},bgcolor:{themeKey:"palette",cssProperty:"backgroundColor",transform:fr},backgroundColor:{themeKey:"palette",transform:fr},p:{style:ze},pt:{style:ze},pr:{style:ze},pb:{style:ze},pl:{style:ze},px:{style:ze},py:{style:ze},padding:{style:ze},paddingTop:{style:ze},paddingRight:{style:ze},paddingBottom:{style:ze},paddingLeft:{style:ze},paddingX:{style:ze},paddingY:{style:ze},paddingInline:{style:ze},paddingInlineStart:{style:ze},paddingInlineEnd:{style:ze},paddingBlock:{style:ze},paddingBlockStart:{style:ze},paddingBlockEnd:{style:ze},m:{style:Ie},mt:{style:Ie},mr:{style:Ie},mb:{style:Ie},ml:{style:Ie},mx:{style:Ie},my:{style:Ie},margin:{style:Ie},marginTop:{style:Ie},marginRight:{style:Ie},marginBottom:{style:Ie},marginLeft:{style:Ie},marginX:{style:Ie},marginY:{style:Ie},marginInline:{style:Ie},marginInlineStart:{style:Ie},marginInlineEnd:{style:Ie},marginBlock:{style:Ie},marginBlockStart:{style:Ie},marginBlockEnd:{style:Ie},displayPrint:{cssProperty:!1,transform:t=>({"@media print":{display:t}})},display:{},overflow:{},textOverflow:{},visibility:{},whiteSpace:{},flexBasis:{},flexDirection:{},flexWrap:{},justifyContent:{},alignItems:{},alignContent:{},order:{},flex:{},flexGrow:{},flexShrink:{},alignSelf:{},justifyItems:{},justifySelf:{},gap:{style:wo},rowGap:{style:To},columnGap:{style:ko},gridColumn:{},gridRow:{},gridAutoFlow:{},gridAutoColumns:{},gridAutoRows:{},gridTemplateColumns:{},gridTemplateRows:{},gridTemplateAreas:{},gridArea:{},position:{},zIndex:{themeKey:"zIndex"},top:{},right:{},bottom:{},left:{},boxShadow:{themeKey:"shadows"},width:{transform:Ye},maxWidth:{style:on},minWidth:{transform:Ye},height:{transform:Ye},maxHeight:{transform:Ye},minHeight:{transform:Ye},boxSizing:{},font:{themeKey:"font"},fontFamily:{themeKey:"typography"},fontSize:{themeKey:"typography"},fontStyle:{themeKey:"typography"},fontWeight:{themeKey:"typography"},letterSpacing:{},textTransform:{},lineHeight:{},textAlign:{},typography:{cssProperty:!1,themeKey:"typography"}};function ic(...t){const o=t.reduce((i,s)=>i.concat(Object.keys(s)),[]),n=new Set(o);return t.every(i=>n.size===Object.keys(i).length)}function sc(t,o){return typeof t=="function"?t(o):t}function ac(){function t(n,i,s,c){const d={[n]:i,theme:s},l=c[n];if(!l)return{[n]:i};const{cssProperty:u=n,themeKey:m,transform:h,style:b}=l;if(i==null)return null;if(m==="typography"&&i==="inherit")return{[n]:i};const f=bo(s,m)||{};return b?b(d):kt(d,i,T=>{let y=mo(f,h,T);return T===y&&typeof T=="string"&&(y=mo(f,h,`${n}${T==="default"?"":Di(T)}`,T)),u===!1?y:{[u]:y}})}function o(n){const{sx:i,theme:s={},nested:c}=n||{};if(!i)return null;const d=s.unstable_sxConfig??Io;function l(u){let m=u;if(typeof u=="function")m=u(s);else if(typeof u!="object")return u;if(!m)return null;const h=Sl(s.breakpoints),b=Object.keys(h);let f=h;return Object.keys(m).forEach(g=>{const T=sc(m[g],s);if(T!=null)if(typeof T=="object")if(d[g])f=Yr(f,t(g,T,s,d));else{const y=kt({theme:s},T,w=>({[g]:w}));ic(y,T)?f[g]=o({sx:T,theme:s,nested:!0}):f=Yr(f,y)}else f=Yr(f,t(g,T,s,d))}),!c&&s.modularCssLayers?{"@layer sx":Rn(s,Nn(b,f))}:Rn(s,Nn(b,f))}return Array.isArray(i)?i.map(l):l(i)}return o}const zo=ac();zo.filterProps=["sx"];function lc(t,o){var i;const n=this;if(n.vars){if(!((i=n.colorSchemes)!=null&&i[t])||typeof n.getColorSchemeSelector!="function")return{};let s=n.getColorSchemeSelector(t);return s==="&"?o:((s.includes("data-")||s.includes("."))&&(s=`*:where(${s.replace(/\s*&$/,"")}) &`),{[s]:o})}return n.palette.mode===t?o:{}}function Mi(t={},...o){const{breakpoints:n={},palette:i={},spacing:s,shape:c={},...d}=t,l=fl(n),u=Ai(s);let m=qe({breakpoints:l,direction:"ltr",components:{},palette:{mode:"light",...i},spacing:u,shape:{...bl,...c}},d);return m=yl(m),m.applyStyles=lc,m=o.reduce((h,b)=>qe(h,b),m),m.unstable_sxConfig={...Io,...d==null?void 0:d.unstable_sxConfig},m.unstable_sx=function(b){return zo({sx:b,theme:this})},m}function cc(t){return Object.keys(t).length===0}function dc(t=null){const o=fo.useContext(Ts.ThemeContext);return!o||cc(o)?t:o}const uc=Mi();function pc(t=uc){return dc(t)}const Fn=t=>t,xc=()=>{let t=Fn;return{configure(o){t=o},generate(o){return t(o)},reset(){t=Fn}}},mc=xc(),fc={active:"active",checked:"checked",completed:"completed",disabled:"disabled",error:"error",expanded:"expanded",focused:"focused",focusVisible:"focusVisible",open:"open",readOnly:"readOnly",required:"required",selected:"selected"};function hc(t,o,n="Mui"){const i=fc[o];return i?`${n}-${i}`:`${mc.generate(t)}-${o}`}function gc(t,o=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER){return Math.max(o,Math.min(t,n))}function nn(t,o=0,n=1){return process.env.NODE_ENV!=="production"&&(t<o||t>n)&&console.error(`MUI: The value provided ${t} is out of range [${o}, ${n}].`),gc(t,o,n)}function yc(t){t=t.slice(1);const o=new RegExp(`.{1,${t.length>=6?2:1}}`,"g");let n=t.match(o);return n&&n[0].length===1&&(n=n.map(i=>i+i)),process.env.NODE_ENV!=="production"&&t.length!==t.trim().length&&console.error(`MUI: The color: "${t}" is invalid. Make sure the color input doesn't contain leading/trailing space.`),n?`rgb${n.length===4?"a":""}(${n.map((i,s)=>s<3?parseInt(i,16):Math.round(parseInt(i,16)/255*1e3)/1e3).join(", ")})`:""}function Dt(t){if(t.type)return t;if(t.charAt(0)==="#")return Dt(yc(t));const o=t.indexOf("("),n=t.substring(0,o);if(!["rgb","rgba","hsl","hsla","color"].includes(n))throw new Error(process.env.NODE_ENV!=="production"?`MUI: Unsupported \`${t}\` color.
|
|
43
|
+
The following formats are supported: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color().`:Yt(9,t));let i=t.substring(o+1,t.length-1),s;if(n==="color"){if(i=i.split(" "),s=i.shift(),i.length===4&&i[3].charAt(0)==="/"&&(i[3]=i[3].slice(1)),!["srgb","display-p3","a98-rgb","prophoto-rgb","rec-2020"].includes(s))throw new Error(process.env.NODE_ENV!=="production"?`MUI: unsupported \`${s}\` color space.
|
|
44
|
+
The following color spaces are supported: srgb, display-p3, a98-rgb, prophoto-rgb, rec-2020.`:Yt(10,s))}else i=i.split(",");return i=i.map(c=>parseFloat(c)),{type:n,values:i,colorSpace:s}}const bc=t=>{const o=Dt(t);return o.values.slice(0,3).map((n,i)=>o.type.includes("hsl")&&i!==0?`${n}%`:n).join(" ")},Vr=(t,o)=>{try{return bc(t)}catch{return o&&process.env.NODE_ENV!=="production"&&console.warn(o),t}};function Eo(t){const{type:o,colorSpace:n}=t;let{values:i}=t;return o.includes("rgb")?i=i.map((s,c)=>c<3?parseInt(s,10):s):o.includes("hsl")&&(i[1]=`${i[1]}%`,i[2]=`${i[2]}%`),o.includes("color")?i=`${n} ${i.join(" ")}`:i=`${i.join(", ")}`,`${o}(${i})`}function _i(t){t=Dt(t);const{values:o}=t,n=o[0],i=o[1]/100,s=o[2]/100,c=i*Math.min(s,1-s),d=(m,h=(m+n/30)%12)=>s-c*Math.max(Math.min(h-3,9-h,1),-1);let l="rgb";const u=[Math.round(d(0)*255),Math.round(d(8)*255),Math.round(d(4)*255)];return t.type==="hsla"&&(l+="a",u.push(o[3])),Eo({type:l,values:u})}function Yo(t){t=Dt(t);let o=t.type==="hsl"||t.type==="hsla"?Dt(_i(t)).values:t.values;return o=o.map(n=>(t.type!=="color"&&(n/=255),n<=.03928?n/12.92:((n+.055)/1.055)**2.4)),Number((.2126*o[0]+.7152*o[1]+.0722*o[2]).toFixed(3))}function Vn(t,o){const n=Yo(t),i=Yo(o);return(Math.max(n,i)+.05)/(Math.min(n,i)+.05)}function E(t,o){return t=Dt(t),o=nn(o),(t.type==="rgb"||t.type==="hsl")&&(t.type+="a"),t.type==="color"?t.values[3]=`/${o}`:t.values[3]=o,Eo(t)}function Vt(t,o,n){try{return E(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Bo(t,o){if(t=Dt(t),o=nn(o),t.type.includes("hsl"))t.values[2]*=1-o;else if(t.type.includes("rgb")||t.type.includes("color"))for(let n=0;n<3;n+=1)t.values[n]*=1-o;return Eo(t)}function ye(t,o,n){try{return Bo(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Do(t,o){if(t=Dt(t),o=nn(o),t.type.includes("hsl"))t.values[2]+=(100-t.values[2])*o;else if(t.type.includes("rgb"))for(let n=0;n<3;n+=1)t.values[n]+=(255-t.values[n])*o;else if(t.type.includes("color"))for(let n=0;n<3;n+=1)t.values[n]+=(1-t.values[n])*o;return Eo(t)}function be(t,o,n){try{return Do(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function vc(t,o=.15){return Yo(t)>.5?Bo(t,o):Do(t,o)}function io(t,o,n){try{return vc(t,o)}catch{return t}}function Sc(t=""){function o(...i){if(!i.length)return"";const s=i[0];return typeof s=="string"&&!s.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))|^(-?(\d*\.)?\d+)$|(\d+ \d+ \d+)/)?`, var(--${t?`${t}-`:""}${s}${o(...i.slice(1))})`:`, ${s}`}return(i,...s)=>`var(--${t?`${t}-`:""}${i}${o(...s)})`}const Hn=(t,o,n,i=[])=>{let s=t;o.forEach((c,d)=>{d===o.length-1?Array.isArray(s)?s[Number(c)]=n:s&&typeof s=="object"&&(s[c]=n):s&&typeof s=="object"&&(s[c]||(s[c]=i.includes(c)?[]:{}),s=s[c])})},jc=(t,o,n)=>{function i(s,c=[],d=[]){Object.entries(s).forEach(([l,u])=>{(!n||n&&!n([...c,l]))&&u!=null&&(typeof u=="object"&&Object.keys(u).length>0?i(u,[...c,l],Array.isArray(u)?[...d,l]:d):o([...c,l],u,d))})}i(t)},Cc=(t,o)=>typeof o=="number"?["lineHeight","fontWeight","opacity","zIndex"].some(i=>t.includes(i))||t[t.length-1].toLowerCase().includes("opacity")?o:`${o}px`:o;function Fo(t,o){const{prefix:n,shouldSkipGeneratingVar:i}=o||{},s={},c={},d={};return jc(t,(l,u,m)=>{if((typeof u=="string"||typeof u=="number")&&(!i||!i(l,u))){const h=`--${n?`${n}-`:""}${l.join("-")}`,b=Cc(l,u);Object.assign(s,{[h]:b}),Hn(c,l,`var(${h})`,m),Hn(d,l,`var(${h}, ${b})`,m)}},l=>l[0]==="vars"),{css:s,vars:c,varsWithDefaults:d}}function wc(t,o={}){const{getSelector:n=v,disableCssColorScheme:i,colorSchemeSelector:s,enableContrastVars:c}=o,{colorSchemes:d={},components:l,defaultColorScheme:u="light",...m}=t,{vars:h,css:b,varsWithDefaults:f}=Fo(m,o);let g=f;const T={},{[u]:y,...w}=d;if(Object.entries(w||{}).forEach(([I,a])=>{const{vars:A,css:B,varsWithDefaults:$}=Fo(a,o);g=qe(g,$),T[I]={css:B,vars:A}}),y){const{css:I,vars:a,varsWithDefaults:A}=Fo(y,o);g=qe(g,A),T[u]={css:I,vars:a}}function v(I,a){var B,$;let A=s;if(s==="class"&&(A=".%s"),s==="data"&&(A="[data-%s]"),s!=null&&s.startsWith("data-")&&!s.includes("%s")&&(A=`[${s}="%s"]`),I){if(A==="media")return t.defaultColorScheme===I?":root":{[`@media (prefers-color-scheme: ${(($=(B=d[I])==null?void 0:B.palette)==null?void 0:$.mode)||I})`]:{":root":a}};if(A)return t.defaultColorScheme===I?`:root, ${A.replace("%s",String(I))}`:A.replace("%s",String(I))}return":root"}return{vars:g,generateThemeVars:()=>{let I={...h};return Object.entries(T).forEach(([,{vars:a}])=>{I=qe(I,a)}),I},generateStyleSheets:()=>{var Y,Q;const I=[],a=t.defaultColorScheme||"light";function A(te,x){Object.keys(x).length&&I.push(typeof te=="string"?{[te]:{...x}}:te)}A(n(void 0,{...b}),b);const{[a]:B,...$}=T;if(B){const{css:te}=B,x=(Q=(Y=d[a])==null?void 0:Y.palette)==null?void 0:Q.mode,N=!i&&x?{colorScheme:x,...te}:{...te};A(n(a,{...N}),N)}return Object.entries($).forEach(([te,{css:x}])=>{var H,J;const N=(J=(H=d[te])==null?void 0:H.palette)==null?void 0:J.mode,W=!i&&N?{colorScheme:N,...x}:{...x};A(n(te,{...W}),W)}),c&&I.push({":root":{"--__l-threshold":"0.7","--__l":"clamp(0, (l / var(--__l-threshold) - 1) * -infinity, 1)","--__a":"clamp(0.87, (l / var(--__l-threshold) - 1) * -infinity, 1)"}}),I}}}function kc(t){return function(n){return t==="media"?(process.env.NODE_ENV!=="production"&&n!=="light"&&n!=="dark"&&console.error(`MUI: @media (prefers-color-scheme) supports only 'light' or 'dark', but receive '${n}'.`),`@media (prefers-color-scheme: ${n})`):t?t.startsWith("data-")&&!t.includes("%s")?`[${t}="${n}"] &`:t==="class"?`.${n} &`:t==="data"?`[data-${n}] &`:`${t.replace("%s",n)} &`:"&"}}const Gr={black:"#000",white:"#fff"},Tc={50:"#fafafa",100:"#f5f5f5",200:"#eeeeee",300:"#e0e0e0",400:"#bdbdbd",500:"#9e9e9e",600:"#757575",700:"#616161",800:"#424242",900:"#212121",A100:"#f5f5f5",A200:"#eeeeee",A400:"#bdbdbd",A700:"#616161"},dr={50:"#f3e5f5",200:"#ce93d8",300:"#ba68c8",400:"#ab47bc",500:"#9c27b0",700:"#7b1fa2"},ur={300:"#e57373",400:"#ef5350",500:"#f44336",700:"#d32f2f",800:"#c62828"},Pr={300:"#ffb74d",400:"#ffa726",500:"#ff9800",700:"#f57c00",900:"#e65100"},pr={50:"#e3f2fd",200:"#90caf9",400:"#42a5f5",700:"#1976d2",800:"#1565c0"},xr={300:"#4fc3f7",400:"#29b6f6",500:"#03a9f4",700:"#0288d1",900:"#01579b"},mr={300:"#81c784",400:"#66bb6a",500:"#4caf50",700:"#388e3c",800:"#2e7d32",900:"#1b5e20"};function $i(){return{text:{primary:"rgba(0, 0, 0, 0.87)",secondary:"rgba(0, 0, 0, 0.6)",disabled:"rgba(0, 0, 0, 0.38)"},divider:"rgba(0, 0, 0, 0.12)",background:{paper:Gr.white,default:Gr.white},action:{active:"rgba(0, 0, 0, 0.54)",hover:"rgba(0, 0, 0, 0.04)",hoverOpacity:.04,selected:"rgba(0, 0, 0, 0.08)",selectedOpacity:.08,disabled:"rgba(0, 0, 0, 0.26)",disabledBackground:"rgba(0, 0, 0, 0.12)",disabledOpacity:.38,focus:"rgba(0, 0, 0, 0.12)",focusOpacity:.12,activatedOpacity:.12}}}const Wi=$i();function Ri(){return{text:{primary:Gr.white,secondary:"rgba(255, 255, 255, 0.7)",disabled:"rgba(255, 255, 255, 0.5)",icon:"rgba(255, 255, 255, 0.5)"},divider:"rgba(255, 255, 255, 0.12)",background:{paper:"#121212",default:"#121212"},action:{active:Gr.white,hover:"rgba(255, 255, 255, 0.08)",hoverOpacity:.08,selected:"rgba(255, 255, 255, 0.16)",selectedOpacity:.16,disabled:"rgba(255, 255, 255, 0.3)",disabledBackground:"rgba(255, 255, 255, 0.12)",disabledOpacity:.38,focus:"rgba(255, 255, 255, 0.12)",focusOpacity:.12,activatedOpacity:.24}}}const Go=Ri();function Un(t,o,n,i){const s=i.light||i,c=i.dark||i*1.5;t[o]||(t.hasOwnProperty(n)?t[o]=t[n]:o==="light"?t.light=Do(t.main,s):o==="dark"&&(t.dark=Bo(t.main,c)))}function Yn(t,o,n,i,s){const c=s.light||s,d=s.dark||s*1.5;o[n]||(o.hasOwnProperty(i)?o[n]=o[i]:n==="light"?o.light=`color-mix(in ${t}, ${o.main}, #fff ${(c*100).toFixed(0)}%)`:n==="dark"&&(o.dark=`color-mix(in ${t}, ${o.main}, #000 ${(d*100).toFixed(0)}%)`))}function Ic(t="light"){return t==="dark"?{main:pr[200],light:pr[50],dark:pr[400]}:{main:pr[700],light:pr[400],dark:pr[800]}}function zc(t="light"){return t==="dark"?{main:dr[200],light:dr[50],dark:dr[400]}:{main:dr[500],light:dr[300],dark:dr[700]}}function Ec(t="light"){return t==="dark"?{main:ur[500],light:ur[300],dark:ur[700]}:{main:ur[700],light:ur[400],dark:ur[800]}}function Bc(t="light"){return t==="dark"?{main:xr[400],light:xr[300],dark:xr[700]}:{main:xr[700],light:xr[500],dark:xr[900]}}function Dc(t="light"){return t==="dark"?{main:mr[400],light:mr[300],dark:mr[700]}:{main:mr[800],light:mr[500],dark:mr[900]}}function Oc(t="light"){return t==="dark"?{main:Pr[400],light:Pr[300],dark:Pr[700]}:{main:"#ed6c02",light:Pr[500],dark:Pr[900]}}function Ac(t){return`oklch(from ${t} var(--__l) 0 h / var(--__a))`}function sn(t){const{mode:o="light",contrastThreshold:n=3,tonalOffset:i=.2,colorSpace:s,...c}=t,d=t.primary||Ic(o),l=t.secondary||zc(o),u=t.error||Ec(o),m=t.info||Bc(o),h=t.success||Dc(o),b=t.warning||Oc(o);function f(w){if(s)return Ac(w);const v=Vn(w,Go.text.primary)>=n?Go.text.primary:Wi.text.primary;if(process.env.NODE_ENV!=="production"){const j=Vn(w,v);j<3&&console.error([`MUI: The contrast ratio of ${j}:1 for ${v} on ${w}`,"falls below the WCAG recommended absolute minimum contrast ratio of 3:1.","https://www.w3.org/TR/2008/REC-WCAG20-20081211/#visual-audio-contrast-contrast"].join(`
|
|
45
|
+
`))}return v}const g=({color:w,name:v,mainShade:j=500,lightShade:S=300,darkShade:I=700})=>{if(w={...w},!w.main&&w[j]&&(w.main=w[j]),!w.hasOwnProperty("main"))throw new Error(process.env.NODE_ENV!=="production"?`MUI: The color${v?` (${v})`:""} provided to augmentColor(color) is invalid.
|
|
46
|
+
The color object needs to have a \`main\` property or a \`${j}\` property.`:Yt(11,v?` (${v})`:"",j));if(typeof w.main!="string")throw new Error(process.env.NODE_ENV!=="production"?`MUI: The color${v?` (${v})`:""} provided to augmentColor(color) is invalid.
|
|
47
|
+
\`color.main\` should be a string, but \`${JSON.stringify(w.main)}\` was provided instead.
|
|
48
48
|
|
|
49
49
|
Did you intend to use one of the following approaches?
|
|
50
50
|
|
|
@@ -56,17 +56,17 @@ const theme1 = createTheme({ palette: {
|
|
|
56
56
|
|
|
57
57
|
const theme2 = createTheme({ palette: {
|
|
58
58
|
primary: { main: green[500] },
|
|
59
|
-
} });`:
|
|
60
|
-
`)),Object.keys(m).length!==0&&console.error(`MUI: Unrecognized argument(s) [${Object.keys(m).join(",")}].`)}return(Array.isArray(s)?s:[s]).map(
|
|
59
|
+
} });`:Yt(12,v?` (${v})`:"",JSON.stringify(w.main)));return s?(Yn(s,w,"light",S,i),Yn(s,w,"dark",I,i)):(Un(w,"light",S,i),Un(w,"dark",I,i)),w.contrastText||(w.contrastText=f(w.main)),w};let T;return o==="light"?T=$i():o==="dark"&&(T=Ri()),process.env.NODE_ENV!=="production"&&(T||console.error(`MUI: The palette mode \`${o}\` is not supported.`)),qe({common:{...Gr},mode:o,primary:g({color:d,name:"primary"}),secondary:g({color:l,name:"secondary",mainShade:"A400",lightShade:"A200",darkShade:"A700"}),error:g({color:u,name:"error"}),warning:g({color:b,name:"warning"}),info:g({color:m,name:"info"}),success:g({color:h,name:"success"}),grey:Tc,contrastThreshold:n,getContrastText:f,augmentColor:g,tonalOffset:i,...T},c)}function Mc(t){const o={};return Object.entries(t).forEach(i=>{const[s,c]=i;typeof c=="object"&&(o[s]=`${c.fontStyle?`${c.fontStyle} `:""}${c.fontVariant?`${c.fontVariant} `:""}${c.fontWeight?`${c.fontWeight} `:""}${c.fontStretch?`${c.fontStretch} `:""}${c.fontSize||""}${c.lineHeight?`/${c.lineHeight} `:""}${c.fontFamily||""}`)}),o}function _c(t,o){return{toolbar:{minHeight:56,[t.up("xs")]:{"@media (orientation: landscape)":{minHeight:48}},[t.up("sm")]:{minHeight:64}},...o}}function $c(t){return Math.round(t*1e5)/1e5}const Gn={textTransform:"uppercase"},qn='"Roboto", "Helvetica", "Arial", sans-serif';function Wc(t,o){const{fontFamily:n=qn,fontSize:i=14,fontWeightLight:s=300,fontWeightRegular:c=400,fontWeightMedium:d=500,fontWeightBold:l=700,htmlFontSize:u=16,allVariants:m,pxToRem:h,...b}=typeof o=="function"?o(t):o;process.env.NODE_ENV!=="production"&&(typeof i!="number"&&console.error("MUI: `fontSize` is required to be a number."),typeof u!="number"&&console.error("MUI: `htmlFontSize` is required to be a number."));const f=i/14,g=h||(w=>`${w/u*f}rem`),T=(w,v,j,S,I)=>({fontFamily:n,fontWeight:w,fontSize:g(v),lineHeight:j,...n===qn?{letterSpacing:`${$c(S/v)}em`}:{},...I,...m}),y={h1:T(s,96,1.167,-1.5),h2:T(s,60,1.2,-.5),h3:T(c,48,1.167,0),h4:T(c,34,1.235,.25),h5:T(c,24,1.334,0),h6:T(d,20,1.6,.15),subtitle1:T(c,16,1.75,.15),subtitle2:T(d,14,1.57,.1),body1:T(c,16,1.5,.15),body2:T(c,14,1.43,.15),button:T(d,14,1.75,.4,Gn),caption:T(c,12,1.66,.4),overline:T(c,12,2.66,1,Gn),inherit:{fontFamily:"inherit",fontWeight:"inherit",fontSize:"inherit",lineHeight:"inherit",letterSpacing:"inherit"}};return qe({htmlFontSize:u,pxToRem:g,fontFamily:n,fontSize:i,fontWeightLight:s,fontWeightRegular:c,fontWeightMedium:d,fontWeightBold:l,...y},b,{clone:!1})}const Rc=.2,Pc=.14,Nc=.12;function Te(...t){return[`${t[0]}px ${t[1]}px ${t[2]}px ${t[3]}px rgba(0,0,0,${Rc})`,`${t[4]}px ${t[5]}px ${t[6]}px ${t[7]}px rgba(0,0,0,${Pc})`,`${t[8]}px ${t[9]}px ${t[10]}px ${t[11]}px rgba(0,0,0,${Nc})`].join(",")}const Lc=["none",Te(0,2,1,-1,0,1,1,0,0,1,3,0),Te(0,3,1,-2,0,2,2,0,0,1,5,0),Te(0,3,3,-2,0,3,4,0,0,1,8,0),Te(0,2,4,-1,0,4,5,0,0,1,10,0),Te(0,3,5,-1,0,5,8,0,0,1,14,0),Te(0,3,5,-1,0,6,10,0,0,1,18,0),Te(0,4,5,-2,0,7,10,1,0,2,16,1),Te(0,5,5,-3,0,8,10,1,0,3,14,2),Te(0,5,6,-3,0,9,12,1,0,3,16,2),Te(0,6,6,-3,0,10,14,1,0,4,18,3),Te(0,6,7,-4,0,11,15,1,0,4,20,3),Te(0,7,8,-4,0,12,17,2,0,5,22,4),Te(0,7,8,-4,0,13,19,2,0,5,24,4),Te(0,7,9,-4,0,14,21,2,0,5,26,4),Te(0,8,9,-5,0,15,22,2,0,6,28,5),Te(0,8,10,-5,0,16,24,2,0,6,30,5),Te(0,8,11,-5,0,17,26,2,0,6,32,5),Te(0,9,11,-5,0,18,28,2,0,7,34,6),Te(0,9,12,-6,0,19,29,2,0,7,36,6),Te(0,10,13,-6,0,20,31,3,0,8,38,7),Te(0,10,13,-6,0,21,33,3,0,8,40,7),Te(0,10,14,-6,0,22,35,3,0,8,42,7),Te(0,11,14,-7,0,23,36,3,0,9,44,8),Te(0,11,15,-7,0,24,38,3,0,9,46,8)],Fc={easeInOut:"cubic-bezier(0.4, 0, 0.2, 1)",easeOut:"cubic-bezier(0.0, 0, 0.2, 1)",easeIn:"cubic-bezier(0.4, 0, 1, 1)",sharp:"cubic-bezier(0.4, 0, 0.6, 1)"},Vc={shortest:150,shorter:200,short:250,standard:300,complex:375,enteringScreen:225,leavingScreen:195};function Jn(t){return`${Math.round(t)}ms`}function Hc(t){if(!t)return 0;const o=t/36;return Math.min(Math.round((4+15*o**.25+o/5)*10),3e3)}function Uc(t){const o={...Fc,...t.easing},n={...Vc,...t.duration};return{getAutoHeightDuration:Hc,create:(s=["all"],c={})=>{const{duration:d=n.standard,easing:l=o.easeInOut,delay:u=0,...m}=c;if(process.env.NODE_ENV!=="production"){const h=f=>typeof f=="string",b=f=>!Number.isNaN(parseFloat(f));!h(s)&&!Array.isArray(s)&&console.error('MUI: Argument "props" must be a string or Array.'),!b(d)&&!h(d)&&console.error(`MUI: Argument "duration" must be a number or a string but found ${d}.`),h(l)||console.error('MUI: Argument "easing" must be a string.'),!b(u)&&!h(u)&&console.error('MUI: Argument "delay" must be a number or a string.'),typeof c!="object"&&console.error(["MUI: Secong argument of transition.create must be an object.","Arguments should be either `create('prop1', options)` or `create(['prop1', 'prop2'], options)`"].join(`
|
|
60
|
+
`)),Object.keys(m).length!==0&&console.error(`MUI: Unrecognized argument(s) [${Object.keys(m).join(",")}].`)}return(Array.isArray(s)?s:[s]).map(h=>`${h} ${typeof d=="string"?d:Jn(d)} ${l} ${typeof u=="string"?u:Jn(u)}`).join(",")},...t,easing:o,duration:n}}const Yc={mobileStepper:1e3,fab:1050,speedDial:1050,appBar:1100,drawer:1200,modal:1300,snackbar:1400,tooltip:1500};function Gc(t){return Bt(t)||typeof t>"u"||typeof t=="string"||typeof t=="boolean"||typeof t=="number"||Array.isArray(t)}function Pi(t={}){const o={...t};function n(i){const s=Object.entries(i);for(let c=0;c<s.length;c++){const[d,l]=s[c];!Gc(l)||d.startsWith("unstable_")?delete i[d]:Bt(l)&&(i[d]={...l},n(i[d]))}}return n(o),`import { unstable_createBreakpoints as createBreakpoints, createTransitions } from '@mui/material/styles';
|
|
61
61
|
|
|
62
62
|
const theme = ${JSON.stringify(o,null,2)};
|
|
63
63
|
|
|
64
64
|
theme.breakpoints = createBreakpoints(theme.breakpoints || {});
|
|
65
65
|
theme.transitions = createTransitions(theme.transitions || {});
|
|
66
66
|
|
|
67
|
-
export default theme;`}function
|
|
68
|
-
`))}j
|
|
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 qc=t=>{if(!Number.isNaN(+t))return+t;const o=t.match(/\d*\.?\d+/g);if(!o)return 0;let n=0;for(let i=0;i<o.length;i+=1)n+=+o[i];return n};function Jc(t){Object.assign(t,{alpha(o,n){const i=this||t;return i.colorSpace?`oklch(from ${o} l c h / ${typeof n=="string"?`calc(${n})`:n})`:i.vars?`rgba(${o.replace(/var\(--([^,\s)]+)(?:,[^)]+)?\)+/g,"var(--$1Channel)")} / ${typeof n=="string"?`calc(${n})`:n})`:E(o,qc(n))},lighten(o,n){const i=this||t;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${o}, #fff ${Kn(n)})`:Do(o,n)},darken(o,n){const i=this||t;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${o}, #000 ${Kn(n)})`:Bo(o,n)}})}function qo(t={},...o){const{breakpoints:n,mixins:i={},spacing:s,palette:c={},transitions:d={},typography:l={},shape:u,colorSpace:m,...h}=t;if(t.vars&&t.generateThemeVars===void 0)throw new Error(process.env.NODE_ENV!=="production"?"MUI: `vars` is a private field used for CSS variables support.\nPlease use another name or follow the [docs](https://mui.com/material-ui/customization/css-theme-variables/usage/) to enable the feature.":Yt(20));const b=sn({...c,colorSpace:m}),f=Mi(t);let g=qe(f,{mixins:_c(f.breakpoints,i),palette:b,shadows:Lc.slice(),typography:Wc(b,l),transitions:Uc(d),zIndex:{...Yc}});if(g=qe(g,h),g=o.reduce((T,y)=>qe(T,y),g),process.env.NODE_ENV!=="production"){const T=["active","checked","completed","disabled","error","expanded","focused","focusVisible","required","selected"],y=(w,v)=>{let j;for(j in w){const S=w[j];if(T.includes(j)&&Object.keys(S).length>0){if(process.env.NODE_ENV!=="production"){const I=hc("",j);console.error([`MUI: The \`${v}\` component increases the CSS specificity of the \`${j}\` internal state.`,"You can not override it like this: ",JSON.stringify(w,null,2),"",`Instead, you need to use the '&.${I}' syntax:`,JSON.stringify({root:{[`&.${I}`]:S}},null,2),"","https://mui.com/r/state-classes-guide"].join(`
|
|
68
|
+
`))}w[j]={}}}};Object.keys(g.components).forEach(w=>{const v=g.components[w].styleOverrides;v&&w.startsWith("Mui")&&y(v,w)})}return g.unstable_sxConfig={...Io,...h==null?void 0:h.unstable_sxConfig},g.unstable_sx=function(y){return zo({sx:y,theme:this})},g.toRuntimeSource=Pi,Jc(g),g}function Kc(t){let o;return t<1?o=5.11916*t**2:o=4.5*Math.log(t+1)+2,Math.round(o*10)/1e3}const Xc=[...Array(25)].map((t,o)=>{if(o===0)return"none";const n=Kc(o);return`linear-gradient(rgba(255 255 255 / ${n}), rgba(255 255 255 / ${n}))`});function Ni(t){return{inputPlaceholder:t==="dark"?.5:.42,inputUnderline:t==="dark"?.7:.42,switchTrackDisabled:t==="dark"?.2:.12,switchTrack:t==="dark"?.3:.38}}function Li(t){return t==="dark"?Xc:[]}function Zc(t){const{palette:o={mode:"light"},opacity:n,overlays:i,colorSpace:s,...c}=t,d=sn({...o,colorSpace:s});return{palette:d,opacity:{...Ni(d.mode),...n},overlays:i||Li(d.mode),...c}}function Qc(t){var o;return!!t[0].match(/(cssVarPrefix|colorSchemeSelector|modularCssLayers|rootSelector|typography|mixins|breakpoints|direction|transitions)/)||!!t[0].match(/sxConfig$/)||t[0]==="palette"&&!!((o=t[1])!=null&&o.match(/(mode|contrastThreshold|tonalOffset)/))}const ed=t=>[...[...Array(25)].map((o,n)=>`--${t?`${t}-`:""}overlays-${n}`),`--${t?`${t}-`:""}palette-AppBar-darkBg`,`--${t?`${t}-`:""}palette-AppBar-darkColor`],td=t=>(o,n)=>{const i=t.rootSelector||":root",s=t.colorSchemeSelector;let c=s;if(s==="class"&&(c=".%s"),s==="data"&&(c="[data-%s]"),s!=null&&s.startsWith("data-")&&!s.includes("%s")&&(c=`[${s}="%s"]`),t.defaultColorScheme===o){if(o==="dark"){const d={};return ed(t.cssVarPrefix).forEach(l=>{d[l]=n[l],delete n[l]}),c==="media"?{[i]:n,"@media (prefers-color-scheme: dark)":{[i]:d}}:c?{[c.replace("%s",o)]:d,[`${i}, ${c.replace("%s",o)}`]:n}:{[i]:{...n,...d}}}if(c&&c!=="media")return`${i}, ${c.replace("%s",String(o))}`}else if(o){if(c==="media")return{[`@media (prefers-color-scheme: ${String(o)})`]:{[i]:n}};if(c)return c.replace("%s",String(o))}return i};function rd(t,o){o.forEach(n=>{t[n]||(t[n]={})})}function R(t,o,n){!t[o]&&n&&(t[o]=n)}function Hr(t){return typeof t!="string"||!t.startsWith("hsl")?t:_i(t)}function jt(t,o){`${o}Channel`in t||(t[`${o}Channel`]=Vr(Hr(t[o]),`MUI: Can't create \`palette.${o}Channel\` because \`palette.${o}\` is not one of these formats: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color().
|
|
69
|
+
To suppress this warning, you need to explicitly provide the \`palette.${o}Channel\` as a string (in rgb format, for example "12 12 12") or undefined if you want to remove the channel token.`))}function od(t){return typeof t=="number"?`${t}px`:typeof t=="string"||typeof t=="function"||Array.isArray(t)?t:"8px"}const ft=t=>{try{return t()}catch{}},nd=(t="mui")=>Sc(t);function Vo(t,o,n,i,s){if(!n)return;n=n===!0?{}:n;const c=s==="dark"?"dark":"light";if(!i){o[s]=Zc({...n,palette:{mode:c,...n==null?void 0:n.palette},colorSpace:t});return}const{palette:d,...l}=qo({...i,palette:{mode:c,...n==null?void 0:n.palette},colorSpace:t});return o[s]={...n,palette:d,opacity:{...Ni(c),...n==null?void 0:n.opacity},overlays:(n==null?void 0:n.overlays)||Li(c)},l}function id(t={},...o){const{colorSchemes:n={light:!0},defaultColorScheme:i,disableCssColorScheme:s=!1,cssVarPrefix:c="mui",nativeColor:d=!1,shouldSkipGeneratingVar:l=Qc,colorSchemeSelector:u=n.light&&n.dark?"media":void 0,rootSelector:m=":root",...h}=t,b=Object.keys(n)[0],f=i||(n.light&&b!=="light"?"light":b),g=nd(c),{[f]:T,light:y,dark:w,...v}=n,j={...v};let S=T;if((f==="dark"&&!("dark"in n)||f==="light"&&!("light"in n))&&(S=!0),!S)throw new Error(process.env.NODE_ENV!=="production"?`MUI: The \`colorSchemes.${f}\` option is either missing or invalid.`:Yt(21,f));let I;d&&(I="oklch");const a=Vo(I,j,S,h,f);y&&!j.light&&Vo(I,j,y,void 0,"light"),w&&!j.dark&&Vo(I,j,w,void 0,"dark");let A={defaultColorScheme:f,...a,cssVarPrefix:c,colorSchemeSelector:u,rootSelector:m,getCssVar:g,colorSchemes:j,font:{...Mc(a.typography),...a.font},spacing:od(h.spacing)};Object.keys(A.colorSchemes).forEach(te=>{const x=A.colorSchemes[te].palette,N=H=>{const J=H.split("-"),ue=J[1],pe=J[2];return g(H,x[ue][pe])};x.mode==="light"&&(R(x.common,"background","#fff"),R(x.common,"onBackground","#000")),x.mode==="dark"&&(R(x.common,"background","#000"),R(x.common,"onBackground","#fff"));function W(H,J,ue){if(I){let pe;return H===Vt&&(pe=`transparent ${((1-ue)*100).toFixed(0)}%`),H===ye&&(pe=`#000 ${(ue*100).toFixed(0)}%`),H===be&&(pe=`#fff ${(ue*100).toFixed(0)}%`),`color-mix(in ${I}, ${J}, ${pe})`}return H(J,ue)}if(rd(x,["Alert","AppBar","Avatar","Button","Chip","FilledInput","LinearProgress","Skeleton","Slider","SnackbarContent","SpeedDialAction","StepConnector","StepContent","Switch","TableCell","Tooltip"]),x.mode==="light"){R(x.Alert,"errorColor",W(ye,x.error.light,.6)),R(x.Alert,"infoColor",W(ye,x.info.light,.6)),R(x.Alert,"successColor",W(ye,x.success.light,.6)),R(x.Alert,"warningColor",W(ye,x.warning.light,.6)),R(x.Alert,"errorFilledBg",N("palette-error-main")),R(x.Alert,"infoFilledBg",N("palette-info-main")),R(x.Alert,"successFilledBg",N("palette-success-main")),R(x.Alert,"warningFilledBg",N("palette-warning-main")),R(x.Alert,"errorFilledColor",ft(()=>x.getContrastText(x.error.main))),R(x.Alert,"infoFilledColor",ft(()=>x.getContrastText(x.info.main))),R(x.Alert,"successFilledColor",ft(()=>x.getContrastText(x.success.main))),R(x.Alert,"warningFilledColor",ft(()=>x.getContrastText(x.warning.main))),R(x.Alert,"errorStandardBg",W(be,x.error.light,.9)),R(x.Alert,"infoStandardBg",W(be,x.info.light,.9)),R(x.Alert,"successStandardBg",W(be,x.success.light,.9)),R(x.Alert,"warningStandardBg",W(be,x.warning.light,.9)),R(x.Alert,"errorIconColor",N("palette-error-main")),R(x.Alert,"infoIconColor",N("palette-info-main")),R(x.Alert,"successIconColor",N("palette-success-main")),R(x.Alert,"warningIconColor",N("palette-warning-main")),R(x.AppBar,"defaultBg",N("palette-grey-100")),R(x.Avatar,"defaultBg",N("palette-grey-400")),R(x.Button,"inheritContainedBg",N("palette-grey-300")),R(x.Button,"inheritContainedHoverBg",N("palette-grey-A100")),R(x.Chip,"defaultBorder",N("palette-grey-400")),R(x.Chip,"defaultAvatarColor",N("palette-grey-700")),R(x.Chip,"defaultIconColor",N("palette-grey-700")),R(x.FilledInput,"bg","rgba(0, 0, 0, 0.06)"),R(x.FilledInput,"hoverBg","rgba(0, 0, 0, 0.09)"),R(x.FilledInput,"disabledBg","rgba(0, 0, 0, 0.12)"),R(x.LinearProgress,"primaryBg",W(be,x.primary.main,.62)),R(x.LinearProgress,"secondaryBg",W(be,x.secondary.main,.62)),R(x.LinearProgress,"errorBg",W(be,x.error.main,.62)),R(x.LinearProgress,"infoBg",W(be,x.info.main,.62)),R(x.LinearProgress,"successBg",W(be,x.success.main,.62)),R(x.LinearProgress,"warningBg",W(be,x.warning.main,.62)),R(x.Skeleton,"bg",I?W(Vt,x.text.primary,.11):`rgba(${N("palette-text-primaryChannel")} / 0.11)`),R(x.Slider,"primaryTrack",W(be,x.primary.main,.62)),R(x.Slider,"secondaryTrack",W(be,x.secondary.main,.62)),R(x.Slider,"errorTrack",W(be,x.error.main,.62)),R(x.Slider,"infoTrack",W(be,x.info.main,.62)),R(x.Slider,"successTrack",W(be,x.success.main,.62)),R(x.Slider,"warningTrack",W(be,x.warning.main,.62));const H=I?W(ye,x.background.default,.6825):io(x.background.default,.8);R(x.SnackbarContent,"bg",H),R(x.SnackbarContent,"color",ft(()=>I?Go.text.primary:x.getContrastText(H))),R(x.SpeedDialAction,"fabHoverBg",io(x.background.paper,.15)),R(x.StepConnector,"border",N("palette-grey-400")),R(x.StepContent,"border",N("palette-grey-400")),R(x.Switch,"defaultColor",N("palette-common-white")),R(x.Switch,"defaultDisabledColor",N("palette-grey-100")),R(x.Switch,"primaryDisabledColor",W(be,x.primary.main,.62)),R(x.Switch,"secondaryDisabledColor",W(be,x.secondary.main,.62)),R(x.Switch,"errorDisabledColor",W(be,x.error.main,.62)),R(x.Switch,"infoDisabledColor",W(be,x.info.main,.62)),R(x.Switch,"successDisabledColor",W(be,x.success.main,.62)),R(x.Switch,"warningDisabledColor",W(be,x.warning.main,.62)),R(x.TableCell,"border",W(be,W(Vt,x.divider,1),.88)),R(x.Tooltip,"bg",W(Vt,x.grey[700],.92))}if(x.mode==="dark"){R(x.Alert,"errorColor",W(be,x.error.light,.6)),R(x.Alert,"infoColor",W(be,x.info.light,.6)),R(x.Alert,"successColor",W(be,x.success.light,.6)),R(x.Alert,"warningColor",W(be,x.warning.light,.6)),R(x.Alert,"errorFilledBg",N("palette-error-dark")),R(x.Alert,"infoFilledBg",N("palette-info-dark")),R(x.Alert,"successFilledBg",N("palette-success-dark")),R(x.Alert,"warningFilledBg",N("palette-warning-dark")),R(x.Alert,"errorFilledColor",ft(()=>x.getContrastText(x.error.dark))),R(x.Alert,"infoFilledColor",ft(()=>x.getContrastText(x.info.dark))),R(x.Alert,"successFilledColor",ft(()=>x.getContrastText(x.success.dark))),R(x.Alert,"warningFilledColor",ft(()=>x.getContrastText(x.warning.dark))),R(x.Alert,"errorStandardBg",W(ye,x.error.light,.9)),R(x.Alert,"infoStandardBg",W(ye,x.info.light,.9)),R(x.Alert,"successStandardBg",W(ye,x.success.light,.9)),R(x.Alert,"warningStandardBg",W(ye,x.warning.light,.9)),R(x.Alert,"errorIconColor",N("palette-error-main")),R(x.Alert,"infoIconColor",N("palette-info-main")),R(x.Alert,"successIconColor",N("palette-success-main")),R(x.Alert,"warningIconColor",N("palette-warning-main")),R(x.AppBar,"defaultBg",N("palette-grey-900")),R(x.AppBar,"darkBg",N("palette-background-paper")),R(x.AppBar,"darkColor",N("palette-text-primary")),R(x.Avatar,"defaultBg",N("palette-grey-600")),R(x.Button,"inheritContainedBg",N("palette-grey-800")),R(x.Button,"inheritContainedHoverBg",N("palette-grey-700")),R(x.Chip,"defaultBorder",N("palette-grey-700")),R(x.Chip,"defaultAvatarColor",N("palette-grey-300")),R(x.Chip,"defaultIconColor",N("palette-grey-300")),R(x.FilledInput,"bg","rgba(255, 255, 255, 0.09)"),R(x.FilledInput,"hoverBg","rgba(255, 255, 255, 0.13)"),R(x.FilledInput,"disabledBg","rgba(255, 255, 255, 0.12)"),R(x.LinearProgress,"primaryBg",W(ye,x.primary.main,.5)),R(x.LinearProgress,"secondaryBg",W(ye,x.secondary.main,.5)),R(x.LinearProgress,"errorBg",W(ye,x.error.main,.5)),R(x.LinearProgress,"infoBg",W(ye,x.info.main,.5)),R(x.LinearProgress,"successBg",W(ye,x.success.main,.5)),R(x.LinearProgress,"warningBg",W(ye,x.warning.main,.5)),R(x.Skeleton,"bg",I?W(Vt,x.text.primary,.13):`rgba(${N("palette-text-primaryChannel")} / 0.13)`),R(x.Slider,"primaryTrack",W(ye,x.primary.main,.5)),R(x.Slider,"secondaryTrack",W(ye,x.secondary.main,.5)),R(x.Slider,"errorTrack",W(ye,x.error.main,.5)),R(x.Slider,"infoTrack",W(ye,x.info.main,.5)),R(x.Slider,"successTrack",W(ye,x.success.main,.5)),R(x.Slider,"warningTrack",W(ye,x.warning.main,.5));const H=I?W(be,x.background.default,.985):io(x.background.default,.98);R(x.SnackbarContent,"bg",H),R(x.SnackbarContent,"color",ft(()=>I?Wi.text.primary:x.getContrastText(H))),R(x.SpeedDialAction,"fabHoverBg",io(x.background.paper,.15)),R(x.StepConnector,"border",N("palette-grey-600")),R(x.StepContent,"border",N("palette-grey-600")),R(x.Switch,"defaultColor",N("palette-grey-300")),R(x.Switch,"defaultDisabledColor",N("palette-grey-600")),R(x.Switch,"primaryDisabledColor",W(ye,x.primary.main,.55)),R(x.Switch,"secondaryDisabledColor",W(ye,x.secondary.main,.55)),R(x.Switch,"errorDisabledColor",W(ye,x.error.main,.55)),R(x.Switch,"infoDisabledColor",W(ye,x.info.main,.55)),R(x.Switch,"successDisabledColor",W(ye,x.success.main,.55)),R(x.Switch,"warningDisabledColor",W(ye,x.warning.main,.55)),R(x.TableCell,"border",W(ye,W(Vt,x.divider,1),.68)),R(x.Tooltip,"bg",W(Vt,x.grey[700],.92))}jt(x.background,"default"),jt(x.background,"paper"),jt(x.common,"background"),jt(x.common,"onBackground"),jt(x,"divider"),Object.keys(x).forEach(H=>{const J=x[H];H!=="tonalOffset"&&J&&typeof J=="object"&&(J.main&&R(x[H],"mainChannel",Vr(Hr(J.main))),J.light&&R(x[H],"lightChannel",Vr(Hr(J.light))),J.dark&&R(x[H],"darkChannel",Vr(Hr(J.dark))),J.contrastText&&R(x[H],"contrastTextChannel",Vr(Hr(J.contrastText))),H==="text"&&(jt(x[H],"primary"),jt(x[H],"secondary")),H==="action"&&(J.active&&jt(x[H],"active"),J.selected&&jt(x[H],"selected")))})}),A=o.reduce((te,x)=>qe(te,x),A);const B={prefix:c,disableCssColorScheme:s,shouldSkipGeneratingVar:l,getSelector:td(A),enableContrastVars:d},{vars:$,generateThemeVars:Y,generateStyleSheets:Q}=wc(A,B);return A.vars=$,Object.entries(A.colorSchemes[A.defaultColorScheme]).forEach(([te,x])=>{A[te]=x}),A.generateThemeVars=Y,A.generateStyleSheets=Q,A.generateSpacing=function(){return Ai(h.spacing,rn(this))},A.getColorSchemeSelector=kc(u),A.spacing=A.generateSpacing(),A.shouldSkipGeneratingVar=l,A.unstable_sxConfig={...Io,...h==null?void 0:h.unstable_sxConfig},A.unstable_sx=function(x){return zo({sx:x,theme:this})},A.toRuntimeSource=Pi,A}function Xn(t,o,n){t.colorSchemes&&n&&(t.colorSchemes[o]={...n!==!0&&n,palette:sn({...n===!0?{}:n.palette,mode:o})})}function sd(t={},...o){const{palette:n,cssVariables:i=!1,colorSchemes:s=n?void 0:{light:!0},defaultColorScheme:c=n==null?void 0:n.mode,...d}=t,l=c||"light",u=s==null?void 0:s[l],m={...s,...n?{[l]:{...typeof u!="boolean"&&u,palette:n}}:void 0};if(i===!1){if(!("colorSchemes"in t))return qo(t,...o);let h=n;"palette"in t||m[l]&&(m[l]!==!0?h=m[l].palette:l==="dark"&&(h={mode:"dark"}));const b=qo({...t,palette:h},...o);return b.defaultColorScheme=l,b.colorSchemes=m,b.palette.mode==="light"&&(b.colorSchemes.light={...m.light!==!0&&m.light,palette:b.palette},Xn(b,"dark",m.dark)),b.palette.mode==="dark"&&(b.colorSchemes.dark={...m.dark!==!0&&m.dark,palette:b.palette},Xn(b,"light",m.light)),b}return!n&&!("light"in m)&&l==="light"&&(m.light=!0),id({...d,colorSchemes:m,defaultColorScheme:l,...typeof i!="boolean"&&i},...o)}const ad=sd();function Tt(){const t=pc(ad);return process.env.NODE_ENV!=="production"&&fo.useDebugValue(t),t[tl]||t}async function ld(t,o,n){try{new URL(t)}catch{throw new Error("Please enter a valid URL")}const i={"Content-Type":"application/json"};o&&(i.Authorization=`Bearer ${o}`);const s=new AbortController,c=setTimeout(()=>s.abort(),3e4);let d;try{d=await fetch(t,{headers:i,signal:s.signal})}catch(m){throw clearTimeout(c),(m==null?void 0:m.name)==="AbortError"?new Error("Request timed out after 30 seconds"):new Error("Failed to fetch — check the URL and your network connection")}finally{clearTimeout(c)}if(d.status===401)throw new Error("Authentication failed (401) — check your API key");if(!d.ok)throw new Error(`API error ${d.status}: ${d.statusText}`);let l;try{l=await d.json()}catch{throw new Error("Response is not valid JSON")}let u;if(Array.isArray(l))u=l;else if(n&&l[n]&&Array.isArray(l[n]))u=l[n];else{const h=["data","results","items","records"].find(b=>l[b]&&Array.isArray(l[b]));if(h)u=l[h];else throw new Error("API response must be a JSON array, or specify the data path key.")}return{data:u,source:t,fetchedAt:new Date().toISOString()}}function cd({isOpen:t,onClose:o,onCreate:n,preloadedData:i,preloadedDataLabel:s}){const[c,d]=p.useState(""),[l,u]=p.useState(!1),[m,h]=p.useState(""),[b,f]=p.useState(null),[g,T]=p.useState(null),[y,w]=p.useState(!1),[v,j]=p.useState(""),S=p.useRef(null),[I,a]=p.useState("json"),[A,B]=p.useState(""),[$,Y]=p.useState(""),[Q,te]=p.useState(""),[x,N]=p.useState("idle"),[W,H]=p.useState(""),[J,ue]=p.useState(null),[pe,re]=p.useState(0),O=async P=>{if(j(""),!P.name.endsWith(".json")){j("Only .json files are allowed");return}const ne=10*1024*1024;if(P.size>ne){j("File size exceeds 10MB limit");return}try{const ce=await P.text();let ie;try{ie=JSON.parse(ce)}catch{j("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(ie)){j("JSON must be an array of objects");return}if(ie.length===0){j("No data rows found in JSON file");return}f(P),T(ie)}catch{j("Network error — please try again")}},F=P=>{P.preventDefault();const ne=P.dataTransfer.files[0];ne&&O(ne)},G=async()=>{if(A.trim()){N("loading"),H("");try{const P=await ld(A.trim(),$.trim()||void 0,Q.trim()||void 0);ue(P.data),re(P.data.length),N("ready")}catch(P){H((P==null?void 0:P.message)||"Connection failed"),N("error")}}},se=()=>{if(!c.trim()){u(!0);return}const P=I==="api"?J:i||g;P&&(n(c.trim(),m.trim(),P),ee())},ee=()=>{d(""),u(!1),h(""),f(null),T(null),j(""),a("json"),B(""),Y(""),te(""),N("idle"),H(""),ue(null),re(0),o()},le=i||g,ae=l&&!c.trim();return c.trim(),e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:ee,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",width:480,maxHeight:"min(720px, calc(100vh - 120px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2.5,fontWeight:500,fontSize:"1.125rem",color:"text.primary",letterSpacing:"-0.01em",borderBottom:"1px solid",borderColor:"divider"},children:["Create new report",e.jsx(r.IconButton,{onClick:ee,size:"small",sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:18}})})]}),e.jsx(r.DialogContent,{sx:{px:3,pt:2,pb:2,overflowY:"auto"},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2,pt:2},children:[e.jsx(r.TextField,{label:"Report name",required:!0,fullWidth:!0,value:c,onChange:P=>{d(P.target.value),l&&P.target.value.trim()&&u(!1)},placeholder:"Enter report name",autoFocus:!0,error:ae,helperText:ae?"Report name is required":void 0,inputProps:{maxLength:255},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsx(r.TextField,{label:"Description (optional)",fullWidth:!0,multiline:!0,rows:2,value:m,onChange:P=>h(P.target.value),placeholder:"Add details about this report",inputProps:{maxLength:500},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsxs(r.Tabs,{value:I==="json"?0:1,onChange:(P,ne)=>{a(ne===0?"json":"api"),N("idle"),H("")},variant:"fullWidth",sx:{borderBottom:1,borderColor:"divider",minHeight:40},children:[e.jsx(r.Tab,{label:"Upload JSON",icon:e.jsx(k.Description,{fontSize:"small"}),iconPosition:"start",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,minHeight:40,py:.5}}),e.jsx(r.Tab,{label:"Connect API",icon:e.jsx(k.Api,{fontSize:"small"}),iconPosition:"start",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,minHeight:40,py:.5}})]}),I==="json"&&e.jsx(r.Box,{children:i?e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2.5,bgcolor:P=>E(P.palette.success.main,.04),display:"flex",alignItems:"center",gap:2},children:[e.jsx(r.Box,{sx:{width:36,height:36,borderRadius:"50%",bgcolor:P=>E(P.palette.success.main,.12),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(k.CheckCircle,{sx:{fontSize:20,color:"success.main"}})}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.dark",fontSize:"0.875rem"},children:s||`${i.length.toLocaleString()} records loaded`}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary"},children:"Data source is connected — ready to create"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:1.25},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Data source"}),e.jsx(r.IconButton,{size:"small",onClick:()=>w(!0),sx:{p:.25,color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:e.jsx(k.Info,{sx:{fontSize:16}})})]}),e.jsxs(r.Box,{onDrop:F,onDragOver:P=>P.preventDefault(),onPaste:P=>P.preventDefault(),onClick:()=>{var P;return(P=S.current)==null?void 0:P.click()},sx:{position:"relative",border:"1.5px",borderStyle:g?"solid":"dashed",borderColor:g?"success.main":v?"error.main":"primary.main",borderRadius:2,p:3,textAlign:"center",cursor:"pointer",bgcolor:g?P=>E(P.palette.success.main,.04):v?P=>E(P.palette.error.main,.04):P=>E(P.palette.primary.main,.04),transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:g?P=>E(P.palette.success.main,.08):v?P=>E(P.palette.error.main,.08):P=>E(P.palette.primary.main,.08),borderColor:g?"success.dark":v?"error.dark":"primary.dark"}},children:[e.jsx(r.Box,{component:"input",ref:S,type:"file",accept:".json",sx:{display:"none"},onChange:P=>{var ne;return((ne=P.target.files)==null?void 0:ne[0])&&O(P.target.files[0])}}),g?e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",gap:.75,animation:"fadeIn 0.2s ease-in","@keyframes fadeIn":{from:{opacity:0,transform:"scale(0.98)"},to:{opacity:1,transform:"scale(1)"}}},children:[e.jsx(r.Box,{sx:{width:40,height:40,borderRadius:"50%",bgcolor:P=>E(P.palette.success.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:.5},children:e.jsx(k.CheckCircle,{sx:{fontSize:24,color:"success.main"}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.main",fontSize:"0.875rem"},children:b==null?void 0:b.name}),e.jsx(r.Typography,{variant:"caption",sx:{color:"success.dark",fontSize:"0.75rem"},children:"Ready to create"})]}):e.jsxs(r.Box,{children:[e.jsx(r.Box,{sx:{width:48,height:48,borderRadius:"50%",bgcolor:P=>E(P.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mx:"auto",mb:1.5},children:e.jsx(k.CloudUpload,{sx:{fontSize:28,color:"primary.main"}})}),e.jsx(r.Typography,{variant:"body2",sx:{color:"text.primary",fontSize:"0.875rem",fontWeight:500,mb:.25},children:"Upload JSON file"}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",display:"block"},children:"Click to browse or drag and drop"}),v&&e.jsx(r.Box,{sx:{mt:1.25,p:.75,borderRadius:1,bgcolor:P=>E(P.palette.error.main,.08),border:1,borderColor:P=>E(P.palette.error.main,.2)},children:e.jsx(r.Typography,{variant:"caption",sx:{color:"error.main",fontSize:"0.6875rem",fontWeight:500},children:v})})]})]})]})}),I==="api"&&e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:[e.jsx(r.TextField,{label:"API Endpoint URL",required:!0,fullWidth:!0,size:"small",value:A,onChange:P=>{B(P.target.value),N("idle")},placeholder:"http://localhost:8000/api/reports/sales-pipeline/data/flat",sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsx(r.TextField,{label:"API Key (optional)",fullWidth:!0,size:"small",value:$,onChange:P=>Y(P.target.value),placeholder:"Leave blank if no auth required",InputProps:{startAdornment:e.jsx(r.InputAdornment,{position:"start",children:e.jsx(k.Lock,{sx:{fontSize:16,color:"text.secondary"}})})},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsx(r.TextField,{label:"Response data path (optional)",fullWidth:!0,size:"small",value:Q,onChange:P=>te(P.target.value),placeholder:"data (leave blank if API returns a plain array)",helperText:'If your API returns { "data": [...] }, enter: data',sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}},"& .MuiFormHelperText-root":{fontSize:"0.75rem",mx:0}}}),e.jsx(r.Button,{variant:"outlined",fullWidth:!0,disabled:!A.trim()||x==="loading",onClick:G,startIcon:x==="loading"?e.jsx(r.CircularProgress,{size:16,color:"inherit"}):e.jsx(k.Api,{}),sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",borderRadius:1,py:.875,borderColor:"primary.main",color:"primary.main","&:hover":{bgcolor:P=>E(P.palette.primary.main,.04),borderColor:"primary.dark"},"&:disabled":{borderColor:"action.disabledBackground",color:"action.disabled"}},children:x==="loading"?"Connecting...":"Test Connection & Load Data"}),x==="ready"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2,bgcolor:P=>E(P.palette.success.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(k.CheckCircle,{sx:{fontSize:20,color:"success.main",flexShrink:0,mt:.1}}),e.jsxs(r.Box,{children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.dark",fontSize:"0.875rem"},children:[pe.toLocaleString()," records loaded — ready to create"]}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",wordBreak:"break-all",display:"block",mt:.25},children:A})]})]}),x==="error"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"error.main",borderRadius:2,p:2,bgcolor:P=>E(P.palette.error.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(k.ErrorOutline,{sx:{fontSize:20,color:"error.main",flexShrink:0,mt:.1}}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"error.main",fontSize:"0.875rem"},children:"Connection failed"}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",display:"block",mt:.25},children:W})]})]})]})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:2,gap:1,borderTop:"1px solid",borderColor:"divider"},children:[e.jsx(r.Button,{onClick:ee,variant:"text",sx:{textTransform:"none",color:"primary.main",fontWeight:500,fontSize:"0.875rem",borderRadius:"4px",px:2,py:.625,minWidth:64,"&:hover":{bgcolor:P=>E(P.palette.primary.main,.04)}},children:"Cancel"}),e.jsx(r.Button,{onClick:se,disabled:I==="json"&&!le||I==="api"&&x!=="ready",variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"4px",px:2.5,py:.625,minWidth:64,"&:hover":{bgcolor:"primary.dark",boxShadow:2},"&:disabled":{bgcolor:"action.disabledBackground",color:"action.disabled"}},children:"Create"})]})]}),e.jsxs(r.Dialog,{open:y,onClose:()=>w(!1),maxWidth:"sm",PaperProps:{sx:{borderRadius:3,width:560,maxHeight:"80vh",boxShadow:8}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,fontWeight:500,fontSize:"1.25rem",color:"text.primary",letterSpacing:"-0.01em"},children:["JSON format guide",e.jsx(r.IconButton,{onClick:()=>w(!1),size:"small",sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{sx:{px:3,py:2},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Required format"}),e.jsx(r.Typography,{variant:"body2",sx:{color:"text.secondary",fontSize:"0.8125rem",lineHeight:1.5},children:"Your JSON file must be an array of objects. Each object represents a row, and all should have the same field names."})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Example structure"}),e.jsx(r.Box,{component:"pre",sx:{bgcolor:"action.hover",border:1,borderColor:"divider",p:2,borderRadius:1,overflow:"auto",maxHeight:200,fontSize:"0.75rem",fontFamily:"monospace",lineHeight:1.5,color:"text.primary"},children:`[
|
|
70
70
|
{
|
|
71
71
|
"id": 1,
|
|
72
72
|
"customerName": "John Smith",
|
|
@@ -76,7 +76,7 @@ To suppress this warning, you need to explicitly provide the \`palette.${o}Chann
|
|
|
76
76
|
"memberSince": "2024-01-15",
|
|
77
77
|
"status": "active"
|
|
78
78
|
}
|
|
79
|
-
]`})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Supported data types"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"Text, numbers, booleans, dates, and null values"})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Guidelines"}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• Must be valid JSON with array format"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• All objects should have consistent field names"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:'• Field names auto-format (e.g., "customerName" → "Customer Name")'})]})]})]})}),e.jsx(r.DialogActions,{sx:{px:3,py:2},children:e.jsx(r.Button,{onClick:()=>
|
|
79
|
+
]`})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Supported data types"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"Text, numbers, booleans, dates, and null values"})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Guidelines"}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• Must be valid JSON with array format"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• All objects should have consistent field names"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:'• Field names auto-format (e.g., "customerName" → "Customer Name")'})]})]})]})}),e.jsx(r.DialogActions,{sx:{px:3,py:2},children:e.jsx(r.Button,{onClick:()=>w(!1),variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"4px",px:2.5,py:.625,minWidth:64,"&:hover":{bgcolor:"primary.dark",boxShadow:2}},children:"Got it"})})]})]})}function Fi({isOpen:t,onClose:o}){return t?e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"md",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(640px, calc(100vh - 180px))",my:"auto",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",display:"flex",flexDirection:"column"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:["JSON Format Guide",e.jsx(r.IconButton,{onClick:o,size:"small",sx:{color:"text.secondary"},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{dividers:!0,sx:{overflowY:"auto",flex:1},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:3,py:1},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Expected JSON Structure"}),e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["The uploaded JSON must be an ",e.jsx("strong",{children:"array of objects"}),". Each object represents a single row in your report, and the keys of each object become the column names."]})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Example JSON"}),e.jsx(r.Paper,{elevation:0,sx:{p:2,bgcolor:"action.hover",border:1,borderColor:"divider",borderRadius:1,overflowX:"auto"},children:e.jsx(r.Box,{component:"pre",sx:{fontSize:"caption.fontSize",fontFamily:"monospace",m:0},children:`[
|
|
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&>.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 dd({onFileUpload:t,onError:o,isUploading:n}){const[i,s]=p.useState(!1),[c,d]=p.useState(""),[l,u]=p.useState(!1),m=p.useRef(null),h=async v=>{if(!v.name.endsWith(".json")){o("Only .json files are allowed");return}const j=10*1024*1024;if(v.size>j){o("File size exceeds 10MB limit");return}d(v.name);try{const S=await v.text();let I;try{I=JSON.parse(S)}catch{o("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(I)){o("JSON must be an array of objects");return}if(I.length===0){o("No data rows found in JSON file");return}t(I)}catch{o("Network error — please try again")}finally{d("")}},b=v=>{v.preventDefault(),s(!0)},f=v=>{v.preventDefault(),s(!1)},g=v=>{v.preventDefault(),s(!1);const j=v.dataTransfer.files[0];j&&h(j)},T=()=>{var v;(v=m.current)==null||v.click()},y=v=>{var S;const j=(S=v.target.files)==null?void 0:S[0];j&&h(j)},w=v=>{v.stopPropagation(),u(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{onDragOver:b,onDragLeave:f,onDrop:g,onPaste:v=>v.preventDefault(),onClick:T,sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:400,border:2,borderStyle:"dashed",borderColor:i?"primary.main":"divider",bgcolor:i?v=>E(v.palette.primary.main,.12):"transparent",borderRadius:1,px:2,py:6,cursor:"pointer",transition:"all 0.2s",opacity:n?.5:1,pointerEvents:n?"none":"auto","&:hover":{borderColor:i?"primary.main":"text.secondary"}},children:[e.jsx(r.Box,{component:"input",ref:m,type:"file",accept:".json",onChange:y,sx:{display:"none"}}),n?e.jsxs(e.Fragment,{children:[e.jsx(r.CircularProgress,{size:32,sx:{mb:2}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,mb:.5},children:"Uploading..."}),c&&e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:c})]}):e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{width:64,height:64,borderRadius:"50%",bgcolor:v=>E(v.palette.primary.main,.12),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(k.UploadFile,{sx:{fontSize:32,color:"primary.main"}})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,mb:1.5},children:[e.jsx(r.Button,{variant:"contained",sx:{fontWeight:500},children:"Upload Data (JSON)"}),e.jsx(r.IconButton,{onClick:w,size:"small",sx:{border:1,borderColor:"divider","&:hover":{borderColor:"text.secondary",bgcolor:"action.hover"}},title:"View JSON format guide",children:e.jsx(k.InfoOutlined,{sx:{fontSize:16}})})]}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{textAlign:"center",maxWidth:500},children:"Upload structured JSON data to generate your report."}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{mt:1},children:"Click to browse or drag and drop a JSON file here"})]})]}),e.jsx(Fi,{isOpen:l,onClose:()=>u(!1)})]})}function ud({schema:t,onConfirm:o,hasConflicts:n}){return e.jsxs(r.Paper,{sx:{border:2,borderColor:"divider",p:3},children:[e.jsxs(r.Box,{sx:{mb:2},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontWeight:600,mb:.5},children:"Schema Preview"}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"Review the detected schema before generating your table"})]}),n&&e.jsxs(r.Alert,{severity:"warning",sx:{mb:2},children:[e.jsx(r.AlertTitle,{sx:{fontWeight:600},children:"Schema Conflict Detected"}),"Some columns have inconsistent data types across rows. Please resolve these conflicts before proceeding."]}),e.jsx(r.TableContainer,{sx:{mb:3},children:e.jsxs(r.Table,{children:[e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{sx:{bgcolor:"action.hover"},children:[e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Column Name"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Detected Type"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Status"})]})}),e.jsx(r.TableBody,{children:t.map(i=>e.jsxs(r.TableRow,{sx:{bgcolor:i.hasConflict?s=>E(s.palette.warning.main,.12):"transparent"},children:[e.jsxs(r.TableCell,{sx:{fontWeight:500},children:[i.name,i.hasConflict&&e.jsx(r.Box,{component:"span",sx:{ml:1,color:"warning.main"},children:"⚠"})]}),e.jsx(r.TableCell,{children:e.jsx(r.Chip,{label:i.type,size:"small",sx:{bgcolor:"action.hover"}})}),e.jsx(r.TableCell,{children:e.jsx(r.Chip,{label:i.required?"Required":"Optional",size:"small",color:i.required?"success":"default"})})]},i.name))})]})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pt:2,borderTop:1,borderColor:"divider"},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(k.Lock,{sx:{fontSize:16}}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"Schema will be locked for this report"})]}),e.jsx(r.Button,{variant:"contained",onClick:o,disabled:n,sx:{fontWeight:500},children:"Generate Table"})]})]})}function pd({error:t,onRetry:o}){return e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:400,border:2,borderColor:"error.light",bgcolor:n=>E(n.palette.error.main,.12),borderRadius:1,px:2,py:6},children:[e.jsx(r.Box,{sx:{width:64,height:64,borderRadius:"50%",bgcolor:n=>E(n.palette.error.main,.3),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(k.ErrorOutline,{color:"error",sx:{fontSize:32}})}),e.jsx(r.Typography,{variant:"h6",color:"error.main",sx:{fontWeight:600,mb:1},children:"Upload Failed"}),e.jsx(r.Typography,{variant:"body2",color:"error.main",sx:{textAlign:"center",maxWidth:500,mb:3},children:t}),e.jsx(r.Button,{variant:"contained",color:"error",startIcon:e.jsx(k.Upload,{sx:{fontSize:16}}),onClick:o,sx:{fontWeight:500},children:"Try Again"})]})}function Vi({title:t,description:o,showIcon:n=!0}){return e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"60vh",px:3,py:8},children:[n&&e.jsx(r.Box,{sx:{width:80,height:80,borderRadius:"50%",bgcolor:i=>E(i.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:3},children:e.jsx(k.Description,{sx:{fontSize:36,color:"primary.main"}})}),e.jsx(r.Typography,{variant:"h5",sx:{fontWeight:500,mb:1,color:"text.primary",fontSize:"1.125rem"},children:t}),e.jsx(r.Typography,{variant:"body1",sx:{textAlign:"center",maxWidth:520,color:"text.secondary",fontSize:"0.875rem",lineHeight:1.5},children:o})]})}function xd({value:t,onChange:o,searchHistory:n,onAddToHistory:i,onToggleFavourite:s,onDeleteHistory:c,disabled:d}){const[l,u]=p.useState(!1),[m,h]=p.useState(!1),[b,f]=p.useState(-1),g=p.useRef(null),T=p.useRef(null);p.useEffect(()=>{function $(Y){g.current&&!g.current.contains(Y.target)&&(u(!1),h(!1))}return document.addEventListener("mousedown",$),()=>document.removeEventListener("mousedown",$)},[]);const y=p.useCallback(()=>{h(!0),f(-1),n.length>0&&u(!0)},[n.length]),w=p.useCallback($=>{o($),f(-1)},[o]),v=p.useCallback($=>{var Y;o($),i($),u(!1),(Y=T.current)==null||Y.blur()},[o,i]),j=p.useCallback($=>{f(-1),v($)},[v]),S=p.useCallback($=>{var Y;$.key==="Enter"?b>=0&&b<n.length?($.preventDefault(),j(n[b].query)):t.trim()&&v(t.trim()):$.key==="Escape"?(u(!1),f(-1),(Y=T.current)==null||Y.blur()):$.key==="ArrowDown"?($.preventDefault(),n.length>0&&(l||u(!0),f(Q=>Q<n.length-1?Q+1:Q))):$.key==="ArrowUp"&&($.preventDefault(),f(Q=>Q>0?Q-1:-1))},[b,n,t,l,j,v]),I=p.useCallback(()=>{var $;o(""),($=T.current)==null||$.focus()},[o]),a=p.useMemo(()=>n.filter($=>$.isFavourite),[n]),A=p.useMemo(()=>n.filter($=>!$.isFavourite),[n]),B=l&&n.length>0;return e.jsxs(r.Box,{sx:{position:"relative",width:240},ref:g,children:[e.jsx(r.TextField,{inputRef:T,size:"small",fullWidth:!0,value:t,onChange:$=>w($.target.value),onFocus:y,onKeyDown:S,placeholder:"Search data...",disabled:d,sx:{"& .MuiOutlinedInput-root":{borderRadius:"20px",fontSize:"0.875rem",bgcolor:"background.paper",height:"36px","& fieldset":{borderColor:$=>`rgba(${$.palette.mode==="dark"?"255,255,255":"0,0,0"}, 0.30)`,transition:"all 0.15s ease"},"&:hover":{bgcolor:"action.hover"},"&:hover fieldset":{borderColor:$=>`rgba(${$.palette.mode==="dark"?"255,255,255":"0,0,0"}, 0.50)`},"&.Mui-focused":{bgcolor:"background.paper"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}},"& .MuiOutlinedInput-input":{py:"6px",px:"8px",color:"text.primary"}},InputProps:{startAdornment:e.jsx(r.InputAdornment,{position:"start",sx:{ml:.5},children:e.jsx(k.Search,{sx:{fontSize:18,color:"text.secondary"}})}),endAdornment:t?e.jsx(r.InputAdornment,{position:"end",children:e.jsx(r.IconButton,{size:"small",onClick:I,edge:"end",sx:{mr:-.5},children:e.jsx(k.Close,{sx:{fontSize:16}})})}):null}}),B&&e.jsxs(r.Paper,{sx:{position:"absolute",zIndex:50,mt:.5,width:"100%",maxHeight:384,overflowY:"auto"},elevation:3,children:[a.length>0&&e.jsxs(r.Box,{sx:{py:1},children:[e.jsx(r.Typography,{variant:"caption",sx:{px:1.5,py:.75,display:"block",fontWeight:600,textTransform:"uppercase",color:"text.secondary",letterSpacing:"0.05em"},children:"Favourite Searches"}),a.map(($,Y)=>e.jsx(Zn,{entry:$,isSelected:b===Y,onClick:()=>j($.query),onToggleFavourite:()=>s($.query),onDelete:()=>c($.query)},`fav-${$.query}`))]}),A.length>0&&e.jsxs(r.Box,{sx:{py:1},children:[a.length>0&&e.jsx(r.Divider,{}),e.jsx(r.Typography,{variant:"caption",sx:{px:1.5,py:.75,display:"block",fontWeight:600,textTransform:"uppercase",color:"text.secondary",letterSpacing:"0.05em"},children:"Recent Searches"}),A.map(($,Y)=>{const Q=a.length+Y;return e.jsx(Zn,{entry:$,isSelected:b===Q,onClick:()=>j($.query),onToggleFavourite:()=>s($.query),onDelete:()=>c($.query)},`recent-${$.query}`)})]})]})]})}const Zn=p.memo(function({entry:o,isSelected:n,onClick:i,onToggleFavourite:s,onDelete:c}){const d=p.useCallback(u=>{u.stopPropagation(),s()},[s]),l=p.useCallback(u=>{u.stopPropagation(),c()},[c]);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:1.5,py:1,cursor:"pointer",bgcolor:n?u=>E(u.palette.primary.main,.12):"transparent","&:hover":{bgcolor:n?u=>E(u.palette.primary.main,.12):"action.hover"}},children:[e.jsx(r.Box,{sx:{flex:1,minWidth:0},onClick:i,children:e.jsx(r.Typography,{variant:"body2",noWrap:!0,children:o.query})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,ml:1},children:[e.jsx(r.IconButton,{size:"small",onClick:d,title:o.isFavourite?"Remove from favourites":"Add to favourites",sx:{p:.5},children:o.isFavourite?e.jsx(k.Star,{sx:{fontSize:14,color:"warning.light"}}):e.jsx(k.StarBorder,{sx:{fontSize:14,color:"action.disabled"}})}),e.jsx(r.IconButton,{size:"small",onClick:l,title:"Delete from history",sx:{p:.5,"&:hover":{color:"error.main"}},children:e.jsx(k.Delete,{sx:{fontSize:14,opacity:.5}})})]})]})});function md({views:t,activeViewId:o,isDirty:n,onSelectView:i,onCreateView:s,onManageViews:c,onToggleDefault:d,onToggleFavorite:l,onRestoreView:u,onPermanentDelete:m,isReadOnly:h,isAdmin:b=!1}){const f=Tt(),[g,T]=p.useState(!1),[y,w]=p.useState(!1),[v,j]=p.useState({top:0,left:0}),[S,I]=p.useState(null),a=p.useRef(null),A=p.useRef(null),B=t.find(O=>O.id===o),$=B==null?void 0:B.isDefault,Y=t.filter(O=>O.scope==="global"&&!O.isDeleted),Q=t.filter(O=>O.scope!=="global"&&!O.isDeleted),te=t.filter(O=>O.isFavorite&&!O.isDeleted).sort((O,F)=>(F.updatedAt||0)-(O.updatedAt||0)),x=t.filter(O=>O.isDeleted);p.useEffect(()=>{if(g&&A.current){const O=A.current.getBoundingClientRect();j({top:O.bottom+window.scrollY+8,left:O.right+window.scrollX-320})}},[g]),p.useEffect(()=>{const O=F=>{a.current&&!a.current.contains(F.target)&&A.current&&!A.current.contains(F.target)&&T(!1)};return g&&document.addEventListener("mousedown",O),()=>{document.removeEventListener("mousedown",O)}},[g]);const N=O=>{if(n&&O!==o){I(O),T(!1);return}i(O),T(!1)},W=()=>{S&&(i(S),I(null))},H=()=>{I(null)},J=(O,F=!1)=>{const G=O.scope==="global",se=!h&&(!G||b);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:o===O.id?f.palette.primary.light+"20":"transparent",transition:"background-color 0.2s","&:hover":{backgroundColor:o===O.id?f.palette.primary.light+"20":f.palette.grey[50]}},children:[e.jsxs(r.Button,{onClick:()=>N(O.id),sx:{display:"flex",alignItems:"center",gap:1,flex:1,textAlign:"left",minWidth:0,textTransform:"none",justifyContent:"flex-start",color:"inherit",p:0,"&:hover":{backgroundColor:"transparent"}},children:[o===O.id&&e.jsx(k.Check,{sx:{fontSize:16,flexShrink:0}}),o!==O.id&&e.jsx(r.Box,{sx:{width:"16px",flexShrink:0}}),e.jsx(r.Typography,{sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:o===O.id?f.palette.primary.dark:f.palette.text.primary,fontWeight:o===O.id?500:400},children:O.name}),F&&e.jsx(r.Typography,{component:"span",sx:{fontSize:"caption.fontSize",color:f.palette.text.secondary,backgroundColor:f.palette.grey[100],px:1,py:.25,borderRadius:1,flexShrink:0},children:"Default"})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[se&&l&&e.jsx(r.IconButton,{onClick:ee=>{ee.stopPropagation(),l(O.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:f.palette.grey[200]}},title:O.isFavorite?"Remove from favorites":"Add to favorites",children:e.jsx(k.Star,{sx:{fontSize:16}})}),se&&d&&!O.isDefault&&e.jsx(r.IconButton,{onClick:ee=>{ee.stopPropagation(),d(O.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:f.palette.grey[200]}},title:"Set as default",children:e.jsx(k.RadioButtonUnchecked,{sx:{fontSize:16}})})]})]},O.id)},ue=O=>e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:f.palette.grey[50]},children:[e.jsx(r.Typography,{sx:{color:f.palette.text.secondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:O.name}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[u&&e.jsx(r.IconButton,{onClick:F=>{F.stopPropagation(),u(O.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:f.palette.grey[200]}},title:"Restore view",children:e.jsx(k.Undo,{sx:{fontSize:16,color:"success.main"}})}),m&&e.jsx(r.IconButton,{onClick:F=>{F.stopPropagation(),m(O.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:f.palette.grey[200]}},title:"Delete permanently",children:e.jsx(k.Delete,{sx:{fontSize:16,color:"error.main"}})})]})]},O.id),pe=n||!$,re=n;return e.jsxs(r.Box,{sx:{position:"relative"},children:[e.jsxs(r.IconButton,{ref:A,onClick:()=>T(!g),size:"small",sx:{position:"relative",color:pe?"warning.main":"text.secondary",bgcolor:pe?E(f.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:pe?E(f.palette.warning.main,.2):E(f.palette.text.primary,.06),color:pe?"warning.dark":"text.primary"}},title:`View: ${(B==null?void 0:B.name)||"Default View"}`,children:[e.jsx(k.Visibility,{sx:{fontSize:20}}),re&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:8,height:8,borderRadius:"50%",bgcolor:"warning.main",border:"2px solid",borderColor:"background.paper"}})]}),g&&di.createPortal(e.jsxs(r.Box,{ref:a,sx:{position:"fixed",width:"320px",backgroundColor:f.palette.background.paper,border:`1px solid ${f.palette.divider}`,borderRadius:1,boxShadow:f.shadows[8],zIndex:50,maxHeight:"500px",overflowY:"auto",top:v.top,left:v.left},children:[Y.length>0&&e.jsxs(r.Box,{sx:{py:.5},children:[e.jsx(r.Typography,{sx:{px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:f.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Global Views"}),Y.map(O=>J(O,O.isDefault))]}),te.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${f.palette.divider}`}}),e.jsxs(r.Box,{sx:{py:.5},children:[e.jsxs(r.Box,{sx:{px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:f.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",gap:.5},children:[e.jsx(k.Star,{sx:{fontSize:12,color:"warning.light"}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:"Favorite Views"})]}),te.map(O=>J(O))]})]}),Q.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${f.palette.divider}`}}),e.jsxs(r.Box,{sx:{py:.5},children:[e.jsx(r.Typography,{sx:{px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:f.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Personal Views"}),Q.map(O=>J(O))]})]}),x.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${f.palette.divider}`}}),e.jsxs(r.Box,{sx:{py:.5},children:[e.jsxs(r.Button,{onClick:()=>w(!y),sx:{width:"100%",px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:f.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",justifyContent:"space-between",transition:"background-color 0.2s","&:hover":{backgroundColor:f.palette.grey[50]}},children:[e.jsxs(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:["Recently Deleted (",x.length,")"]}),e.jsx(k.ChevronRight,{sx:{fontSize:16}})]}),y&&e.jsx(r.Box,{sx:{backgroundColor:f.palette.grey[50]},children:x.map(O=>ue(O))})]})]}),e.jsx(r.Box,{sx:{borderTop:`1px solid ${f.palette.divider}`}}),e.jsxs(r.Button,{onClick:()=>{s(),T(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:f.palette.text.primary,textTransform:"none",justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:f.palette.grey[50]}},children:[e.jsx(k.Add,{sx:{fontSize:16}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit"},children:"Create New Report View"})]}),e.jsxs(r.Button,{onClick:()=>{c(),T(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:f.palette.text.primary,textTransform:"none",justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:f.palette.grey[50]}},children:[e.jsx(k.Settings,{sx:{fontSize:16}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit"},children:"View Setup"})]})]}),document.body),e.jsxs(r.Dialog,{open:S!==null,onClose:H,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",gap:1,pb:1},children:[e.jsx(k.Warning,{sx:{fontSize:20,color:"warning.main"}}),"Unsaved changes"]}),e.jsx(r.DialogContent,{children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"You have unsaved changes to the current view. Switching views will discard them."})}),e.jsxs(r.DialogActions,{sx:{px:3,pb:2,gap:1},children:[e.jsx(r.Button,{onClick:H,variant:"text",sx:{textTransform:"none",fontWeight:500},children:"Stay here"}),e.jsx(r.Button,{onClick:W,variant:"contained",color:"warning",disableElevation:!0,sx:{textTransform:"none",fontWeight:500},children:"Discard & switch"})]})]})]})}function fd({columnName:t,columnType:o="string",currentSort:n,hasFilters:i,isInSortStack:s,isReadOnly:c=!1,hasModifications:d=!1,position:l,onSortAscending:u,onSortDescending:m,onRemoveSort:h,onFilter:b,onClearFilter:f,onGroupByColumn:g,onHideColumn:T,onManageColumns:y,onManageViews:w,onResetLayout:v,onClose:j}){var te,x;const I=Tt().palette,a=p.useRef(null);p.useEffect(()=>{if(!a.current)return;const N=a.current,W=N.getBoundingClientRect(),H=window.innerWidth,J=window.innerHeight;W.right>H-8&&(N.style.left=`${H-W.width-8}px`),W.bottom>J-8&&(N.style.top=`${J-W.height-8}px`)},[l]),p.useEffect(()=>{const N=H=>{a.current&&!a.current.contains(H.target)&&j()},W=H=>{H.key==="Escape"&&j()};return document.addEventListener("mousedown",N),document.addEventListener("keydown",W),()=>{document.removeEventListener("mousedown",N),document.removeEventListener("keydown",W)}},[j]);const A=p.useCallback(N=>()=>{N(),j()},[j]),B=(n==null?void 0:n.direction)==="asc",$=(n==null?void 0:n.direction)==="desc",Y=o==="number"?"0→9":o==="boolean"?"F→T":"A→Z",Q=o==="number"?"9→0":o==="boolean"?"T→F":"Z→A";return di.createPortal(e.jsxs(r.Paper,{ref:a,elevation:0,sx:{position:"fixed",left:`${l.x}px`,top:`${l.y}px`,zIndex:1400,minWidth:210,maxWidth:264,border:"1px solid",borderColor:"divider",borderRadius:"10px",overflow:"hidden",boxShadow:`0 4px 20px ${E(((te=I.common)==null?void 0:te.black)??"#000",.12)}, 0 1px 4px ${E(((x=I.common)==null?void 0:x.black)??"#000",.06)}`},children:[!c&&e.jsxs(r.Box,{sx:{px:2,py:.75,display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid",borderColor:"divider"},children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",fontWeight:500,color:"text.primary"},children:"Sorting"}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25},children:[e.jsx(r.Tooltip,{title:`Sort Ascending (${Y})`,placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:A(()=>u(t)),sx:{p:.625,borderRadius:"6px",color:B?"primary.main":"text.secondary",bgcolor:B?E(I.primary.main,.1):"transparent","&:hover":{bgcolor:E(I.primary.main,.08),color:"primary.main"}},children:e.jsx(k.ArrowUpward,{sx:{fontSize:16}})})}),e.jsx(r.Tooltip,{title:`Sort Descending (${Q})`,placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:A(()=>m(t)),sx:{p:.625,borderRadius:"6px",color:$?"primary.main":"text.secondary",bgcolor:$?E(I.primary.main,.1):"transparent","&:hover":{bgcolor:E(I.primary.main,.08),color:"primary.main"}},children:e.jsx(k.ArrowDownward,{sx:{fontSize:16}})})}),e.jsx(r.Tooltip,{title:"Clear Sort",placement:"top",arrow:!0,children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:!s,onClick:A(()=>h(t)),sx:{p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:E(I.error.main,.08),color:"error.main"},"&.Mui-disabled":{opacity:.3}},children:e.jsx(k.Close,{sx:{fontSize:16}})})})})]})]}),e.jsxs(r.MenuList,{dense:!0,sx:{py:.5},children:[e.jsxs(r.MenuItem,{onClick:A(()=>b(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(k.FilterList,{sx:{fontSize:16,color:i?"primary.main":"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Filter by Column",primaryTypographyProps:{fontSize:"0.8125rem",fontWeight:i?600:400,color:i?"primary.main":"text.primary"}})]}),i&&!c&&e.jsxs(r.MenuItem,{onClick:A(()=>f(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:E(I.warning.main,.06),"& .MuiListItemText-primary":{color:"warning.main"},"& .MuiListItemIcon-root svg":{color:"warning.main"}}},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(k.FilterListOff,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Clear Filter",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]}),!c&&g&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{sx:{my:.25}}),e.jsx(r.MenuList,{dense:!0,sx:{py:.5},children:e.jsxs(r.MenuItem,{onClick:A(()=>g(t)),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(k.GroupWorkOutlined,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Group By Column",primaryTypographyProps:{fontSize:"0.8125rem"}})]})})]}),e.jsx(r.Divider,{sx:{my:.25}}),e.jsxs(r.MenuList,{dense:!0,sx:{py:.5},children:[!c&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",mx:.5,borderRadius:"6px",overflow:"hidden","&:hover":{bgcolor:"action.hover"}},children:[e.jsxs(r.MenuItem,{onClick:A(()=>T(t)),sx:{flex:1,py:.75,px:1.5,minHeight:34,borderRadius:"6px 0 0 6px","&:hover":{bgcolor:"transparent"}},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(k.VisibilityOff,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Hide Column",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),e.jsx(r.Tooltip,{title:"Manage Columns",placement:"top",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:A(y),sx:{mr:.75,p:.625,borderRadius:"6px",color:"text.secondary","&:hover":{bgcolor:E(I.primary.main,.08),color:"primary.main"}},children:e.jsx(k.Settings,{sx:{fontSize:16}})})})]}),c&&e.jsxs(r.MenuItem,{onClick:A(y),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(k.Settings,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Manage Columns",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),w&&e.jsxs(r.MenuItem,{onClick:A(w),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(k.TableRows,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Manage Views",primaryTypographyProps:{fontSize:"0.8125rem"}})]}),!c&&d&&v&&e.jsxs(r.MenuItem,{onClick:A(v),sx:{py:.75,px:1.5,borderRadius:"6px",mx:.5,minHeight:34,"&:hover":{bgcolor:E(I.error.main,.05),"& .MuiListItemText-primary":{color:"error.main"},"& .MuiListItemIcon-root svg":{color:"error.main"}}},children:[e.jsx(r.ListItemIcon,{sx:{minWidth:28},children:e.jsx(k.RestartAlt,{sx:{fontSize:16,color:"text.secondary"}})}),e.jsx(r.ListItemText,{primary:"Reset to Default Layout",primaryTypographyProps:{fontSize:"0.8125rem"}})]})]})]}),document.body)}const hd=150,Qn="COLUMN_HEADER",gd=p.memo(function({column:o,index:n,sortRule:i,hasFilters:s,isInSortStack:c,isReadOnly:d=!1,hasModifications:l=!1,width:u,onColumnClick:m,onMoveColumn:h,onResizeStart:b,onSortAscending:f,onSortDescending:g,onRemoveSort:T,onOpenFilterForColumn:y,onClearFiltersForColumn:w,onGroupByColumn:v,onHideColumn:j,onManageColumns:S,onManageViews:I,onResetLayout:a}){const A=p.useRef(null),[B,$]=p.useState(!1),[Y,Q]=p.useState({x:0,y:0}),[{handlerId:te,isOver:x},N]=wt.useDrop({accept:Qn,collect(G){return{handlerId:G.getHandlerId(),isOver:G.isOver()}},hover(G,se){var ie;if(!A.current)return;const ee=G.index,le=n;if(ee===le)return;const ae=(ie=A.current)==null?void 0:ie.getBoundingClientRect(),P=(ae.right-ae.left)/2,ne=se.getClientOffset(),ce=((ne==null?void 0:ne.x)??0)-ae.left;ee<le&&ce<P||ee>le&&ce>P||(h(ee,le),G.index=le)}}),[{isDragging:W},H]=wt.useDrag({type:Qn,item:()=>({index:n,columnName:o.name}),collect:G=>({isDragging:G.isDragging()})});H(N(A));const J=p.useCallback(G=>{G.preventDefault(),G.stopPropagation(),Q({x:G.clientX,y:G.clientY}),$(!0)},[]),ue=p.useCallback(()=>$(!1),[]),pe=p.useCallback(()=>{m(o.name)},[m,o.name]),re=p.useCallback(G=>{G.stopPropagation(),y(o.name)},[y,o.name]),O=p.useCallback(()=>i?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[i.direction==="asc"?e.jsx(k.ArrowUpward,{sx:{fontSize:13,color:"primary.main"}}):e.jsx(k.ArrowDownward,{sx:{fontSize:13,color:"primary.main"}}),e.jsx(r.Box,{sx:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:16,height:16,bgcolor:"primary.main",color:"primary.contrastText",fontSize:"0.6rem",fontWeight:700,borderRadius:"50%",lineHeight:1},children:i.priority})]}):null,[i]),F=p.useCallback(()=>s?e.jsx(r.Box,{onClick:re,title:"Active filters on this column",sx:{ml:.75,width:7,height:7,borderRadius:"50%",bgcolor:"primary.main",cursor:"pointer",flexShrink:0,"&:hover":{transform:"scale(1.25)"},transition:"transform 0.12s ease"}}):null,[s,re]);return e.jsxs(e.Fragment,{children:[e.jsxs(r.TableCell,{ref:A,"data-handler-id":te,"data-column-index":n,onClick:pe,onContextMenu:J,sx:{position:"sticky",top:0,zIndex:50,textAlign:"left",fontSize:"0.8125rem",fontWeight:700,textTransform:"none",letterSpacing:0,whiteSpace:"nowrap",overflow:"hidden",cursor:"pointer",userSelect:"none",color:"primary.main",opacity:W?.25:1,transition:"background-color 0.12s ease, opacity 0.15s ease",bgcolor:x?G=>E(G.palette.primary.main,.08):"action.hover",boxShadow:"0 1px 0 rgba(0,0,0,0.08)",backgroundImage:"none",borderBottom:"1px solid",borderColor:"divider",py:0,px:2,height:34,"&:hover":{bgcolor:G=>E(G.palette.primary.main,.1),color:"primary.dark"},width:u?`${u}px`:`${hd}px`},children:[e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center"},children:[Ge(o.name),O(),F()]}),e.jsx(r.Box,{sx:{position:"absolute",right:0,top:0,height:"100%",width:8,cursor:"col-resize",zIndex:10,"&:hover":{bgcolor:"primary.light"}},onMouseDown:G=>{G.stopPropagation(),b(G,o.name)},onClick:G=>G.stopPropagation()}),x&&e.jsx(r.Box,{sx:{position:"absolute",left:0,top:0,bottom:0,width:4,bgcolor:"primary.main"}})]}),B&&e.jsx(fd,{columnName:o.name,columnType:o.type,currentSort:i,hasFilters:s,isInSortStack:c,isReadOnly:d,hasModifications:l,position:Y,onSortAscending:f,onSortDescending:g,onRemoveSort:T,onFilter:y,onClearFilter:w,onGroupByColumn:v,onHideColumn:j,onManageColumns:S,onManageViews:I,onResetLayout:a,onClose:ue})]})});function yd({selectedCount:t,selectedRowIds:o,resolvedFavoritesSet:n,viewMode:i="list",onExportSelected:s,onClearSelection:c,onBulkSetFavorites:d}){const[l,u]=p.useState(null),m=p.useMemo(()=>Array.from(o),[o]),h=p.useMemo(()=>m.filter(v=>n.has(v)),[m,n]),b=p.useMemo(()=>m.filter(v=>!n.has(v)),[m,n]),f=h.length>0,g=b.length>0;if(t===0)return null;const T=()=>{d&&d(m,!0)},y=()=>{d&&d(m,!1)},w=v=>{s(v),u(null)};return e.jsx(r.Box,{sx:{width:"100%",flexShrink:0,bgcolor:v=>E(v.palette.primary.main,.08),borderBottom:v=>`1px solid ${E(v.palette.primary.main,.25)}`,zIndex:10},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:1.25},children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"primary.main"},children:[t," ",i==="grid"?t===1?"card":"cards":t===1?"row":"rows"," selected"]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.Button,{onClick:c,startIcon:e.jsx(k.Close,{sx:{fontSize:16}}),size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",color:"text.secondary","&:hover":{bgcolor:v=>E(v.palette.text.primary,.06),color:"text.primary"}},children:"Clear"}),e.jsx(r.Button,{onClick:v=>u(v.currentTarget),startIcon:e.jsx(k.Download,{sx:{fontSize:16}}),size:"small",variant:"outlined",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",borderColor:v=>E(v.palette.primary.main,.4),color:"primary.main","&:hover":{borderColor:"primary.main",bgcolor:v=>E(v.palette.primary.main,.06)}},children:"Export Selected"}),e.jsxs(r.Menu,{anchorEl:l,open:!!l,onClose:()=>u(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{mt:.5,minWidth:180,borderRadius:1.5}},children:[e.jsx(r.MenuItem,{dense:!0,onClick:()=>w("csv"),sx:{py:1,px:2},children:"Export as CSV"}),e.jsx(r.MenuItem,{dense:!0,onClick:()=>w("excel"),sx:{py:1,px:2},children:"Export as Excel"}),e.jsx(r.MenuItem,{dense:!0,onClick:()=>w("json"),sx:{py:1,px:2},children:"Export as JSON"})]}),d&&g&&e.jsx(r.Button,{onClick:T,startIcon:e.jsx(k.StarBorder,{sx:{fontSize:16}}),size:"small",variant:"outlined",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",borderColor:v=>E(v.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:v=>E(v.palette.warning.main,.06)}},children:"Add to Favorites"}),d&&f&&e.jsx(r.Button,{onClick:y,startIcon:e.jsx(k.Star,{sx:{fontSize:16,color:"#fbbc04"}}),size:"small",variant:"outlined",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",borderColor:v=>E(v.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:v=>E(v.palette.warning.main,.06)}},children:"Remove from Favorites"})]})]})})}const bd={active:{bg:"#e6f4ea",color:"#137333"},completed:{bg:"#e6f4ea",color:"#137333"},approved:{bg:"#e6f4ea",color:"#137333"},success:{bg:"#e6f4ea",color:"#137333"},done:{bg:"#e6f4ea",color:"#137333"},contract:{bg:"#e8eaf6",color:"#3949ab"},"in progress":{bg:"#e8eaf6",color:"#3949ab"},"in review":{bg:"#e8eaf6",color:"#3949ab"},review:{bg:"#e8eaf6",color:"#3949ab"},pending:{bg:"#e8eaf6",color:"#3949ab"},"on leave":{bg:"#fce8e6",color:"#c5221f"},"on hold":{bg:"#fff8e1",color:"#e65100"},probation:{bg:"#fff8e1",color:"#e65100"},cancelled:{bg:"#fce8e6",color:"#c5221f"},rejected:{bg:"#fce8e6",color:"#c5221f"},blocked:{bg:"#fce8e6",color:"#c5221f"},inactive:{bg:"#f1f3f4",color:"text.secondary"},"not started":{bg:"#f1f3f4",color:"text.secondary"},paused:{bg:"#f1f3f4",color:"text.secondary"}},vd={low:"text.secondary",medium:"#e65100",high:"#e8710a",critical:"#c5221f",urgent:"#c5221f"};function Sd(t){const o=t.toLowerCase().trim(),n=bd[o]||{bg:"#f1f3f4",color:"text.secondary"};return e.jsx(r.Box,{component:"span",sx:{display:"inline-flex",alignItems:"center",px:1,py:.25,borderRadius:"10px",fontSize:"0.75rem",fontWeight:500,bgcolor:n.bg,color:n.color,whiteSpace:"nowrap",lineHeight:1.5},children:t})}function jd(t,o){if(o==null||o==="")return e.jsx(r.Box,{component:"span",sx:{color:"text.disabled",fontSize:"0.8125rem"},children:"—"});const n=String(o),i=t.name.toLowerCase();if(/\b(status|state|stage)\b/.test(i))return Sd(n);if(/\b(priority|severity|urgency)\b/.test(i)){const s=vd[n.toLowerCase().trim()];return s?e.jsx(r.Box,{component:"span",sx:{color:s,fontWeight:600,fontSize:"0.8125rem"},children:n}):e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:n})}return typeof o=="boolean"?e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:o?"Yes":"No"}):typeof o=="object"?e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:JSON.stringify(o)}):e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:n})}function Cd(t){const o=t.find(s=>{const c=s.name.toLowerCase();return/\b(name|title|label|subject|task_?name|taskname)\b/.test(c)})||t[0]||null,n=t.find(s=>{const c=s.name.toLowerCase().replace(/[\s_-]/g,"");return/(^id$|id$|_id$|taskid|code$|ref$)/.test(c)&&s!==o})||null,i=t.filter(s=>s!==o&&s!==n).slice(0,4);return{primaryCol:o,idCol:n,bodyColumns:i}}function wd({row:t,rowIndex:o,visibleColumns:n,isSelected:i,isFavorite:s,isReadOnly:c,onToggleSelection:d,onToggleFavorite:l,onView:u,onEdit:m,onDuplicate:h,onDelete:b}){const[f,g]=p.useState(null),[T,y]=p.useState(!1),{primaryCol:w,idCol:v,bodyColumns:j}=p.useMemo(()=>Cd(n),[n]),S=w?t[w.name]:null,I=v?t[v.name]:null,a=T||i||s||!!f;return e.jsxs(r.Box,{onMouseEnter:()=>y(!0),onMouseLeave:()=>y(!1),onClick:()=>d(o),sx:{position:"relative",display:"flex",flexDirection:"column",bgcolor:"background.paper",border:"1px solid",borderColor:i?"primary.main":A=>E(A.palette.divider,.8),borderWidth:i?2:1,borderRadius:"12px",cursor:"pointer",transition:"box-shadow 0.2s ease, border-color 0.2s ease, transform 0.15s ease",overflow:"hidden",minHeight:180,boxShadow:i?A=>`0 0 0 3px ${E(A.palette.primary.main,.15)}, 0 2px 8px ${E(A.palette.common.black,.08)}`:T?"0 4px 16px rgba(60,64,67,0.15), 0 1px 4px rgba(60,64,67,0.08)":"0 1px 3px rgba(60,64,67,0.08), 0 1px 2px rgba(60,64,67,0.06)",transform:T&&!i?"translateY(-2px)":"none","&:active":{transform:"translateY(0)"},...i&&{bgcolor:A=>E(A.palette.primary.main,.03)}},children:[e.jsx(r.Box,{sx:{px:2,pt:2,pb:1.5},children:e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,fontSize:"0.9375rem",color:"text.primary",lineHeight:1.35,wordBreak:"break-word",letterSpacing:"-0.01em"},children:S!=null&&S!==""?String(S):e.jsx(r.Box,{component:"span",sx:{color:"text.disabled",fontStyle:"italic",fontWeight:400},children:"Untitled"})})}),e.jsx(r.Box,{sx:{mx:2,height:"1px",bgcolor:"divider",flexShrink:0}}),e.jsxs(r.Box,{sx:{px:2,py:1.5,flex:1,display:"flex",flexDirection:"column",gap:1},children:[j.map(A=>e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,minHeight:22},children:[e.jsx(r.Typography,{sx:{color:"text.secondary",fontWeight:500,fontSize:"0.6875rem",textTransform:"uppercase",letterSpacing:"0.06em",minWidth:68,flexShrink:0,lineHeight:1},children:Ge(A.name)}),e.jsx(r.Box,{sx:{flex:1,lineHeight:1},children:jd(A,t[A.name])})]},A.name)),j.length===0&&e.jsx(r.Typography,{variant:"caption",color:"text.disabled",sx:{fontStyle:"italic"},children:"No additional fields visible"})]}),e.jsxs(r.Box,{sx:{px:2,py:1,display:"flex",alignItems:"center",justifyContent:"space-between",borderTop:"1px solid",borderColor:"divider",bgcolor:A=>E(A.palette.action.hover,.1),minHeight:40},children:[e.jsx(r.Typography,{sx:{color:"primary.main",fontFamily:'"Roboto Mono", "Courier New", monospace',fontSize:"0.75rem",fontWeight:400,letterSpacing:"0.04em",opacity:I?.85:0,userSelect:"none"},children:I?String(I):" "}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,opacity:a?1:0,transition:"opacity 0.15s ease"},onClick:A=>A.stopPropagation(),children:[l&&e.jsx(r.Tooltip,{title:s?"Remove from favorites":"Add to favorites",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:A=>{A.stopPropagation(),l(t)},sx:{width:28,height:28,color:s?"#fbbc04":"action.disabled","&:hover":{bgcolor:A=>E(A.palette.warning.main,.1),color:"#fbbc04"}},children:s?e.jsx(k.Star,{sx:{fontSize:17}}):e.jsx(k.StarBorder,{sx:{fontSize:17}})})}),e.jsx(r.Tooltip,{title:"More actions",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:A=>{A.stopPropagation(),g(A.currentTarget)},sx:{width:28,height:28,color:"action.active","&:hover":{bgcolor:A=>E(A.palette.text.primary,.08)}},children:e.jsx(k.MoreVert,{sx:{fontSize:17}})})})]})]}),e.jsxs(r.Popover,{open:!!f,anchorEl:f,onClose:()=>g(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{minWidth:180,py:.5,borderRadius:"10px",boxShadow:"0 4px 20px rgba(60,64,67,0.15), 0 1px 6px rgba(60,64,67,0.1)"}},onClick:A=>A.stopPropagation(),children:[e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{u(t),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(k.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"View"})]}),!c&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{m(t,o),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(k.Edit,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Edit"})]}),!c&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{h(o,t),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5},children:[e.jsx(k.ContentCopy,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Duplicate"})]}),!c&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{sx:{my:.5,mx:.5}}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{b(o,t),g(null)},sx:{py:1,px:2,gap:1.5,borderRadius:"6px",mx:.5,color:"error.main"},children:[e.jsx(k.Delete,{sx:{fontSize:18,color:"error.main"}}),e.jsx(r.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]})]})]})}function kd({row:t,grouping:o,onToggleCollapse:n}){var i;return e.jsxs(r.Box,{onClick:()=>n(t.groupKey),sx:{gridColumn:"1 / -1",display:"flex",alignItems:"center",gap:1,px:2,py:1,mt:1,mb:.5,bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"8px",cursor:"pointer",boxShadow:"0 1px 2px rgba(60,64,67,0.06)","&:hover":{bgcolor:s=>E(s.palette.primary.main,.04),borderColor:"primary.light"},transition:"all 0.15s ease"},children:[t.isCollapsed?e.jsx(k.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}):e.jsx(k.KeyboardArrowDown,{sx:{fontSize:16,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,color:"text.primary"},children:yi(t.groupLevel,((i=o==null?void 0:o.levels[t.groupLevel])==null?void 0:i.column)||"",t.groupValue)}),e.jsxs(r.Box,{sx:{px:1,py:.125,fontSize:"0.6875rem",fontWeight:600,bgcolor:s=>E(s.palette.primary.main,.1),color:"primary.main",borderRadius:"10px"},children:[t.rowCount," ",t.rowCount===1?"row":"rows"]}),Object.keys(t.aggregates).length>0&&e.jsx(r.Typography,{variant:"caption",sx:{ml:.5,color:"text.secondary"},children:Object.entries(t.aggregates).map(([s,c])=>gi(c)).filter(Boolean).join(" • ")})]})}function Td({data:t,visibleColumns:o,grouping:n,selectedRowIds:i,resolvedFavoritesSet:s,isReadOnly:c,isGrouped:d,sortStack:l=[],onSort:u,onToggleRowSelection:m,onToggleRowFavorite:h,onToggleGroupCollapse:b,onViewRow:f,onEditRow:g,onDuplicateRow:T,onDeleteRow:y}){const w=p.useMemo(()=>{const v=new Set;return i.forEach(j=>{const S=j==null?void 0:j.__urm_row_id__;S!==void 0&&v.add(S)}),v},[i]);return t.length===0?e.jsx(r.Box,{sx:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",py:10},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})}):e.jsxs(r.Box,{children:[u&&o.length>0&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,px:2,py:1,borderBottom:"1px solid",borderColor:"divider",bgcolor:"background.paper",flexWrap:"wrap"},children:[e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontWeight:500,mr:.5,whiteSpace:"nowrap"},children:"Sort by:"}),o.map(v=>{const j=l.find(S=>S.column===v.name);return e.jsxs(r.Box,{onClick:()=>u(v.name),sx:{display:"inline-flex",alignItems:"center",gap:.5,px:1.25,py:.375,borderRadius:"6px",border:"1px solid",borderColor:j?"primary.main":"divider",bgcolor:j?S=>E(S.palette.primary.main,.07):"transparent",cursor:"pointer",transition:"all 0.15s ease","&:hover":{borderColor:"primary.light",bgcolor:S=>E(S.palette.primary.main,.05)}},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",fontWeight:j?600:400,color:j?"primary.main":"text.secondary",whiteSpace:"nowrap"},children:Ge(v.name)}),j?j.direction==="asc"?e.jsx(k.ArrowUpward,{sx:{fontSize:12,color:"primary.main"}}):e.jsx(k.ArrowDownward,{sx:{fontSize:12,color:"primary.main"}}):e.jsx(k.SwapVert,{sx:{fontSize:12,color:"text.disabled"}})]},v.name)})]}),e.jsx(r.Box,{sx:{p:2,display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(272px, 1fr))",gap:1.5,alignContent:"start"},children:t.map((v,j)=>d&&v.isGroupHeader?e.jsx(kd,{row:v,grouping:n,onToggleCollapse:b||(()=>{})},`group-${v.groupKey}`):e.jsx(wd,{row:v,rowIndex:j,visibleColumns:o,isSelected:w.has(v==null?void 0:v.__urm_row_id__),isFavorite:s.has(v),isReadOnly:c,onToggleSelection:()=>m(v),onToggleFavorite:h,onView:f,onEdit:g,onDuplicate:T,onDelete:y},`card-${j}`))})]})}const ei=[10,15,25,50,100];function Id(t,o){const n=t.trim();if(n==="")return"Page number is required";if(!/^-?\d+$/.test(n))return"Must be a number";const i=parseInt(n,10);return i<1?"Page number must be at least 1":i>o?"Entered page number is out of range":null}function zd({currentPage:t,pageSize:o,totalRows:n,totalFields:i,onPageChange:s,onPageSizeChange:c}){var N;const l=Tt().palette,u=Math.ceil(n/o),[m,h]=p.useState(String(t)),[b,f]=p.useState(null),[g,T]=p.useState(!1),y=p.useRef(null);p.useEffect(()=>{g||(h(String(t)),f(null))},[t,g]);const w=p.useCallback(()=>{const W=Id(m,u);if(W){f(W);return}const H=parseInt(m.trim(),10);f(null),T(!1),H!==t&&s(H)},[m,u,t,s]),v=p.useCallback(W=>{var H;W.key==="Enter"?(W.preventDefault(),w()):W.key==="Escape"&&(h(String(t)),f(null),T(!1),(H=y.current)==null||H.blur())},[w,t]),j=p.useCallback(()=>{h(String(t)),f(null),T(!1)},[t]),S=p.useCallback(()=>{T(!0),f(null),setTimeout(()=>{var W;return(W=y.current)==null?void 0:W.select()},0)},[]);if(n<=Math.min(...ei))return null;const I=()=>{h(String(t)),f(null),T(!1)},a=()=>{I(),s(1)},A=()=>{I(),t>1&&s(t-1)},B=()=>{I(),t<u&&s(t+1)},$=()=>{I(),s(u)},Y=(t-1)*o+1,Q=Math.min(t*o,n),te=`${Math.max(2,String(u).length+.5)}ch`,x={p:.75,color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"action.disabled"}};return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:3,px:2,py:1,borderTop:"1px solid",borderColor:"divider",bgcolor:"background.paper",minHeight:48},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:2},children:[e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400},children:["Total data:"," ",e.jsx(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:n})]}),i!==void 0&&e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400},children:["Total fields:"," ",e.jsx(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:i})]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:3},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400},children:"Rows per page:"}),e.jsx(r.Select,{value:o,onChange:W=>c(Number(W.target.value)),size:"small",MenuProps:{PaperProps:{sx:{maxHeight:300}},anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"bottom",horizontal:"left"}},sx:{minWidth:70,fontSize:"0.8125rem",color:"text.primary","& .MuiSelect-select":{py:.5,px:1.5},"& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"}},children:ei.map(W=>e.jsx(r.MenuItem,{value:W,sx:{fontSize:"0.8125rem"},children:W},W))})]}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400,userSelect:"none"},children:[Y,"–",Q," of ",n]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,position:"relative"},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",userSelect:"none"},children:"Page"}),e.jsxs(r.Box,{sx:{position:"relative"},children:[b&&e.jsx(r.Box,{sx:{position:"absolute",bottom:"calc(100% + 6px)",left:"50%",transform:"translateX(-50%)",bgcolor:"background.paper",border:"1px solid",borderColor:E(l.error.main,.4),borderRadius:"6px",px:1,py:.5,boxShadow:`0 2px 8px ${E(((N=l.common)==null?void 0:N.black)??"#000",.12)}`,zIndex:20,whiteSpace:"nowrap","&::after":{content:'""',position:"absolute",top:"100%",left:"50%",transform:"translateX(-50%)",border:"5px solid transparent",borderTopColor:E(l.error.main,.4)}},children:e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:500,color:"error.main",lineHeight:1.3},children:b})}),e.jsx(r.InputBase,{inputRef:y,value:m,onChange:W=>{h(W.target.value),b&&f(null)},onKeyDown:v,onFocus:S,onBlur:j,inputProps:{"aria-label":`Page number, 1 to ${u}`,style:{textAlign:"center",padding:"2px 0",width:te,fontSize:"0.8125rem",fontWeight:600}},sx:{fontSize:"0.8125rem",fontWeight:600,color:b?"error.main":"text.primary",border:"1px solid",borderColor:b?"error.main":g?"primary.main":"divider",borderRadius:"4px",bgcolor:b?E(l.error.main,.04):g?E(l.primary.main,.04):"background.paper",px:.75,transition:"border-color 0.15s ease, background-color 0.15s ease","&:hover":{borderColor:b?"error.main":"text.secondary"},"&:focus-within":{boxShadow:b?`0 0 0 2px ${E(l.error.main,.2)}`:`0 0 0 2px ${E(l.primary.main,.2)}`}}})]}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",userSelect:"none"},children:["of ",u]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx(r.IconButton,{onClick:a,disabled:t===1,size:"small",title:"First page",sx:x,children:e.jsx(k.FirstPage,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:A,disabled:t===1,size:"small",title:"Previous page",sx:x,children:e.jsx(k.ChevronLeft,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:B,disabled:t===u,size:"small",title:"Next page",sx:x,children:e.jsx(k.ChevronRight,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:$,disabled:t===u,size:"small",title:"Last page",sx:x,children:e.jsx(k.LastPage,{sx:{fontSize:20}})})]})]})]})}function Ed(){return e.jsx(r.Chip,{icon:e.jsx(k.Visibility,{sx:{fontSize:14}}),label:"View Only",size:"small",variant:"outlined",sx:{bgcolor:"action.hover",borderColor:"divider",fontSize:"caption.fontSize",fontWeight:500}})}const Hi="urm_hint_seen_";function Bd(t){try{return localStorage.getItem(Hi+t)==="true"}catch{return!1}}function Dd(t){try{localStorage.setItem(Hi+t,"true")}catch{}}function ti(t,o){if(t==null||t==="")return"";if(o==="boolean")return t?"True":"False";if(o==="object"||o==="array")try{return JSON.stringify(t,null,2)}catch{return String(t)}return String(t)}function ri(t){const o={fontSize:11};switch(t){case"number":return e.jsx(k.Numbers,{sx:o});case"boolean":return e.jsx(k.CheckBox,{sx:o});case"array":return e.jsx(k.DataArray,{sx:o});case"object":return e.jsx(k.DataObject,{sx:o});default:return e.jsx(k.TextFields,{sx:o})}}function oi(t,o){var n,i;switch(t){case"number":return{bg:E(o.primary.main,.08),color:o.primary.main};case"boolean":return{bg:E(((n=o.success)==null?void 0:n.main)??"#2e7d32",.08),color:((i=o.success)==null?void 0:i.main)??"#2e7d32"};case"array":case"object":return{bg:E(o.secondary.main,.08),color:o.secondary.main};default:return{bg:E(o.text.secondary,.07),color:o.text.secondary}}}function Od({open:t,onClose:o,row:n,schema:i,reportName:s}){var b,f;const d=Tt().palette;if(!n)return null;const l=i.filter(g=>g.name in n),u=l.filter(g=>g.type!=="object"&&g.type!=="array"),m=l.filter(g=>g.type==="object"||g.type==="array"),h=l.length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"16px",maxHeight:"min(720px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${E(((b=d.common)==null?void 0:b.black)??"#000",.14)}, 0 2px 8px ${E(((f=d.common)==null?void 0:f.black)??"#000",.08)}`,overflow:"hidden"}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2.5,pb:2,bgcolor:"background.paper",display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,minWidth:0},children:[e.jsx(r.Box,{sx:{width:36,height:36,borderRadius:"10px",bgcolor:E(d.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(k.VisibilityOutlined,{sx:{fontSize:18,color:"primary.main"}})}),e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1rem",fontWeight:600,color:"text.primary",lineHeight:1.3},children:"View Record"}),s&&e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[s," · ",h," ",h===1?"field":"fields"]})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{mt:.25,color:"text.secondary",borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:18}})})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogContent,{sx:{p:0,overflowY:"auto",flex:1,bgcolor:E(d.text.primary,.015)},children:[u.length>0&&e.jsx(r.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"1px",bgcolor:"divider",m:2,mb:m.length>0?1.5:2,borderRadius:"12px",overflow:"hidden",border:"1px solid",borderColor:"divider"},children:u.map((g,T)=>{const y=n[g.name],w=ti(y,g.type),v=!w,j=oi(g.type,d),S=T===u.length-1&&u.length%2!==0;return e.jsxs(r.Box,{sx:{bgcolor:"background.paper",px:2,py:1.75,gridColumn:S?"span 2":"span 1",display:"flex",flexDirection:"column",gap:.75},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,px:.75,py:.25,borderRadius:"4px",bgcolor:j.bg,color:j.color,flexShrink:0},children:ri(g.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",lineHeight:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Ge(g.name)})]}),e.jsx(r.Typography,{sx:{fontSize:"0.875rem",fontWeight:v?400:500,color:v?"text.disabled":"text.primary",fontStyle:v?"italic":"normal",lineHeight:1.5,wordBreak:"break-word",fontFamily:g.type==="number"?'"Roboto Mono", monospace':"inherit"},children:v?"No value":w})]},g.name)})}),m.map(g=>{const T=n[g.name],y=ti(T,g.type),w=!y,v=oi(g.type,d);return e.jsxs(r.Box,{sx:{mx:2,mb:1.5,borderRadius:"12px",overflow:"hidden",border:"1px solid",borderColor:"divider"},children:[e.jsxs(r.Box,{sx:{px:2,py:1.25,bgcolor:"background.paper",borderBottom:"1px solid",borderColor:"divider",display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,px:.75,py:.25,borderRadius:"4px",bgcolor:v.bg,color:v.color},children:ri(g.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:Ge(g.name)}),e.jsx(r.Chip,{label:g.type,size:"small",sx:{height:18,fontSize:"0.625rem",fontWeight:600,ml:"auto",bgcolor:v.bg,color:v.color,border:"none",letterSpacing:"0.03em"}})]}),e.jsx(r.Box,{component:"pre",sx:{m:0,px:2,py:1.5,bgcolor:E(d.text.primary,.02),fontSize:"0.75rem",fontFamily:'"Roboto Mono", "Fira Code", monospace',color:w?"text.disabled":"text.primary",fontStyle:w?"italic":"normal",overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6},children:w?"No value":y})]},g.name)}),l.length===0&&e.jsxs(r.Box,{sx:{py:6,display:"flex",flexDirection:"column",alignItems:"center",gap:1,color:"text.disabled"},children:[e.jsx(k.VisibilityOutlined,{sx:{fontSize:40,opacity:.4}}),e.jsx(r.Typography,{variant:"body2",children:"No fields to display"})]})]}),e.jsx(r.Divider,{}),e.jsx(r.DialogActions,{sx:{px:3,py:1.75,bgcolor:"background.paper",justifyContent:"flex-end"},children:e.jsx(r.Button,{onClick:o,variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,px:3,py:.75,borderRadius:"8px",minWidth:80},children:"Close"})})]})}function Ad({open:t,onClose:o,onConfirm:n,rowPreview:i}){return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2.5,pb:1.5,display:"flex",alignItems:"flex-start",justifyContent:"space-between"},children:[e.jsxs(r.Stack,{direction:"row",spacing:1.5,alignItems:"flex-start",children:[e.jsx(r.Box,{sx:{width:40,height:40,borderRadius:"50%",bgcolor:"#fce8e6",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(k.WarningAmberRounded,{sx:{fontSize:22,color:"error.main"}})}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5,mb:.5},children:"Delete record?"}),e.jsxs(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary"},children:[i?`"${i}"`:"This record"," will be permanently removed."]})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"#f1f3f4",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{sx:{px:3,pb:2},children:e.jsx(r.Box,{sx:{p:2,borderRadius:"8px",bgcolor:"#fce8e6",border:"1px solid #f28b82"},children:e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"error.main",fontWeight:500},children:"This action cannot be undone. The record will be deleted from this report immediately."})})}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"grey.50",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:()=>{n(),o()},variant:"contained",startIcon:e.jsx(k.DeleteForever,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"error.main",color:"common.white",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"#b3190e",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Delete record"})]})]})}function Ho(t){const o={fontSize:11};switch(t){case"number":return e.jsx(k.Numbers,{sx:o});case"boolean":return e.jsx(k.CheckBox,{sx:o});case"array":return e.jsx(k.DataArray,{sx:o});case"object":return e.jsx(k.DataObject,{sx:o});default:return e.jsx(k.TextFields,{sx:o})}}function ni(t,o){var n,i;switch(t){case"number":return{bg:E(o.primary.main,.08),color:o.primary.main};case"boolean":return{bg:E(((n=o.success)==null?void 0:n.main)??"#2e7d32",.08),color:((i=o.success)==null?void 0:i.main)??"#2e7d32"};case"array":case"object":return{bg:E(o.secondary.main,.08),color:o.secondary.main};default:return{bg:E(o.text.secondary,.07),color:o.text.secondary}}}function Md({open:t,onClose:o,onSave:n,row:i,schema:s,reportName:c}){var w,v,j;const l=Tt().palette,[u,m]=p.useState({});if(p.useEffect(()=>{t&&i&&m({...i})},[t,i]),!i)return null;const h=s.filter(S=>S.name in i),b=h.filter(S=>S.type!=="object"&&S.type!=="array"),f=h.filter(S=>S.type==="object"||S.type==="array"),g=(S,I)=>{m(a=>({...a,[S]:I}))},T=()=>{const S={...u};h.forEach(I=>{const a=u[I.name];if(I.type==="number"){const A=Number(a);S[I.name]=isNaN(A)?i[I.name]:A}else I.type==="boolean"&&(S[I.name]=!!a)}),n(S),o()},y=h.length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"16px",maxHeight:"min(760px, calc(100vh - 80px))",display:"flex",flexDirection:"column",boxShadow:`0 8px 32px ${E(((w=l.common)==null?void 0:w.black)??"#000",.14)}, 0 2px 8px ${E(((v=l.common)==null?void 0:v.black)??"#000",.08)}`,overflow:"hidden"}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2.5,pb:2,bgcolor:"background.paper",display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:2,flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,minWidth:0},children:[e.jsx(r.Box,{sx:{width:36,height:36,borderRadius:"10px",bgcolor:E(((j=l.warning)==null?void 0:j.main)??"#ed6c02",.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(k.EditOutlined,{sx:{fontSize:18,color:"warning.main"}})}),e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsx(r.Typography,{sx:{fontSize:"1rem",fontWeight:600,color:"text.primary",lineHeight:1.3},children:"Edit Record"}),c&&e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",display:"block",mt:.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[c," · ",y," ",y===1?"field":"fields"]})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{mt:.25,color:"text.secondary",borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:18}})})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogContent,{sx:{p:2.5,overflowY:"auto",flex:1,bgcolor:E(l.text.primary,.015),display:"flex",flexDirection:"column",gap:2},children:[b.length>0&&e.jsxs(r.Box,{children:[b.length>1&&e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.08em",mb:1.25},children:"Fields"}),e.jsx(r.Box,{sx:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:1.5},children:b.map((S,I)=>{const a=u[S.name],A=ni(S.type,l),B=S.type==="boolean",$=!B&&I===b.filter(Q=>Q.type!=="boolean").length-1&&b.filter(Q=>Q.type!=="boolean").length%2!==0,Y=B||$;return S.type==="boolean"?e.jsxs(r.Box,{sx:{gridColumn:"span 2",bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"10px",px:2,py:1.5,display:"flex",alignItems:"center",justifyContent:"space-between",gap:2,transition:"border-color 0.15s","&:hover":{borderColor:"primary.main"}},children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:.25},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",px:.75,py:.25,borderRadius:"4px",bgcolor:A.bg,color:A.color},children:Ho(S.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em"},children:Ge(S.name)})]}),e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",ml:.25},children:a?"Enabled":"Disabled"})]}),e.jsx(r.Switch,{checked:!!a,onChange:Q=>g(S.name,Q.target.checked),size:"small",sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"primary.main"},"& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track":{bgcolor:"primary.main"}}})]},S.name):e.jsxs(r.Box,{sx:{gridColumn:Y?"span 2":"span 1",bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"10px",overflow:"hidden",transition:"border-color 0.15s","&:focus-within":{borderColor:"primary.main",boxShadow:`0 0 0 2px ${E(l.primary.main,.12)}`}},children:[e.jsxs(r.Box,{sx:{px:1.5,py:.875,borderBottom:"1px solid",borderColor:"divider",bgcolor:E(l.text.primary,.02),display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",px:.75,py:.25,borderRadius:"4px",bgcolor:A.bg,color:A.color},children:Ho(S.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Ge(S.name)})]}),e.jsx(r.TextField,{value:a??"",onChange:Q=>g(S.name,Q.target.value),type:S.type==="number"?"number":"text",size:"small",fullWidth:!0,variant:"standard",placeholder:`Enter ${S.type==="number"?"number":"value"}…`,InputProps:{disableUnderline:!0},sx:{"& .MuiInputBase-root":{px:1.5,py:1,fontSize:"0.875rem",fontWeight:500,color:"text.primary",fontFamily:S.type==="number"?'"Roboto Mono", monospace':"inherit"},"& .MuiInputBase-input":{p:0,"&::placeholder":{color:"text.disabled",opacity:1,fontWeight:400}}}})]},S.name)})})]}),f.length>0&&e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:1.25},children:[e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.08em"},children:"Read-only Fields"}),e.jsx(r.Tooltip,{title:"Object and array fields cannot be edited directly",arrow:!0,children:e.jsx(k.InfoOutlined,{sx:{fontSize:13,color:"text.disabled",cursor:"help"}})})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:f.map(S=>{const I=i[S.name];let a="";try{a=I==null?"":JSON.stringify(I,null,2)}catch{a=String(I)}const A=ni(S.type,l);return e.jsxs(r.Box,{sx:{bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"10px",overflow:"hidden",opacity:.8},children:[e.jsxs(r.Box,{sx:{px:1.5,py:.875,borderBottom:"1px solid",borderColor:"divider",bgcolor:E(l.text.primary,.02),display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",px:.75,py:.25,borderRadius:"4px",bgcolor:A.bg,color:A.color},children:Ho(S.type)}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.06em",flex:1},children:Ge(S.name)}),e.jsx(r.Chip,{label:"read only",size:"small",sx:{height:16,fontSize:"0.5625rem",fontWeight:600,letterSpacing:"0.04em",bgcolor:E(l.text.secondary,.07),color:"text.secondary",border:"none"}})]}),e.jsx(r.Box,{component:"pre",sx:{m:0,px:1.5,py:1.25,fontSize:"0.75rem",fontFamily:'"Roboto Mono", "Fira Code", monospace',color:a?"text.primary":"text.disabled",fontStyle:a?"normal":"italic",bgcolor:E(l.text.primary,.015),overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word",lineHeight:1.6,maxHeight:120,overflowY:"auto"},children:a||"No value"})]},S.name)})})]}),h.length===0&&e.jsxs(r.Box,{sx:{py:6,display:"flex",flexDirection:"column",alignItems:"center",gap:1,color:"text.disabled"},children:[e.jsx(k.EditOutlined,{sx:{fontSize:40,opacity:.4}}),e.jsx(r.Typography,{variant:"body2",children:"No editable fields"})]})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,bgcolor:"background.paper",gap:1,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"text.secondary",px:2,borderRadius:"8px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:T,variant:"contained",disableElevation:!0,startIcon:e.jsx(k.SaveOutlined,{sx:{fontSize:15}}),sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,px:2.5,borderRadius:"8px",minWidth:90},children:"Save"})]})]})}const _d=160,$d={active:{bg:"success.lighter",color:"success.dark"},completed:{bg:"success.lighter",color:"success.dark"},approved:{bg:"success.lighter",color:"success.dark"},success:{bg:"success.lighter",color:"success.dark"},done:{bg:"success.lighter",color:"success.dark"},contract:{bg:"primary.lighter",color:"primary.main"},"in progress":{bg:"primary.lighter",color:"primary.main"},"in review":{bg:"primary.lighter",color:"primary.main"},review:{bg:"primary.lighter",color:"primary.main"},pending:{bg:"primary.lighter",color:"primary.main"},"on leave":{bg:"error.lighter",color:"error.dark"},"on hold":{bg:"warning.lighter",color:"warning.dark"},probation:{bg:"warning.lighter",color:"warning.dark"},cancelled:{bg:"error.lighter",color:"error.dark"},rejected:{bg:"error.lighter",color:"error.dark"},blocked:{bg:"error.lighter",color:"error.dark"},inactive:{bg:"action.selected",color:"text.secondary"},"not started":{bg:"action.selected",color:"text.secondary"},paused:{bg:"action.selected",color:"text.secondary"}},Wd={low:"text.secondary",medium:"warning.dark",high:"warning.main",critical:"error.main",urgent:"error.main"};function Rd(t){const o=t.toLowerCase().trim(),n=$d[o]||{bg:"grey.100",color:"grey.600"};return e.jsx(r.Box,{component:"span",sx:{display:"inline-flex",alignItems:"center",px:1.25,py:.375,borderRadius:"12px",fontSize:"0.75rem",fontWeight:500,bgcolor:n.bg,color:n.color,whiteSpace:"nowrap",lineHeight:1.6,letterSpacing:"0.01em"},children:t})}function Pd(t){const o=t.toLowerCase().trim(),n=Wd[o];return n?e.jsx(r.Box,{component:"span",sx:{color:n,fontWeight:500,fontSize:"inherit"},children:t}):t}function Nd(t){return e.jsx(r.Box,{component:"span",sx:{color:"primary.main",fontFamily:'"Roboto Mono", "Courier New", monospace',fontSize:"0.8125rem",fontWeight:400,letterSpacing:"0.04em"},children:t})}function Ld(t,o){const n=t.name.toLowerCase().replace(/[_\s-]/g,""),i=t.name.toLowerCase(),s=o.findIndex(m=>m.name===t.name),c=/(\bid\b|id$|_id$|code$|ref$|no$|num$)/.test(n),d=i.includes("name")||i.includes("task")||i.includes("title")||i.includes("label")||i.includes("subject")||i.includes("description")||i.includes("filename"),l=i.includes("assignee")||i.includes("assigned")||i.includes("owner")||i.includes("author")||i.includes("creator")||i.includes("member")||i.includes("contact")||i.includes("recipient")||i.includes("sender"),u=s===0&&t.type!=="boolean"&&!i.includes("status")&&!i.includes("state");return c||d&&!l||u&&!l}function Fd(t){return e.jsx(r.Box,{component:"span",sx:{fontWeight:700,color:"text.primary",fontSize:"inherit"},children:t})}function Vd(t,o,n=!1,i){if(o==null||o==="")return e.jsx(r.Box,{component:"span",sx:{color:"grey.400"},children:"—"});const s=String(o),c=t.name.toLowerCase().replace(/[_\s-]/g,""),d=/\b(status|state|stage|employmenttype|contracttype|availability)\b/.test(t.name.toLowerCase());if(d)return Rd(s);const l=/\b(priority|severity|urgency|importance|criticality)\b/.test(t.name.toLowerCase());if(l)return Pd(s);const u=/(\bid\b|id$|_id$|code$|ref$|no$|num$)/.test(c)||/^[A-Z]{2,8}-\d{2,}$/.test(s);if(u)return Nd(s);if(n&&!d&&!l&&!u)return Fd(s);if(t.type==="date"){const m=t.dateFormat??"iso",h=Vs(o,m,i??null);return e.jsx(r.Box,{component:"span",sx:{color:"text.primary",whiteSpace:"nowrap"},children:h})}if(t.type==="number"&&typeof o=="number")return o.toLocaleString();if(typeof o=="boolean")return o?"Yes":"No";if(Array.isArray(o)){if(o.length===0)return e.jsx(r.Box,{component:"span",sx:{color:"grey.400"},children:"[ ]"});const m=o.slice(0,3).map(h=>typeof h=="object"?JSON.stringify(h):String(h)).join(", ");return e.jsxs(r.Box,{component:"span",sx:{color:"text.secondary",fontSize:"0.8125rem"},children:[m,o.length>3?` +${o.length-3} more`:""]})}if(typeof o=="object"){const m=JSON.stringify(o);return e.jsx(r.Box,{component:"span",title:m,sx:{color:"text.secondary",fontSize:"0.8125rem",fontFamily:"monospace",cursor:"help"},children:m.length>40?m.slice(0,40)+"…":m})}return s}function Hd({schema:t,data:o,sortStack:n=[],filters:i=[],views:s=[],activeViewId:c="",isDirty:d=!1,isExporting:l=!1,columnVisibility:u={},columnOrder:m=[],columnWidths:h={},grouping:b=null,onSort:f,onSortAscending:g,onSortDescending:T,onOpenFilters:y,onOpenSort:w,onOpenFilterForColumn:v,onSelectView:j,onCreateView:S,onManageViews:I,onUpdateCurrentView:a,onSaveAsNewView:A,onToggleDefault:B,onToggleFavorite:$,onRestoreView:Y,onPermanentDelete:Q,isAdmin:te=!1,onExport:x,onOpenColumns:N,onUpdateColumnWidth:W,onUpdateColumnOrder:H,onUpdateColumnVisibility:J,onClearFiltersForColumn:ue,onResetLayout:pe,onOpenGroup:re,onGroupByColumn:O,onToggleGroupCollapse:F,onOpenAuditHistory:G,onOpenScheduledReports:se,searchQuery:ee,searchHistory:le=[],onAddToSearchHistory:ae,onToggleSearchFavourite:P,onDeleteSearchHistory:ne,selectedRowIds:ce=new Set,onSearchChange:ie,onToggleRowSelection:he,onToggleAllRows:q,onRangeSelection:Ae,onClearSelection:We,onExportSelected:tt,currentPage:Kt=1,pageSize:hr=15,totalRowsBeforePagination:At=o.length,onPageChange:it,onPageSizeChange:Re,isReadOnly:Ee=!1,userRole:gt,reportName:st,onEditRow:rt,onDuplicateRow:Je,onDeleteRow:It,favoriteRowIndices:Xt=[],resolvedFavoritesSet:at=new Set,showFavoritesOnly:Ke=!1,onToggleRowFavorite:Pe,onBulkSetFavorites:Zt,showDevPanel:yt=!1,onOpenDevConfig:zt,onToggleFavoritesFilter:Qt}){var Ft;const[lt,gr]=p.useState(null),[yr,br]=p.useState(0),[Mt,vr]=p.useState(0),Xe=((Ft=Gt().dates)==null?void 0:Ft.displayFormat)??null,[ve,jr]=p.useState(null),[er,ot]=p.useState(null),[L,Ne]=p.useState(null),[Se,_e]=p.useState(!1),[Cr,_t]=p.useState(!1),[bt,$t]=p.useState(null),[Wt,Et]=p.useState(""),[wr,Rt]=p.useState(!1),[De,X]=p.useState(null),[vt,ge]=p.useState(null),[je,Ze]=p.useState(null),[kr,St]=p.useState(null),[$e,tr]=p.useState("list"),[Tr,rr]=p.useState(!1),[or,Ir]=p.useState(()=>!Bd("toolbar_search"));p.useRef(null);const nr=p.useCallback(()=>{Dd("toolbar_search"),Ir(!1)},[]),ir=p.useMemo(()=>m.length>0?m.map(M=>t.find(Z=>Z.name===M)).filter(M=>M!==void 0):t,[m,t]),Le=p.useMemo(()=>ir.filter(M=>u[M.name]!==!1),[ir,u]),ct=p.useMemo(()=>t.filter(M=>u[M.name]===!1).length,[t,u]),dt=p.useMemo(()=>t.map(M=>M.name),[t]),Fe=p.useMemo(()=>JSON.stringify(m)!==JSON.stringify(dt),[m,dt]),sr=p.useCallback((M,Z)=>{M.preventDefault(),M.stopPropagation(),gr(Z),br(M.clientX),vr(h[Z]||150)},[h]);p.useEffect(()=>{if(!lt)return;const M=K=>{const de=K.clientX-yr,oe=Math.max(100,Mt+de);W==null||W(lt,oe)},Z=()=>{gr(null)};return document.addEventListener("mousemove",M),document.addEventListener("mouseup",Z),()=>{document.removeEventListener("mousemove",M),document.removeEventListener("mouseup",Z)}},[lt,yr,Mt,W]);const Pt=p.useCallback(M=>M==null?"-":typeof M=="object"?JSON.stringify(M):typeof M=="boolean"?M?"true":"false":String(M),[]);p.useCallback(M=>{const Z=n.find(K=>K.column===M);return Z?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[Z.direction==="asc"?e.jsx(k.ArrowUpward,{sx:{fontSize:14}}):e.jsx(k.ArrowDownward,{sx:{fontSize:14}}),e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,bgcolor:"primary.main",color:"primary.contrastText",fontSize:"caption.fontSize",fontWeight:"bold",borderRadius:"50%"},children:Z.priority})]}):null},[n]),p.useCallback(M=>i.some(K=>K.column===M)?e.jsx(r.IconButton,{size:"small",onClick:K=>{K.stopPropagation(),v==null||v(M)},sx:{ml:.5,p:.25,color:"primary.main","&:hover":{color:"primary.main"}},title:"Active filters on this column",children:e.jsx(k.FilterList,{sx:{fontSize:14}})}):null,[i,v]);const zr=p.useCallback(M=>{f&&f(M)},[f]),Er=p.useCallback((M,Z)=>{if(!H)return;const K=[...m.length>0?m:t.map(oe=>oe.name)],[de]=K.splice(M,1);K.splice(Z,0,de),H(K)},[H,m,t]),Br=p.useCallback(M=>{if(!f)return;const Z=n.find(K=>K.column===M);(!Z||Z.direction!=="asc")&&f(M)},[f,n]),Dr=p.useCallback(M=>{if(!f)return;const Z=n.find(K=>K.column===M);Z?Z.direction==="asc"&&f(M):(f(M),setTimeout(()=>f(M),0))},[f,n]),Or=p.useCallback(M=>{if(!f)return;const Z=n.find(K=>K.column===M);Z&&(Z.direction==="asc"?(f(M),setTimeout(()=>f(M),0)):Z.direction==="desc"&&f(M))},[f,n]),Ar=p.useCallback(M=>{J&&J(M,!1)},[J]),Nt=(b==null?void 0:b.enabled)&&o.length>0&&o[0]&&"isGroupHeader"in o[0],Mr=n.length>0||i.length>0||((b==null?void 0:b.enabled)??!1)||Object.values(u).some(M=>M===!1),_r=(Kt-1)*hr,Me=o,Ve=p.useMemo(()=>{const M=new Set;return ce.forEach(Z=>{const K=Z==null?void 0:Z.__urm_row_id__;K!==void 0&&M.add(K)}),M},[ce]);p.useEffect(()=>{const M=Z=>{!q||!We||Z.target instanceof HTMLInputElement||Z.target instanceof HTMLTextAreaElement||((Z.ctrlKey||Z.metaKey)&&Z.key==="a"&&(Z.preventDefault(),q(!0,Me)),Z.key==="Escape"&&(Z.preventDefault(),We()))};return document.addEventListener("keydown",M),()=>document.removeEventListener("keydown",M)},[q,We,Me]);const ar=p.useCallback((M,Z)=>{he&&(Z.shiftKey&&ve!==null?(Z.preventDefault(),Ae&&Ae(ve,M,Me)):(he(Me[M]),jr(M)))},[he,ve,Ae,Me]);!p.useMemo(()=>Me.length>0&&Ve.size>0&&Me.every(M=>Ve.has(M==null?void 0:M.__urm_row_id__)),[Me,Ve])&&Me.some(M=>Ve.has(M==null?void 0:M.__urm_row_id__));const ut=he&&q,lr=p.useCallback(M=>{var de;const Z=M.groupLevel,K=Z*24;return e.jsx(r.TableRow,{onClick:()=>F==null?void 0:F(M.groupKey),sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"},cursor:"pointer",borderTop:2,borderColor:"divider"},children:e.jsx(r.TableCell,{colSpan:Le.length+(ut?1:0),sx:{pl:`${K+24}px`},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[M.isCollapsed?e.jsx(k.ChevronRight,{sx:{fontSize:16}}):e.jsx(k.KeyboardArrowDown,{sx:{fontSize:16}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:yi(Z,((de=b==null?void 0:b.levels[Z])==null?void 0:de.column)||"",M.groupValue)}),e.jsxs(r.Box,{sx:{px:1,py:.25,fontSize:"caption.fontSize",fontWeight:500,bgcolor:oe=>E(oe.palette.primary.main,.12),color:"primary.main",borderRadius:2},children:[M.rowCount," ",M.rowCount===1?"row":"rows"]}),Object.keys(M.aggregates).length>0&&e.jsx(r.Typography,{variant:"caption",sx:{ml:1,color:"text.secondary"},children:Object.entries(M.aggregates).map(([oe,He])=>gi(He)).filter(Boolean).join(" • ")})]})})},M.groupKey)},[Le,ut,b,F]),Lt=p.useCallback((M,Z)=>{const K=Ve.has(M==null?void 0:M.__urm_row_id__),de=er===Z;return e.jsxs(r.TableRow,{"data-row-index":Z,onMouseEnter:()=>ot(Z),onMouseLeave:()=>ot(null),onClick:oe=>{!he||oe.target.closest("[data-row-action]")||ar(Z,oe)},onContextMenu:oe=>{oe.preventDefault(),oe.stopPropagation(),Ze({mouseX:oe.clientX,mouseY:oe.clientY,row:M,rowIndex:Z})},sx:{height:34,cursor:"pointer",bgcolor:K?oe=>E(oe.palette.warning.main,.12):"background.paper",transition:"background-color 0.12s ease","&:hover":{bgcolor:K?oe=>E(oe.palette.warning.main,.2):"action.hover"},borderBottom:"1px solid",borderColor:"divider"},children:[Le.map((oe,He)=>e.jsx(r.TableCell,{sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",py:"6px",px:He===Le.length-1?`${(Pe?76:40)+16}px`:2,fontSize:"0.8125rem",fontWeight:400,color:"text.primary",borderBottom:"1px solid",borderColor:"divider",minWidth:h[oe.name]?`${h[oe.name]}px`:`${_d}px`},children:Vd(oe,M[oe.name],Ld(oe,Le),Xe)},oe.name)),e.jsx(r.TableCell,{"data-row-action":"true",onClick:oe=>oe.stopPropagation(),sx:{position:"sticky",right:0,width:Pe?76:40,minWidth:Pe?76:40,maxWidth:Pe?76:40,p:0,border:"none",borderBottom:"1px solid",borderColor:"divider",opacity:de?1:0,transition:"opacity 0.12s ease",bgcolor:"background.paper",zIndex:10,verticalAlign:"middle"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"flex-end",height:"100%",px:1,gap:.25},children:[Pe&&e.jsx(r.IconButton,{size:"small",onClick:oe=>{oe.stopPropagation(),oe.preventDefault(),Pe(M)},title:at.has(M)?"Remove from favorites":"Add to favorites",sx:{color:at.has(M)?"warning.main":"text.secondary","&:hover":{bgcolor:oe=>E(oe.palette.warning.main,.08),color:"warning.main"}},children:at.has(M)?e.jsx(k.Star,{sx:{fontSize:18}}):e.jsx(k.StarBorder,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:oe=>{oe.stopPropagation(),oe.preventDefault(),Ze({anchorEl:oe.currentTarget,row:M,rowIndex:Z})},sx:{color:"text.secondary","&:hover":{bgcolor:oe=>E(oe.palette.text.primary,.08),color:"text.primary"}},children:e.jsx(k.MoreVert,{sx:{fontSize:18}})})]})})]},Z)},[ce,_r,er,ar,Le,h,Pt,rt,Je,It,he,Pe,at,Ne,_e,Ze]);return e.jsxs(wt.DndProvider,{backend:Xo.HTML5Backend,children:[e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[ut&&tt&&We&&e.jsx(yd,{selectedCount:Ve.size,selectedRowIds:ce,resolvedFavoritesSet:at,viewMode:$e,onExportSelected:tt,onClearSelection:We,onBulkSetFavorites:Zt}),e.jsxs(r.Box,{sx:{position:"sticky",top:0,zIndex:10,bgcolor:"background.paper",borderBottom:"1px solid",borderColor:"divider",px:2,py:0,height:56,display:"flex",alignItems:"center",gap:1},children:[Ee&&e.jsx(Ed,{}),ie&&ae&&P&&ne&&e.jsx(r.Tooltip,{open:or,title:e.jsxs(r.Box,{sx:{p:.5},children:[e.jsx(r.Typography,{variant:"caption",sx:{display:"block",fontWeight:500,mb:.25},children:"💡 Search tip"}),e.jsx(r.Typography,{variant:"caption",children:"Type to search across all columns instantly"})]}),placement:"bottom-start",arrow:!0,PopperProps:{onClick:nr},componentsProps:{tooltip:{sx:{bgcolor:"primary.main","& .MuiTooltip-arrow":{color:"primary.main"},maxWidth:220,cursor:"pointer",userSelect:"none"}}},children:e.jsx(r.Box,{component:"span",children:e.jsx(xd,{value:ee||"",onChange:ie,searchHistory:le,onAddToHistory:ae,onToggleFavourite:P,onDeleteHistory:ne,disabled:Ee})})}),e.jsx(r.Tooltip,{title:"JSON format guide",children:e.jsx(r.IconButton,{size:"small",onClick:()=>rr(!0),sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:M=>E(M.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(k.InfoOutlined,{sx:{fontSize:20}})})}),Qt&&e.jsx(r.Tooltip,{title:Ke?"Show all data":"Show favorites only",children:e.jsxs(r.IconButton,{onClick:Qt,size:"small",disabled:Ee,sx:{position:"relative",color:Ke?"warning.main":"text.secondary",bgcolor:Ke?M=>E(M.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:Ke?M=>E(M.palette.warning.main,.2):M=>E(M.palette.text.primary,.06),color:Ke?"warning.main":"text.primary"},"&.Mui-disabled":{color:"action.disabled"}},children:[Ke?e.jsx(k.Star,{sx:{fontSize:20}}):e.jsx(k.StarBorder,{sx:{fontSize:20}}),Ke&&Xt.length>0&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"warning.main",color:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:Xt.length})]})}),yt&&zt&&e.jsx(r.Tooltip,{title:"Developer configuration",children:e.jsx(r.IconButton,{size:"small",onClick:zt,sx:{color:"text.secondary",borderRadius:1,border:"1px dashed",borderColor:M=>E(M.palette.text.secondary,.3),"&:hover":{bgcolor:M=>E(M.palette.warning.main,.08),borderColor:"warning.main",color:"warning.dark"}},children:e.jsx(k.DisplaySettings,{sx:{fontSize:20}})})}),e.jsx(r.Box,{sx:{flexGrow:1}}),j&&S&&I&&a&&s.length>0&&e.jsx(md,{views:s||[],activeViewId:c||"",isDirty:d,onSelectView:j,onCreateView:S,onManageViews:I,onToggleDefault:B,onToggleFavorite:$,onRestoreView:Y,onPermanentDelete:Q,isAdmin:te,isReadOnly:Ee}),!Ee&&w&&e.jsx(r.Tooltip,{title:"Sort",children:e.jsxs(r.IconButton,{onClick:w,size:"small",sx:{position:"relative",color:n.length>0?"primary.main":"text.secondary",bgcolor:n.length>0?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:n.length>0?M=>E(M.palette.primary.main,.2):M=>E(M.palette.text.primary,.06),color:n.length>0?"primary.main":"text.primary"}},children:[e.jsx(k.SwapVert,{sx:{fontSize:20}}),n.length>0&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:n.length})]})}),!Ee&&y&&e.jsx(r.Tooltip,{title:"Filter",children:e.jsxs(r.IconButton,{onClick:y,size:"small",sx:{position:"relative",color:i.length>0?"primary.main":"text.secondary",bgcolor:i.length>0?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:i.length>0?M=>E(M.palette.primary.main,.2):M=>E(M.palette.text.primary,.06),color:i.length>0?"primary.main":"text.primary"}},children:[e.jsx(k.FilterList,{sx:{fontSize:20}}),i.length>0&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:i.length})]})}),!Ee&&N&&e.jsx(r.Tooltip,{title:"Columns",children:e.jsxs(r.IconButton,{onClick:N,size:"small",sx:{position:"relative",color:ct>0||Fe?"primary.main":"text.secondary",bgcolor:ct>0||Fe?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:ct>0||Fe?M=>E(M.palette.primary.main,.2):M=>E(M.palette.text.primary,.06),color:ct>0||Fe?"primary.main":"text.primary"}},children:[e.jsx(k.ViewColumn,{sx:{fontSize:20}}),ct>0&&e.jsx(r.Box,{component:"span",sx:{position:"absolute",top:-2,right:-2,width:16,height:16,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:"primary.main",color:"common.white",borderRadius:"50%",fontSize:"0.625rem",fontWeight:700,border:"2px solid",borderColor:"background.paper"},children:ct})]})}),e.jsx(r.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5,my:1.5}}),e.jsx(r.Tooltip,{title:"List view",children:e.jsx(r.IconButton,{size:"small",onClick:()=>tr("list"),sx:{borderRadius:1,color:$e==="list"?"primary.main":"text.secondary",bgcolor:$e==="list"?"primary.lighter":"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:$e==="list"?M=>E(M.palette.primary.main,.2):M=>E(M.palette.text.primary,.06),color:$e==="list"?"primary.main":"text.primary"}},children:e.jsx(k.TableRows,{sx:{fontSize:20}})})}),e.jsx(r.Tooltip,{title:"Grid view",children:e.jsx(r.IconButton,{size:"small",onClick:()=>tr("grid"),sx:{borderRadius:1,color:$e==="grid"?"primary.main":"text.secondary",bgcolor:$e==="grid"?"primary.lighter":"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:$e==="grid"?M=>E(M.palette.primary.main,.2):M=>E(M.palette.text.primary,.06),color:$e==="grid"?"primary.main":"text.primary"}},children:e.jsx(k.GridView,{sx:{fontSize:20}})})}),e.jsx(r.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5,my:1.5}}),e.jsx(r.Tooltip,{title:"Settings",children:e.jsx(r.IconButton,{onClick:M=>St(M.currentTarget),size:"small",sx:{color:"text.secondary",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:M=>E(M.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(k.Settings,{sx:{fontSize:20}})})})]}),e.jsxs(r.Popover,{open:!!kr,anchorEl:kr,onClose:()=>St(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},PaperProps:{sx:{mt:.5,minWidth:200,py:.5,borderRadius:1.5,boxShadow:3}},children:[x&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{x(),St(null)},disabled:l,sx:{py:1,px:2,gap:1.5},children:[e.jsx(k.Download,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Export"})]}),!Ee&&re&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{re(),St(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(k.Layers,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Grouping"})]}),G&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{G(),St(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(k.History,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Audit History"})]}),se&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{se(),St(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(k.Schedule,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Scheduled Reports"})]})]}),e.jsxs(r.Box,{sx:{position:"relative",flex:1,display:"flex",flexDirection:"column",minHeight:0},children:[$e==="grid"&&e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",overflowX:"hidden",bgcolor:"action.hover"},children:e.jsx(Td,{data:Me,visibleColumns:Le,grouping:b,selectedRowIds:ce,resolvedFavoritesSet:at,isReadOnly:Ee,isGrouped:!!Nt,sortStack:n,onSort:f,onToggleRowSelection:he||(()=>{}),onToggleRowFavorite:Pe,onToggleGroupCollapse:F,onViewRow:M=>{Ne(M),_e(!0)},onEditRow:(M,Z)=>{X(M),ge(Z),Rt(!0)},onDuplicateRow:(M,Z)=>Je==null?void 0:Je(M,Z),onDeleteRow:(M,Z)=>{$t(Z);const K=Object.values(Z).find(de=>de!=null&&de!=="");Et(K?String(K):""),_t(!0)}})}),$e==="list"&&e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",overflowX:"auto",position:"relative",bgcolor:"background.paper","&::-webkit-scrollbar":{width:8,height:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:M=>M.palette.mode==="dark"?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.2)",borderRadius:4,"&:hover":{bgcolor:M=>M.palette.mode==="dark"?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.3)"}}},children:e.jsxs(r.Table,{sx:{tableLayout:"fixed",borderCollapse:"collapse",width:"100%",minWidth:"100%"},children:[e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{sx:{height:34,bgcolor:"action.hover",borderBottom:"1px solid",borderColor:"divider"},children:[Le.map((M,Z)=>e.jsx(gd,{column:M,index:Z,sortRule:n.find(K=>K.column===M.name),hasFilters:i.some(K=>K.column===M.name),isInSortStack:n.some(K=>K.column===M.name),isReadOnly:Ee,hasModifications:Mr,width:h[M.name],onColumnClick:zr,onMoveColumn:Er,onResizeStart:sr,onSortAscending:g||Br,onSortDescending:T||Dr,onRemoveSort:Or,onOpenFilterForColumn:v||(()=>{}),onClearFiltersForColumn:ue||(()=>{}),onGroupByColumn:O,onHideColumn:Ar,onManageColumns:N||(()=>{}),onManageViews:I,onResetLayout:pe},M.name)),e.jsx(r.TableCell,{sx:{position:"sticky",top:0,right:0,width:Pe?76:40,minWidth:Pe?76:40,p:0,border:"none",borderBottom:"1px solid",borderColor:"divider",bgcolor:"action.hover",zIndex:25}})]})}),e.jsx(r.TableBody,{children:Me.length===0?e.jsx(r.TableRow,{children:e.jsx(r.TableCell,{colSpan:Le.length+(ut?1:0),align:"center",sx:{py:4},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})})}):Nt?Me.map((M,Z)=>M.isGroupHeader?lr(M):Lt(M,Z)):Me.map((M,Z)=>Lt(M,Z))})]})}),it&&Re&&e.jsx(zd,{currentPage:Kt,pageSize:hr,totalRows:At,totalFields:t.length,onPageChange:it,onPageSizeChange:Re}),!(it&&Re)&&e.jsx(r.Box,{sx:{px:3,py:1.5,bgcolor:"action.hover",borderTop:1,borderColor:"divider"},children:e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["Showing ",Me.length," ",Me.length===1?"row":"rows"]})})]})]}),e.jsxs(r.Popover,{open:!!je,onClose:()=>Ze(null),anchorEl:(je==null?void 0:je.anchorEl)||null,anchorReference:je!=null&&je.anchorEl?"anchorEl":"anchorPosition",anchorPosition:je&&!je.anchorEl?{top:je.mouseY,left:je.mouseX}:void 0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:je!=null&&je.anchorEl?{vertical:"top",horizontal:"right"}:{vertical:"top",horizontal:"left"},PaperProps:{sx:{minWidth:176,py:.5,borderRadius:1.5,boxShadow:3}},children:[e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{je&&(Ne(je.row),_e(!0)),Ze(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(k.Visibility,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"View"})]}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{je&&(X(je.row),ge(je.rowIndex),Rt(!0)),Ze(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(k.Edit,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Edit"})]}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{je&&(Je==null||Je(je.rowIndex,je.row)),Ze(null)},sx:{py:1,px:2,gap:1.5},children:[e.jsx(k.ContentCopy,{sx:{fontSize:18,color:"text.secondary"}}),e.jsx(r.Typography,{variant:"body2",children:"Duplicate"})]}),e.jsx(r.Divider,{sx:{my:.5}}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{if(je){$t(je.row);const M=Object.values(je.row).find(Z=>Z!=null&&Z!=="");Et(M?String(M):""),_t(!0)}Ze(null)},sx:{py:1,px:2,gap:1.5,color:"error.main"},children:[e.jsx(k.Delete,{sx:{fontSize:18,color:"error.main"}}),e.jsx(r.Typography,{variant:"body2",color:"error.main",children:"Delete"})]})]}),e.jsx(Od,{open:Se,onClose:()=>{_e(!1),Ne(null)},row:L,schema:t,reportName:st}),e.jsx(Md,{open:wr,onClose:()=>{Rt(!1),X(null),ge(null)},onSave:M=>{vt!==null&&(rt==null||rt(vt,M))},row:De,schema:t,reportName:st}),e.jsx(Ad,{open:Cr,onClose:()=>{_t(!1),$t(null)},onConfirm:()=>{bt!==null&&(It==null||It(bt))},rowPreview:Wt}),e.jsx(Fi,{isOpen:Tr,onClose:()=>rr(!1)})]})}function qt({content:t,isDev:o=!1}){const[n,i]=p.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(r.IconButton,{size:"small",onClick:s=>i(s.currentTarget),"aria-label":`Help: ${t.title}`,sx:{p:.375,color:"text.disabled","&:hover":{color:"primary.main",bgcolor:s=>E(s.palette.primary.main,.08)}},children:e.jsx(k.InfoOutlined,{sx:{fontSize:15}})}),e.jsxs(r.Popover,{open:!!n,anchorEl:n,onClose:()=>i(null),anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},PaperProps:{sx:{width:280,borderRadius:"10px",boxShadow:4,p:0,overflow:"hidden"}},children:[e.jsx(r.Box,{sx:{px:2,py:1.5,bgcolor:s=>E(s.palette.primary.main,.06)},children:e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,color:"primary.main",fontSize:"0.875rem"},children:t.title})}),e.jsx(r.Divider,{}),e.jsxs(r.Box,{sx:{px:2,py:1.5,display:"flex",flexDirection:"column",gap:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{color:"text.secondary",fontSize:"0.8125rem",lineHeight:1.6},children:t.description}),t.tips&&t.tips.length>0&&e.jsx(r.Box,{component:"ul",sx:{m:0,pl:2,display:"flex",flexDirection:"column",gap:.5},children:t.tips.map((s,c)=>e.jsx(r.Box,{component:"li",sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.5},children:s},c))}),o&&t.devNote&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{sx:{my:.5}}),e.jsxs(r.Box,{sx:{px:1.25,py:.75,borderRadius:"6px",bgcolor:s=>E(s.palette.warning.main,.08),border:"1px solid",borderColor:s=>E(s.palette.warning.main,.2)},children:[e.jsx(r.Typography,{variant:"caption",sx:{color:"warning.dark",fontWeight:500,display:"block",mb:.25},children:"Dev note"}),e.jsx(r.Typography,{variant:"caption",sx:{color:"warning.dark",lineHeight:1.5},children:t.devNote})]})]})]})]})]})}const Jt={filter:{title:"Filter columns",description:"Narrow down rows by setting conditions on any column. Only rows matching all active filters are shown.",tips:["Add multiple conditions to combine filters (AND logic)",'Use "Contains" for partial text matches','Use "Is empty" to find missing values',"Clear all filters to return to the full dataset"],devNote:"Max filter conditions controlled by DevConfig → Filter → maxConditions. Allowed operators also configurable."},sort:{title:"Sort columns",description:"Order rows by one or more columns. Drag levels to set sort priority — the first level is applied first.",tips:["Add multiple sort levels for multi-column sorting","Drag the ⋮⋮ handle to reorder sort priority","Each level can be ascending (A→Z, 0→9) or descending"],devNote:"Max sort levels controlled by DevConfig → Sort → maxLevels."},grouping:{title:"Group data",description:"Organize rows into collapsible groups by one or more column values. Each unique value becomes a group header.",tips:["Add up to 3 nesting levels for hierarchical grouping","Click a group header to collapse or expand it","Aggregates (count) are shown on each group header","Combine grouping with filters and sort for focused views"],devNote:"Max group levels controlled by DevConfig → Grouping → maxLevels. allowNested and allowCollapse also configurable."},columns:{title:"Manage columns",description:"Control which columns are visible, their display order, and their widths.",tips:["Drag rows to reorder columns","Toggle the eye icon to show or hide a column","Drag the resize handle in the table header to resize","Reset to restore default visibility and order"],devNote:"Max visible columns and width range controlled by DevConfig → Columns."},export:{title:"Export data",description:"Download the report data as a file. Choose between CSV, Excel, or JSON format.",tips:["CSV: universal format, opens in any spreadsheet app","Excel: formatted .xlsx file with native Excel support","JSON: structured data including metadata","Export visible rows only (after filters) or all rows"],devNote:"Allowed export formats controlled by DevConfig → Export → allowedFormats."},schedule:{title:"Scheduled reports",description:"Set up automatic exports that run at a specified time — daily, weekly, or monthly.",tips:["The browser tab must remain open for the schedule to fire","Each schedule triggers a file download automatically","Add an email address to open a notification in your mail app","Pause a schedule without deleting it"],devNote:"Schedules are stored in localStorage per-report. Key: urm_schedules_{reportId}."},auditHistory:{title:"Audit history",description:"A full log of all changes made to this report — filters applied, sorts changed, views saved, exports triggered, and more.",tips:["Each entry shows the action, timestamp, and who performed it","Use audit history to trace back unexpected changes"],devNote:"Audit entries are stored per-report in IndexedDB via the persistence layer."}};function Ud({schema:t,filters:o,onAddFilter:n,onRemoveFilter:i,onUpdateFilter:s,onClearAll:c,onClose:d,focusColumn:l}){const[u,m]=p.useState(""),[h,b]=p.useState(""),[f,g]=p.useState(""),[T,y]=p.useState([]),w=Gt();p.useEffect(()=>{y([...o])},[o]),p.useEffect(()=>{l&&m(l)},[l]);const v=p.useCallback(()=>{m(""),b(""),g("")},[]),j=p.useMemo(()=>t.filter(x=>x.type!=="mixed"&&x.type!=="null"&&x.type!=="array"&&x.type!=="object"),[t]),S=t.find(x=>x.name===u),I=p.useMemo(()=>{const x=S?wn(S.type):[],N=w.filter.allowedOperators;return N.length>0?x.filter(W=>N.includes(W.value)):x},[S]),a=p.useCallback(()=>!(!u||!h||to(h)&&!f.trim()||T.length>=w.filter.maxConditions),[u,h,f,T,w]),A=p.useCallback(()=>{if(!a())return;const x={column:u,operator:h};if(to(h)){const W=S==null?void 0:S.type;x.value=W==="number"?Number(f):f}if(T.some(W=>W.column===x.column&&W.operator===x.operator&&W.value===x.value)){v();return}y([...T,x]),v()},[a,u,h,S,f,T,v]),B=p.useCallback(x=>{y(T.filter((N,W)=>W!==x))},[T]),$=p.useMemo(()=>T.length!==o.length?!0:JSON.stringify(T)!==JSON.stringify(o),[T,o]),Y=p.useCallback(()=>{c(),T.forEach(x=>n(x)),d()},[T,n,c,d]),Q=p.useCallback(()=>{y([...o]),v(),d()},[o,v,d]),te=p.useCallback(x=>{var J;const N=t.find(ue=>ue.name===x.column);if(!N)return"";const H=((J=wn(N.type).find(ue=>ue.value===x.operator))==null?void 0:J.label)||x.operator;return to(x.operator)?`${x.column} ${H.toLowerCase()} "${x.value}"`:`${x.column} ${H.toLowerCase()}`},[t]);return e.jsx(r.Box,{onClick:Q,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:x=>x.stopPropagation(),elevation:0,sx:{position:"relative",width:520,maxWidth:"calc(100vw - 120px)",maxHeight:"min(520px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Filter columns"}),e.jsx(qt,{content:Jt.filter,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:Q,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:1,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:[e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add filter"}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.75},children:[e.jsxs(r.FormControl,{size:"small",fullWidth:!0,children:[e.jsx(r.InputLabel,{sx:{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},children:"Column"}),e.jsx(r.Select,{value:u,onChange:x=>{m(x.target.value),b(""),g("")},label:"Column",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:j.map(x=>e.jsxs(r.MenuItem,{value:x.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:N=>E(N.palette.primary.main,.2)}}},children:[Ge(x.name)," (",x.type,")"]},x.name))})]}),u&&e.jsxs(r.FormControl,{size:"small",fullWidth:!0,children:[e.jsx(r.InputLabel,{sx:{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},children:"Operator"}),e.jsx(r.Select,{value:h,onChange:x=>{b(x.target.value),g("")},label:"Operator",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:I.map(x=>e.jsx(r.MenuItem,{value:x.value,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:N=>E(N.palette.primary.main,.2)}}},children:x.label},x.value))})]}),h&&to(h)&&e.jsx(r.TextField,{size:"small",fullWidth:!0,type:(S==null?void 0:S.type)==="number"?"number":"text",value:f,onChange:x=>g(x.target.value),label:"Value",placeholder:"Enter value...",sx:{"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:1,color:"text.primary"}}})]}),e.jsx(r.Button,{onClick:A,disabled:!a(),sx:{mt:1.5,textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",p:0,justifyContent:"flex-start",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"primary.dark",textDecoration:"underline"},"&.Mui-disabled":{color:"grey.400"}},children:"+ Add another filter"})]}),T.length>0&&e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1.5},children:[e.jsxs(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",textTransform:"uppercase"},children:["Active filters (",T.length,")"]}),e.jsx(r.Button,{onClick:()=>y([]),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"error.main",p:0,minWidth:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"#b3190e",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:T.map((x,N)=>e.jsx(r.Chip,{label:te(x),onDelete:()=>B(N),sx:{bgcolor:"primary.lighter",color:"primary.main",fontSize:"0.875rem",fontWeight:400,height:32,borderRadius:"16px",border:W=>`1px solid ${E(W.palette.primary.main,.3)}`,transition:"all 0.2s ease","&:hover":{bgcolor:W=>E(W.palette.primary.main,.2),borderColor:"#aecbfa"},"& .MuiChip-label":{px:1.5,color:"primary.main"},"& .MuiChip-deleteIcon":{color:"primary.main",fontSize:18,transition:"all 0.2s ease","&:hover":{color:"primary.dark"}}}},N))})]})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:Q,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:Y,disabled:!$,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"grey.300",color:"grey.500"}},children:"Apply filter"})]})]})})}const ii="SORT_RULE";function Yd({rule:t,index:o,onToggleDirection:n,onRemove:i,onMove:s}){const c=p.useRef(null),[{handlerId:d},l]=wt.useDrop({accept:ii,collect(h){return{handlerId:h.getHandlerId()}},hover(h,b){var j;if(!c.current)return;const f=h.index,g=o;if(f===g)return;const T=(j=c.current)==null?void 0:j.getBoundingClientRect(),y=(T.bottom-T.top)/2,w=b.getClientOffset(),v=((w==null?void 0:w.y)??0)-T.top;f<g&&v<y||f>g&&v>y||(s(f,g),h.index=g)}}),[{isDragging:u},m]=wt.useDrag({type:ii,item:()=>({index:o}),collect:h=>({isDragging:h.isDragging()})});return m(l(c)),e.jsxs(r.Box,{ref:c,"data-handler-id":d,sx:{display:"flex",alignItems:"center",gap:1.25,px:2,py:1.25,borderRadius:"8px",bgcolor:"background.paper",border:"1px solid divider",opacity:u?.4:1,cursor:"move",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:"grey.50",borderColor:"grey.300",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.1), 0 1px 3px 1px rgba(60, 64, 67, 0.05)",transform:"translateY(-1px)"}},children:[e.jsx(r.Chip,{label:t.priority,size:"small",sx:{width:26,height:26,fontSize:"0.75rem",fontWeight:600,bgcolor:"primary.main",color:"background.paper",boxShadow:"0 1px 2px 0 rgba(25, 103, 210, 0.3)","& .MuiChip-label":{px:0}}}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:"3px",cursor:"grab",px:.5,opacity:.6,transition:"opacity 0.2s ease","&:hover":{opacity:1},"&:active":{cursor:"grabbing"}},children:[e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}}),e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}}),e.jsx(r.Box,{sx:{width:"4px",height:"4px",borderRadius:"50%",bgcolor:"text.secondary"}})]}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",fontWeight:400,color:"text.primary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:"0 0 100px",lineHeight:1.5},children:t.column}),e.jsx(r.FormControl,{size:"small",sx:{flex:1,minWidth:100},children:e.jsxs(r.Select,{value:t.direction,onChange:h=>n(o,h.target.value),sx:{fontSize:"0.875rem",height:36,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"& .MuiSelect-select":{py:.875,color:"text.primary",fontWeight:400}},children:[e.jsx(r.MenuItem,{value:"asc",sx:{fontSize:"0.875rem",color:"text.primary","&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:h=>E(h.palette.primary.main,.2)}}},children:"Ascending"}),e.jsx(r.MenuItem,{value:"desc",sx:{fontSize:"0.875rem",color:"text.primary","&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:h=>E(h.palette.primary.main,.2)}}},children:"Descending"})]})}),e.jsx(r.IconButton,{onClick:()=>i(o),size:"small",sx:{p:.5,color:"text.secondary",transition:"all 0.2s ease","&:hover":{color:"error.main",bgcolor:"rgba(217, 48, 37, 0.08)",transform:"scale(1.1)"}},children:e.jsx(k.Close,{sx:{fontSize:18}})})]})}function Gd({schema:t,sortStack:o,onUpdateSortStack:n,onClose:i}){const[s,c]=p.useState(""),[d,l]=p.useState([]);p.useEffect(()=>{l([...o])},[o]);const u=Gt(),m=p.useCallback(()=>!(d.length>=u.sort.maxLevels||!s||d.some(j=>j.column===s)),[d,s]),h=p.useCallback(()=>{if(!m())return;const j=d.length+1,S={column:s,direction:"asc",priority:j};l([...d,S]),c("")},[m,s,d]),b=p.useCallback(j=>{const I=d.filter((a,A)=>A!==j).map((a,A)=>({...a,priority:A+1}));l(I)},[d]),f=p.useCallback((j,S)=>{const I=[...d];I[j]={...I[j],direction:S},l(I)},[d]),g=p.useCallback((j,S)=>{const I=[...d],[a]=I.splice(j,1);I.splice(S,0,a);const A=I.map((B,$)=>({...B,priority:$+1}));l(A)},[d]),T=p.useCallback(()=>{l([])},[]),y=p.useCallback(()=>{n(d),i()},[d,n,i]),w=p.useCallback(()=>{l([...o]),c(""),i()},[o,i]),v=t.filter(j=>!d.some(S=>S.column===j.name));return e.jsx(wt.DndProvider,{backend:Xo.HTML5Backend,children:e.jsx(r.Box,{onClick:w,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:j=>j.stopPropagation(),elevation:0,sx:{position:"relative",width:480,maxWidth:"calc(100vw - 120px)",maxHeight:"min(440px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Sort columns"}),e.jsx(qt,{content:Jt.sort,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:w,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:2.5,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:[e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add sort level"}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,disabled:d.length>=u.sort.maxLevels,children:[e.jsx(r.InputLabel,{sx:{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},children:"Select column..."}),e.jsx(r.Select,{value:s,onChange:j=>c(j.target.value),label:"Select column...",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-disabled":{bgcolor:"grey.50"}},children:v.map(j=>e.jsx(r.MenuItem,{value:j.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:S=>E(S.palette.primary.main,.2)}}},children:Ge(j.name)},j.name))})]}),e.jsx(r.Button,{onClick:h,disabled:!m(),sx:{mt:1.5,textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",p:0,justifyContent:"flex-start",minHeight:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"primary.dark",textDecoration:"underline"},"&.Mui-disabled":{color:"grey.400"}},children:"+ Add sort column"}),d.length>=u.sort.maxLevels&&e.jsxs(r.Typography,{variant:"caption",sx:{mt:.75,display:"block",color:"warning.dark",fontSize:"0.75rem",fontWeight:500},children:["Maximum ",u.sort.maxLevels," sort levels allowed"]})]}),d.length>0&&e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1.5},children:[e.jsxs(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",textTransform:"uppercase"},children:["Sorted sequence (",d.length,"/",u.sort.maxLevels,")"]}),e.jsx(r.Button,{onClick:T,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"error.main",p:0,minWidth:"auto",minHeight:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"#b3190e",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:d.map((j,S)=>e.jsx(Yd,{rule:j,index:S,onToggleDirection:f,onRemove:b,onMove:g},`${j.column}-${S}`))})]})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:w,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:y,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Apply sort"})]})]})})})}function qd({views:t,activeViewId:o,onSelectView:n,onCreateView:i,onEditView:s,onDeleteView:c,onRestoreView:d,onPermanentDelete:l,onPromoteToGlobal:u,isAdmin:m=!1,onClose:h}){var S,I;const f=Tt().palette,g=t.filter(a=>!a.isDeleted),T=t.filter(a=>a.isDeleted),y=g.filter(a=>a.scope==="global"),w=g.filter(a=>a.scope!=="global"),v=a=>{var Q,te,x,N,W;const A=a.scope==="global",B=a.id===o,$=m||!A,Y=m&&!A;return e.jsx(r.Paper,{variant:"outlined",sx:{p:0,overflow:"hidden",borderRadius:"8px",borderColor:B?"primary.main":"divider",bgcolor:B?E(f.primary.main,.03):"background.paper",transition:"border-color 0.15s","&:hover":{borderColor:B?"primary.main":E(f.text.primary,.22)}},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:1.75,py:1.25,gap:1},children:[e.jsxs(r.Box,{sx:{flex:1,minWidth:0,cursor:"pointer",display:"flex",alignItems:"center",gap:1},onClick:()=>{n(a.id),h()},children:[e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsx(r.Typography,{sx:{fontSize:"0.875rem",fontWeight:B?600:500,color:B?"primary.main":"text.primary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.name}),a.description&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.description})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[A&&e.jsx(r.Chip,{label:"Global",size:"small",icon:e.jsx(k.Language,{sx:{fontSize:"11px !important"}}),sx:{height:20,fontSize:"0.625rem",fontWeight:700,letterSpacing:"0.04em",bgcolor:E(((Q=f.info)==null?void 0:Q.main)??f.primary.main,.1),color:((te=f.info)==null?void 0:te.main)??f.primary.main,border:`1px solid ${E(((x=f.info)==null?void 0:x.main)??f.primary.main,.25)}`,"& .MuiChip-label":{px:.625},"& .MuiChip-icon":{ml:.5}}}),a.isDefault&&e.jsx(r.Chip,{label:"Default",size:"small",sx:{height:20,fontSize:"0.625rem",fontWeight:600,bgcolor:E(f.text.secondary,.08),color:"text.secondary","& .MuiChip-label":{px:.75}}})]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,flexShrink:0},children:[Y&&u&&e.jsx(r.Tooltip,{title:"Promote to Global View",arrow:!0,placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:H=>{H.stopPropagation(),u(a.id)},sx:{p:.625,color:"text.secondary",borderRadius:"6px","&:hover":{color:((N=f.info)==null?void 0:N.main)??f.primary.main,bgcolor:E(((W=f.info)==null?void 0:W.main)??f.primary.main,.08)}},children:e.jsx(k.Language,{sx:{fontSize:16}})})}),$&&e.jsx(r.Tooltip,{title:A&&!m?"Global Views are read-only":"Edit view",arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:A&&!m,onClick:H=>{H.stopPropagation(),s(a.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"primary.main",bgcolor:E(f.primary.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(k.Edit,{sx:{fontSize:15}})})})}),e.jsx(r.Tooltip,{title:A&&!m?"Only admins can delete Global Views":"Delete view",arrow:!0,placement:"top",children:e.jsx("span",{children:e.jsx(r.IconButton,{size:"small",disabled:A&&!m,onClick:H=>{H.stopPropagation(),c(a.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:E(f.error.main,.08)},"&.Mui-disabled":{opacity:.35}},children:e.jsx(k.Delete,{sx:{fontSize:15}})})})})]})]})},a.id)},j=a=>{var A;return e.jsxs(r.Paper,{variant:"outlined",sx:{px:1.75,py:1.25,borderRadius:"8px",borderColor:"divider",display:"flex",alignItems:"center",justifyContent:"space-between",bgcolor:E(f.text.primary,.02)},children:[e.jsx(r.Typography,{sx:{fontSize:"0.875rem",color:"text.disabled",textDecoration:"line-through",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.name}),e.jsxs(r.Box,{sx:{display:"flex",gap:.25,flexShrink:0,ml:1},children:[d&&e.jsx(r.Tooltip,{title:"Restore view",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:B=>{B.stopPropagation(),d(a.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"success.main",bgcolor:E(((A=f.success)==null?void 0:A.main)??"#2e7d32",.08)}},children:e.jsx(k.Undo,{sx:{fontSize:15}})})}),l&&e.jsx(r.Tooltip,{title:"Delete permanently",arrow:!0,children:e.jsx(r.IconButton,{size:"small",onClick:B=>{B.stopPropagation(),l(a.id)},sx:{p:.625,borderRadius:"6px","&:hover":{color:"error.main",bgcolor:E(f.error.main,.08)}},children:e.jsx(k.Delete,{sx:{fontSize:15}})})})]})]},a.id)};return e.jsxs(r.Dialog,{open:!0,onClose:h,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:"14px",maxHeight:"min(640px, calc(100vh - 80px))",boxShadow:`0 8px 32px ${E(((S=f.common)==null?void 0:S.black)??"#000",.14)}`}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontSize:"1rem",fontWeight:600},children:"Manage Views"}),m&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.125},children:"Admin mode — you can promote Personal Views to Global"})]}),e.jsx(r.IconButton,{onClick:h,size:"small",sx:{color:"text.secondary"},children:e.jsx(k.Close,{sx:{fontSize:19}})})]}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",pb:2},children:[e.jsx(r.Box,{sx:{mb:2},children:e.jsx(r.Button,{onClick:i,variant:"contained",disableElevation:!0,startIcon:e.jsx(k.Add,{sx:{fontSize:16}}),size:"small",sx:{textTransform:"none",borderRadius:"7px",fontWeight:500},children:"Create New View"})}),y.length>0&&e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:1},children:[e.jsx(k.Language,{sx:{fontSize:14,color:((I=f.info)==null?void 0:I.main)??f.primary.main}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Global Views"}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:"— visible to all users"})]}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:y.map(v)})]}),w.length>0&&e.jsxs(r.Box,{sx:{mb:2.5},children:[e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.07em",mb:1},children:"Personal Views"}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:w.map(v)})]}),T.length>0&&e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.disabled",textTransform:"uppercase",letterSpacing:"0.07em",mb:1},children:"Recently Deleted"}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:T.map(j)})]}),g.length===0&&T.length===0&&e.jsx(r.Box,{sx:{py:4,textAlign:"center",color:"text.disabled"},children:e.jsx(r.Typography,{variant:"body2",children:"No views created yet"})})]}),e.jsx(r.DialogActions,{sx:{px:3,py:1.5,borderTop:"1px solid",borderColor:"divider",justifyContent:"flex-end"},children:e.jsx(r.Button,{onClick:h,variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,borderRadius:"7px",px:3},children:"Close"})})]})}const so=50;function si({currentSnapshot:t,onSave:o,onClose:n,isEditMode:i=!1,initialName:s="",initialDescription:c="",initialIsDefault:d=!1,atViewLimit:l=!1,maxViews:u=10}){const[m,h]=p.useState(s),[b,f]=p.useState(!1),[g,T]=p.useState(c),[y,w]=p.useState(d),v=()=>{if(!m.trim()){f(!0);return}if(m.trim().length>so){f(!0);return}o(m.trim(),g.trim(),y),n()},j=I=>{I.key==="Enter"&&!I.shiftKey?v():I.key==="Escape"&&n()},S=()=>i&&s?`Update ${s} view`:"Create New Report View";return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:"12px",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[S(),e.jsx(r.IconButton,{onClick:n,size:"small",sx:{color:"text.secondary"},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2,pt:1},children:[l&&!i&&e.jsxs(r.Alert,{severity:"warning",sx:{borderRadius:"8px"},children:["You have reached the maximum of ",u," saved views. Delete an existing view before creating a new one."]}),e.jsx(r.TextField,{label:"View Name",required:!0,value:m,onChange:I=>{I.target.value.length<=so&&h(I.target.value),b&&I.target.value.trim()&&f(!1)},onKeyDown:j,placeholder:"e.g., Active Users",autoFocus:!0,fullWidth:!0,size:"small",disabled:l&&!i,inputProps:{maxLength:so},error:b&&!m.trim(),helperText:b&&!m.trim()?"View name is required":`${m.length} / ${so}`}),e.jsx(r.TextField,{label:"Description (optional)",value:g,onChange:I=>T(I.target.value),placeholder:"Brief description of this view",multiline:!0,rows:2,fullWidth:!0,size:"small"}),e.jsxs(r.Paper,{sx:{p:2,bgcolor:"action.hover"},variant:"outlined",children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,mb:1},children:"This view will capture:"}),e.jsxs(r.Box,{component:"ul",sx:{m:0,pl:2,"& li":{fontSize:"body2.fontSize",color:"text.secondary"}},children:[e.jsxs("li",{children:[t.filters.length," filter",t.filters.length!==1?"s":""]}),e.jsxs("li",{children:["Sorting: ",ra(t.sortStack)]}),e.jsx("li",{children:"Column order & visibility"})]})]}),!i&&e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:y,onChange:I=>w(I.target.checked),size:"small"}),label:e.jsx(r.Typography,{variant:"body2",children:"Set as default view"})})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"grey.50",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:v,variant:"contained",disabled:l&&!i,startIcon:e.jsx(k.Save,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"grey.400"}},children:i?"Save Changes":"Create Report View"})]})]})}function Jd({viewName:t,onConfirm:o,onCancel:n}){return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(480px, calc(100vh - 180px))",my:"auto",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:["Delete View",e.jsx(r.IconButton,{onClick:n,size:"small",sx:{color:"text.secondary"},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:1.5,mt:1},children:[e.jsx(k.Warning,{color:"error",sx:{fontSize:20,flexShrink:0}}),e.jsxs(r.Box,{children:[e.jsxs(r.Typography,{variant:"body2",sx:{mb:1},children:["Are you sure you want to delete the view ",e.jsxs("strong",{children:['"',t,'"']}),"?"]}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"This action cannot be undone."})]})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:.875,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"action.selected",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:o,variant:"contained",color:"error",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Delete View"})]})]})}const Jo=80,Ko=600,ai="COLUMN";function Kd({column:t,index:o,isVisible:n,width:i,onToggleVisibility:s,onWidthChange:c,moveColumn:d}){const l=p.useRef(null),[u,m]=p.useState(i.toString());p.useEffect(()=>{m(i.toString())},[i]);const[{handlerId:h},b]=wt.useDrop({accept:ai,collect(j){return{handlerId:j.getHandlerId()}},hover(j,S){var Q;if(!l.current)return;const I=j.index,a=o;if(I===a)return;const A=(Q=l.current)==null?void 0:Q.getBoundingClientRect(),B=(A.bottom-A.top)/2,$=S.getClientOffset(),Y=(($==null?void 0:$.y)??0)-A.top;I<a&&Y<B||I>a&&Y>B||(d(I,a),j.index=a)}}),[{isDragging:f},g]=wt.useDrag({type:ai,item:()=>({index:o}),collect:j=>({isDragging:j.isDragging()})});g(b(l));const T=()=>{const j=parseInt(u);if(isNaN(j)){m(i.toString()),c(t.name,i);return}const S=Math.max(Jo,Math.min(Ko,j));m(S.toString()),c(t.name,S)},y=j=>{if(j===""||/^\d+$/.test(j)){m(j);const S=parseInt(j);if(!isNaN(S)&&S>=Jo){const I=Math.min(Ko,S);c(t.name,I)}}},w=j=>{j.key==="Enter"&&(j.preventDefault(),T(),j.target.blur())},v=j=>({string:"primary.main",number:"success.main",boolean:"#9334e6",array:"#ea8600",object:"error.main",null:"text.secondary",mixed:"text.secondary"})[j]||"text.secondary";return e.jsxs(r.TableRow,{ref:l,"data-handler-id":h,sx:{opacity:f?.4:1,bgcolor:n?"background.paper":"grey.50",transition:"all 0.2s ease","&:hover":{bgcolor:n?"grey.50":"grey.100"},cursor:"move",height:56,borderBottom:"1px solid divider"},children:[e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[e.jsx(r.Box,{sx:{color:"text.secondary",cursor:"grab",opacity:.6,transition:"opacity 0.2s ease","&:hover":{opacity:1},"&:active":{cursor:"grabbing"}},children:e.jsx(k.DragIndicator,{sx:{fontSize:20}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:400,fontSize:"0.875rem",color:n?"text.primary":"text.secondary"},children:Ge(t.name)})]})}),e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsx(r.Chip,{label:t.type.toUpperCase(),size:"small",sx:{height:22,fontSize:"0.6875rem",fontWeight:600,bgcolor:`${v(t.type)}15`,color:v(t.type),border:`1px solid ${v(t.type)}30`,"& .MuiChip-label":{px:1}}})}),e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.TextField,{type:"text",value:u,onChange:j=>y(j.target.value),onBlur:T,onKeyDown:w,placeholder:"150",size:"small",sx:{width:80,"& .MuiOutlinedInput-root":{height:32,fontSize:"0.8125rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:.5,px:1.25,color:"text.primary"}}}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:"px"})]})}),e.jsx(r.TableCell,{sx:{py:1.5,px:2.5,borderBottom:"none"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[e.jsx(r.IconButton,{onClick:()=>s(t.name,!n),title:n?"Hide column":"Show column",size:"small",sx:{p:.75,color:n?"primary.main":"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:n?"primary.dark":"primary.main"}},children:n?e.jsx(k.Visibility,{sx:{fontSize:20}}):e.jsx(k.VisibilityOff,{sx:{fontSize:20}})}),e.jsx(r.Chip,{label:n?"Visible":"Hidden",size:"small",sx:{height:22,fontSize:"0.6875rem",fontWeight:500,bgcolor:n?"#e6f4ea":"grey.100",color:n?"success.main":"text.secondary","& .MuiChip-label":{px:1}}})]})})]})}function Xd({schema:t,columnVisibility:o,columnOrder:n,columnWidths:i={},views:s=[],activeViewId:c="",onUpdateColumnVisibility:d,onUpdateColumnOrder:l,onUpdateColumnWidth:u,onResetLayout:m,onSaveToCurrentView:h,onSaveToAllViews:b,onSelectView:f,onClose:g}){const[T,y]=p.useState(!1),[w,v]=p.useState(n),[j,S]=p.useState(i),[I,a]=p.useState("all"),[A,B]=p.useState(null);p.useEffect(()=>{v(n)},[n]),p.useEffect(()=>{S(i)},[i]);const $=(re,O)=>{S(F=>({...F,[re]:O}))},Y=(re,O)=>{const F=[...w],[G]=F.splice(re,1);F.splice(O,0,G),v(F),l(F)},Q=()=>{m(),y(!1)},x=w.map(re=>t.find(O=>O.name===re)).filter(re=>re!==void 0).filter(re=>{const O=o[re.name]??!0;return I==="active"?O:I==="hidden"?!O:!0}),N=Object.values(o).filter(re=>re).length,W=t.length,H=s.find(re=>re.id===c),J=s.filter(re=>!re.isDeleted),ue=J.length>1,pe=p.useMemo(()=>{if(!H)return!1;const re=H.snapshot,O=JSON.stringify(o)!==JSON.stringify(re.columnVisibility),F=JSON.stringify(n)!==JSON.stringify(re.columnOrder),G=JSON.stringify(j)!==JSON.stringify(re.columnWidths);return O||F||G},[H,o,n,j]);return e.jsx(wt.DndProvider,{backend:Xo.HTML5Backend,children:e.jsx(r.Box,{onClick:g,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:re=>re.stopPropagation(),elevation:0,sx:{position:"relative",width:720,maxWidth:"calc(100vw - 120px)",maxHeight:"min(760px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{px:3,pt:2,pb:1.5,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between"},children:[e.jsxs(r.Box,{sx:{flex:1},children:[e.jsxs(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:["Manage columns",e.jsx(qt,{content:Jt.columns,isDev:process.env.NODE_ENV==="development"})]}),e.jsxs(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary",mt:.5},children:[N," of ",W," columns visible • Drag to reorder"]})]}),J.length>0&&f&&e.jsxs(r.Box,{sx:{ml:2},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",color:"text.secondary",mb:.75,display:"block",textTransform:"uppercase",fontWeight:600,letterSpacing:"0.1em"},children:"View:"}),e.jsx(r.Button,{onClick:re=>B(re.currentTarget),variant:"outlined",size:"small",endIcon:e.jsx(k.KeyboardArrowDown,{sx:{fontSize:18}}),sx:{minWidth:180,justifyContent:"space-between",textTransform:"none",fontSize:"0.875rem",fontWeight:400,color:"text.primary",borderColor:"grey.300",py:.75,px:1.5,"&:hover":{borderColor:"primary.main",bgcolor:"grey.50"}},children:e.jsx(r.Box,{component:"span",sx:{overflow:"hidden",textOverflow:"ellipsis"},children:(H==null?void 0:H.name)||"Select View"})}),e.jsx(r.Menu,{anchorEl:A,open:!!A,onClose:()=>B(null),PaperProps:{sx:{mt:.5,borderRadius:"8px",boxShadow:"0 2px 6px rgba(60, 64, 67, 0.15)"}},children:J.map(re=>e.jsx(r.MenuItem,{onClick:()=>{f(re.id),B(null)},selected:re.id===c,sx:{fontSize:"0.875rem",color:"text.primary",py:1,px:2,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:O=>E(O.palette.primary.main,.2)}}},children:re.name},re.id))})]}),e.jsx(r.IconButton,{onClick:g,size:"small",sx:{ml:2,p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.Tabs,{value:I,onChange:(re,O)=>a(O),sx:{minHeight:36,mt:.5,"& .MuiTabs-indicator":{bgcolor:"primary.main",height:3}},children:[e.jsx(r.Tab,{label:"All",value:"all",sx:{minHeight:36,py:.75,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary","&.Mui-selected":{color:"primary.main"}}}),e.jsx(r.Tab,{label:"Visible",value:"active",sx:{minHeight:36,py:.75,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary","&.Mui-selected":{color:"primary.main"}}}),e.jsx(r.Tab,{label:"Hidden",value:"hidden",sx:{minHeight:36,py:.75,fontSize:"0.875rem",fontWeight:500,textTransform:"none",color:"text.secondary","&.Mui-selected":{color:"primary.main"}}})]})]}),e.jsx(r.Box,{sx:{flex:1,overflow:"auto","&::-webkit-scrollbar":{width:8,height:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:e.jsxs(r.Table,{stickyHeader:!0,sx:{minWidth:650},children:[e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{children:[e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"grey.50",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Column name"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"grey.50",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Type"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"grey.50",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:["Width",e.jsx(r.Tooltip,{title:`Column width in pixels (min: ${Jo}px, max: ${Ko}px)`,arrow:!0,placement:"top",children:e.jsx(k.InfoOutlined,{sx:{fontSize:14,color:"text.secondary",cursor:"help"}})})]})}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"0.6875rem",color:"text.secondary",bgcolor:"grey.50",letterSpacing:"0.1em",py:1.5,px:2.5,borderBottom:"1px solid divider"},children:"Visibility"})]})}),e.jsx(r.TableBody,{children:x.length===0?e.jsx(r.TableRow,{children:e.jsx(r.TableCell,{colSpan:4,align:"center",sx:{py:6,borderBottom:"none"},children:e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary"},children:"No columns in this category"})})}):x.map((re,O)=>e.jsx(Kd,{column:re,index:O,isVisible:o[re.name]??!0,width:j[re.name]||150,onToggleVisibility:d,onWidthChange:$,moveColumn:Y},re.name))})]})}),e.jsxs(r.Box,{sx:{px:3,py:1.75,borderTop:"1px solid divider",display:"flex",justifyContent:"space-between",alignItems:"center",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:()=>y(!0),disabled:!pe,variant:"outlined",startIcon:e.jsx(k.Undo,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",borderColor:"grey.300",px:2.5,py:.875,minHeight:36,borderRadius:"4px","&:hover":{borderColor:"primary.main",bgcolor:"background.paper",color:"primary.main"},"&.Mui-disabled":{color:"grey.400",borderColor:"divider"}},children:"Reset to default"}),e.jsxs(r.Stack,{direction:"row",spacing:1.25,children:[h&&e.jsx(r.Button,{onClick:()=>{h(j),g()},disabled:!pe,variant:"contained",startIcon:e.jsx(k.Save,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"grey.400"}},children:"Save to current view"}),b&&ue&&e.jsx(r.Button,{onClick:()=>{b(j),g()},disabled:!pe||!ue,variant:"contained",startIcon:e.jsx(k.GridView,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"success.main",color:"background.paper",px:2.5,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"success.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"},"&.Mui-disabled":{bgcolor:"divider",color:"grey.400"}},children:"Save to all views"})]})]}),T&&e.jsx(r.Box,{onClick:()=>y(!1),sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1400},children:e.jsxs(r.Paper,{onClick:re=>re.stopPropagation(),elevation:0,sx:{width:400,maxWidth:"90vw",borderRadius:"12px",bgcolor:"background.paper",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"},children:[e.jsxs(r.Box,{sx:{px:3,py:2.5},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1rem",fontWeight:500,color:"text.primary",mb:1.5},children:"Reset column layout?"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary",lineHeight:1.5},children:"This will restore default visibility, order, and widths for all columns."})]}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:()=>y(!1),variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,borderRadius:"4px","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:Q,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"error.main",color:"background.paper",px:3,py:1,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)","&:hover":{bgcolor:"#b3190e",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Reset layout"})]})]})})]})})})}function Zd({schema:t,grouping:o,onApply:n,onClose:i}){var A;const[s,c]=p.useState(o||{enabled:!1,levels:[],collapsedGroups:[]}),[d,l]=p.useState(""),[u,m]=p.useState(null),h=p.useMemo(()=>Ks(t),[t]),b=p.useMemo(()=>h.filter(B=>!s.levels.some(($,Y)=>$.column===B.name&&Y!==u)),[h,s.levels,u]),f=Gt(),g=s.levels.length<f.grouping.maxLevels&&b.length>0,T=p.useCallback(()=>{!g||!d||(c({...s,levels:[...s.levels,{column:d}],enabled:!0}),l(""))},[g,d,s]),y=p.useCallback(B=>{const $=s.levels.filter((Y,Q)=>Q!==B);if($.length===0){n(null),i();return}c({...s,levels:$,enabled:$.length>0})},[s,n,i]),w=p.useCallback(B=>{m(B),l(s.levels[B].column)},[s.levels]),v=p.useCallback(()=>{if(u===null||!d)return;const B=[...s.levels];B[u]={column:d},c({...s,levels:B}),m(null),l("")},[u,d,s]),j=p.useCallback(()=>{m(null),l("")},[]),S=p.useCallback((B,$)=>{const Y=$==="up"?B-1:B+1;if(Y<0||Y>=s.levels.length)return;const Q=[...s.levels],[te]=Q.splice(B,1);Q.splice(Y,0,te),c({...s,levels:Q})},[s]),I=p.useCallback(()=>{n(null),i()},[n,i]),a=p.useCallback(()=>{s.levels.length===0?n(null):n({...s,enabled:!0,collapsedGroups:(o==null?void 0:o.collapsedGroups)||[]}),i()},[s,o,n,i]);return e.jsx(r.Box,{onClick:i,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:B=>B.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(560px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Group configuration"}),e.jsx(qt,{content:Jt.grouping,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:i,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:1,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:e.jsxs(r.Stack,{spacing:2.5,children:[u===null&&e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,display:"block",textTransform:"uppercase"},children:"Add group level"}),e.jsx(r.FormControl,{fullWidth:!0,size:"small",sx:{mb:1.5},children:e.jsxs(r.Select,{value:d,onChange:B=>l(B.target.value),disabled:!g,displayEmpty:!0,sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-disabled":{bgcolor:"grey.50"}},children:[e.jsx(r.MenuItem,{value:"",sx:{fontSize:"0.875rem",color:"text.secondary"},children:"Select a column..."}),b.map(B=>e.jsxs(r.MenuItem,{value:B.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:$=>E($.palette.primary.main,.2)}}},children:[Ge(B.name)," (",B.type.toUpperCase(),")"]},B.name))]})}),e.jsx(r.Button,{onClick:T,disabled:!g||!d,variant:"outlined",startIcon:e.jsx(k.Add,{sx:{fontSize:18}}),fullWidth:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",borderColor:"grey.300",py:1,transition:"all 0.2s ease","&:hover":{borderColor:"primary.main",bgcolor:"grey.50"},"&.Mui-disabled":{color:"grey.400",borderColor:"divider"}},children:"Add group level"}),s.levels.length>=f.grouping.maxLevels&&e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",textAlign:"center",mt:1.5,fontSize:"0.75rem",color:"text.secondary"},children:"Maximum group levels (3) reached"}),h.length===0&&e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{textAlign:"center",py:2,fontSize:"0.875rem",color:"text.secondary"},children:"No groupable columns available. Only STRING and BOOLEAN columns can be grouped."})]}),u!==null&&e.jsxs(r.Alert,{severity:"warning",sx:{borderRadius:"8px",border:"1px solid #fdd663",bgcolor:"#fef7e0","& .MuiAlert-icon":{color:"#ea8600"}},children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:500,mb:1.5,fontSize:"0.875rem",color:"text.primary"},children:["Edit Group Level ",u+1]}),e.jsx(r.FormControl,{fullWidth:!0,size:"small",sx:{mb:1.5},children:e.jsxs(r.Select,{value:d,onChange:B=>l(B.target.value),sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:[e.jsx(r.MenuItem,{value:"",sx:{fontSize:"0.875rem"},children:"Select a column..."}),e.jsxs(r.MenuItem,{value:s.levels[u].column,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:"primary.lighter"}},children:[s.levels[u].column," (",(A=t.find(B=>B.name===s.levels[u].column))==null?void 0:A.type.toUpperCase(),")"]}),b.filter(B=>B.name!==s.levels[u].column).map(B=>e.jsxs(r.MenuItem,{value:B.name,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:"primary.lighter"}},children:[Ge(B.name)," (",B.type.toUpperCase(),")"]},B.name))]})}),e.jsxs(r.Stack,{direction:"row",spacing:1.5,children:[e.jsx(r.Button,{onClick:v,disabled:!d,variant:"contained",fullWidth:!0,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"#ea8600",color:"background.paper",py:.875,boxShadow:"none","&:hover":{bgcolor:"#c96e00",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)"}},children:"Save"}),e.jsx(r.Button,{onClick:j,variant:"outlined",fullWidth:!0,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",borderColor:"grey.300",py:.875,"&:hover":{borderColor:"grey.400",bgcolor:"grey.50"}},children:"Cancel"})]})]}),s.levels.length>0&&u===null&&e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1.5},children:[e.jsx(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",textTransform:"uppercase"},children:"Active group levels"}),e.jsx(r.Button,{onClick:I,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"error.main",p:0,minWidth:"auto","&:hover":{bgcolor:"transparent",color:"#b3190e",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Stack,{spacing:1.5,children:s.levels.map((B,$)=>{const Y=t.find(Q=>Q.name===B.column);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,p:2,borderRadius:"8px",bgcolor:"background.paper",border:"1px solid divider",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.50",borderColor:"grey.300",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.1)"}},children:[e.jsx(r.Chip,{label:`L${$+1}`,size:"small",sx:{width:40,height:28,fontWeight:600,fontSize:"0.75rem",bgcolor:"primary.main",color:"background.paper",boxShadow:"0 1px 2px 0 rgba(25, 103, 210, 0.3)"}}),e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:B.column}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:Y==null?void 0:Y.type.toUpperCase()})]}),e.jsxs(r.Stack,{direction:"row",spacing:.5,children:[e.jsx(r.IconButton,{size:"small",onClick:()=>S($,"up"),disabled:$===0,sx:{color:"text.secondary","&:hover":{bgcolor:"grey.100"},"&.Mui-disabled":{color:"divider"}},children:e.jsx(k.KeyboardArrowUp,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>S($,"down"),disabled:$===s.levels.length-1,sx:{color:"text.secondary","&:hover":{bgcolor:"grey.100"},"&.Mui-disabled":{color:"divider"}},children:e.jsx(k.KeyboardArrowDown,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>w($),sx:{color:"text.secondary","&:hover":{bgcolor:"grey.100",color:"primary.main"}},children:e.jsx(k.Edit,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>y($),sx:{color:"text.secondary","&:hover":{bgcolor:"rgba(217, 48, 37, 0.08)",color:"error.main"}},children:e.jsx(k.Delete,{sx:{fontSize:18}})})]})]},$)})})]})]})}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:i,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:a,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Apply grouping"})]})]})})}const Qd={filters:k.FilterList,sorting:k.UnfoldMore,visibility:k.Visibility,order:k.ViewColumn,widths:k.Straighten,grouping:k.Layers};function eu({changes:t,onClose:o}){const n=i=>({filters:"primary",sorting:"secondary",visibility:"success",order:"warning",widths:"info",grouping:"error"})[i]||"default";return e.jsxs(r.Dialog,{open:!0,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:"12px",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:["View Changes Summary",e.jsx(r.IconButton,{onClick:o,size:"small",sx:{color:"text.secondary"},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{dividers:!0,children:t.length===0?e.jsx(r.Box,{sx:{textAlign:"center",py:4},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No changes detected"})}):e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{mb:2},children:"The following modifications have been made to this view:"}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:t.map((i,s)=>{const c=Qd[i.category];return e.jsxs(r.Paper,{elevation:0,sx:{display:"flex",gap:1.5,p:1.5,border:1,borderColor:"divider",borderRadius:1},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,borderRadius:1,bgcolor:`${n(i.category)}.lighter`,color:`${n(i.category)}.main`,flexShrink:0},children:e.jsx(c,{sx:{fontSize:16}})}),e.jsxs(r.Box,{sx:{flex:1,minWidth:0},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500},children:i.label}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:i.description})]})]},s)})})]})}),e.jsx(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:e.jsx(r.Button,{onClick:o,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"common.white",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Close"})})]})}function tu({viewName:t,isDefaultView:o,changes:n=[],onSaveToCurrentView:i,onSaveAsNewView:s,onCancel:c}){const[d,l]=p.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{width:"100%",flexShrink:0,bgcolor:"primary.lighter",borderBottom:u=>`1px solid ${E(u.palette.primary.main,.3)}`,zIndex:10},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:1.25},children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:400,fontSize:"0.875rem",color:"text.primary"},children:['Unsaved changes to "',t,'"']}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.Button,{onClick:c,variant:"text",size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",color:"text.secondary",bgcolor:"transparent",minHeight:32,"&:hover":{bgcolor:"rgba(60, 64, 67, 0.08)",color:"text.primary"}},children:"Discard"}),e.jsx(r.Button,{onClick:s,variant:"contained",size:"small",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2.5,py:.625,borderRadius:"18px",minHeight:32,boxShadow:"none","&:hover":{boxShadow:"0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px rgba(60, 64, 67, 0.15)"}},children:"Save as new view"})]})]})}),d&&e.jsx(eu,{changes:n,onClose:()=>l(!1)})]})}function ru({onExportAnyway:t,onSaveAndExport:o,onCancel:n}){return e.jsx(r.Box,{sx:{mb:2,mx:3,mt:2},children:e.jsxs(r.Alert,{severity:"warning",icon:e.jsx(k.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:n,sx:{color:"warning.main"},children:e.jsx(k.Close,{sx:{fontSize:20}})}),sx:{alignItems:"flex-start"},children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:600,mb:.5},children:"You are exporting with unsaved view changes"}),e.jsx(r.Typography,{variant:"body2",sx:{mb:1.5},children:"Your current view has unsaved changes. Choose how to proceed:"}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Button,{onClick:o,variant:"contained",color:"primary",startIcon:e.jsx(k.Save,{sx:{fontSize:14}}),size:"small",children:"Save View & Export"}),e.jsx(r.Button,{onClick:t,variant:"contained",color:"warning",startIcon:e.jsx(k.Download,{sx:{fontSize:14}}),size:"small",children:"Export Anyway"})]})]})})}const li=[{key:"1h",label:"Last 1 Hour",ms:3600*1e3},{key:"24h",label:"Last 24 Hours",ms:1440*60*1e3},{key:"7d",label:"Last 7 Days",ms:10080*60*1e3},{key:"30d",label:"Last 30 Days",ms:720*60*60*1e3},{key:"all",label:"All Time",ms:null}];function ou(t,o){if(o===null)return t.length;const n=Date.now()-o;return t.filter(i=>new Date(i.timestamp).getTime()>=n).length}function nu(t,o){if(o===null)return[];const n=Date.now()-o;return t.filter(i=>new Date(i.timestamp).getTime()<n)}function iu({auditHistory:t,onClose:o,onClearAuditHistory:n}){var T,y,w,v;const s=Tt().palette,[c,d]=p.useState("1h"),[l,u]=p.useState(!1),m=[...t].sort((j,S)=>new Date(S.timestamp).getTime()-new Date(j.timestamp).getTime()),h=li.find(j=>j.key===c),b=ou(t,h.ms),f=()=>u(!0),g=()=>{n&&(n(nu(t,h.ms)),u(!1))};return e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{onClick:o,sx:{position:"fixed",inset:0,bgcolor:E(((T=s.common)==null?void 0:T.black)??"#000",.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:j=>j.stopPropagation(),elevation:0,sx:{width:520,maxWidth:"calc(100vw - 48px)",maxHeight:"min(700px, calc(100vh - 80px))",display:"flex",flexDirection:"column",borderRadius:"16px",bgcolor:"background.paper",overflow:"hidden",boxShadow:`0 8px 32px ${E(((y=s.common)==null?void 0:y.black)??"#000",.14)}, 0 2px 8px ${E(((w=s.common)==null?void 0:w.black)??"#000",.08)}`,animation:"slideIn 0.2s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.96) translateY(-8px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{px:2.5,py:1.75,display:"flex",alignItems:"center",justifyContent:"space-between",gap:1.5,flexShrink:0,borderBottom:"1px solid",borderColor:"divider"},children:[e.jsxs(r.Box,{sx:{minWidth:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",fontWeight:600,color:"text.primary"},children:"Audit History"}),e.jsx(qt,{content:Jt.auditHistory,isDev:process.env.NODE_ENV==="development"})]}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.125},children:[m.length," event",m.length!==1?"s":""," recorded"]})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,flexShrink:0},children:[n&&t.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Select,{value:c,onChange:j=>d(j.target.value),size:"small",variant:"outlined",sx:{fontSize:"0.75rem",height:30,minWidth:120,"& .MuiSelect-select":{py:.375,px:1,fontSize:"0.75rem"},"& .MuiOutlinedInput-notchedOutline":{borderColor:"divider"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:E(s.text.primary,.3)}},children:li.map(j=>e.jsx(r.MenuItem,{value:j.key,sx:{fontSize:"0.8125rem"},children:j.label},j.key))}),e.jsx(r.Button,{size:"small",variant:"outlined",color:"error",startIcon:e.jsx(k.DeleteSweepOutlined,{sx:{fontSize:14}}),onClick:f,sx:{textTransform:"none",fontSize:"0.75rem",fontWeight:500,borderRadius:"7px",px:1.25,height:30,whiteSpace:"nowrap",borderColor:E(s.error.main,.5),"&:hover":{bgcolor:E(s.error.main,.06),borderColor:"error.main"}},children:"Clear Logs"})]}),e.jsx(r.IconButton,{onClick:o,size:"small",sx:{color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:17}})})]})]}),e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",px:2,py:1.5,bgcolor:E(s.text.primary,.012),"&::-webkit-scrollbar":{width:5},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:E(s.text.primary,.14),borderRadius:3}},children:m.length===0?e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8,gap:1,textAlign:"center"},children:[e.jsx(k.AccessTime,{sx:{fontSize:44,color:"text.disabled",opacity:.5}}),e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",color:"text.secondary",fontWeight:500},children:"No audit events yet"}),e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.disabled"},children:"Changes to this report will appear here"})]}):e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:m.map(j=>{const S=ba(j.feature),{summary:I,detail:a}=fa(j);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:1.25,px:1.5,py:1.25,borderRadius:"10px",bgcolor:"background.paper",border:"1px solid",borderColor:"divider",transition:"border-color 0.15s","&:hover":{borderColor:E(s.text.primary,.18)}},children:[e.jsx(r.Chip,{label:ya(j.feature),size:"small",sx:{height:20,fontSize:"0.5625rem",fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",bgcolor:E(S,.1),color:S,border:`1px solid ${E(S,.22)}`,flexShrink:0,mt:.125,"& .MuiChip-label":{px:.75}}}),e.jsxs(r.Box,{sx:{flex:1,minWidth:0},children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",fontWeight:500,color:"text.primary",lineHeight:1.45,wordBreak:"break-word"},children:I}),a&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.25,lineHeight:1.4},children:a}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,mt:.5,flexWrap:"wrap"},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.375},children:[e.jsx(k.AccessTime,{sx:{fontSize:11,color:"text.disabled"}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:va(j.timestamp)})]}),j.user&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.375},children:[e.jsx(k.Person,{sx:{fontSize:11,color:"text.disabled"}}),e.jsx(r.Typography,{sx:{fontSize:"0.6875rem",color:"text.disabled"},children:j.user})]})]})]})]},j.id)})})})]})}),e.jsxs(r.Dialog,{open:l,onClose:()=>u(!1),maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"14px",boxShadow:`0 8px 32px ${E(((v=s.common)==null?void 0:v.black)??"#000",.14)}`}},children:[e.jsxs(r.DialogContent,{sx:{pt:3,pb:2,px:3},children:[e.jsx(r.Box,{sx:{width:44,height:44,borderRadius:"12px",bgcolor:E(s.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(k.WarningAmberOutlined,{sx:{fontSize:22,color:"error.main"}})}),e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",fontWeight:600,color:"text.primary",mb:1},children:"Clear Audit Logs"}),e.jsxs(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.65},children:["You are about to permanently remove"," ",e.jsxs(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:[b," audit record",b!==1?"s":""]})," ",h.key==="all"?"from all time":`from the ${h.label.toLowerCase()}`,". This action cannot be undone."]})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogActions,{sx:{px:2.5,py:1.5,gap:1},children:[e.jsx(r.Button,{onClick:()=>u(!1),variant:"text",sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsxs(r.Button,{onClick:g,variant:"contained",color:"error",disableElevation:!0,startIcon:e.jsx(k.DeleteSweepOutlined,{sx:{fontSize:14}}),sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,borderRadius:"7px",px:2},children:["Clear ",b," Record",b!==1?"s":""]})]})]})]})}function su({onSave:t,onClose:o}){const[n,i]=p.useState(""),[s,c]=p.useState(""),[d,l]=p.useState(""),[u,m]=p.useState([]),[h,b]=p.useState(""),[f,g]=p.useState(""),T=a=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a),y=()=>{const a=d.trim();if(a){if(!T(a)){g("Please enter a valid email address");return}if(u.includes(a)){g("This email is already added");return}m([...u,a]),l(""),g("")}},w=a=>{m(u.filter(A=>A!==a))},v=a=>{a.key==="Enter"&&(a.preventDefault(),y())},j=()=>{if(!n.trim()){b("Preset name is required");return}t(n.trim(),s.trim(),u.length>0?u:void 0)},S=a=>{i(a),h&&b("")},I=a=>{l(a),f&&g("")};return e.jsx(r.Box,{onClick:o,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:a=>a.stopPropagation(),elevation:0,sx:{position:"relative",width:540,maxWidth:"calc(100vw - 120px)",maxHeight:"min(480px, calc(100vh - 280px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"background.paper",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Create shareable preset"}),e.jsx(r.IconButton,{onClick:o,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:2.5,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[e.jsx(r.Alert,{severity:"info",icon:e.jsx(k.Info,{sx:{fontSize:20}}),sx:{borderRadius:"8px",border:a=>`1px solid ${E(a.palette.primary.main,.3)}`,bgcolor:"primary.lighter","& .MuiAlert-icon":{color:"primary.main"},"& .MuiAlert-message":{fontSize:"0.8125rem",color:"text.primary",lineHeight:1.5}},children:"This preset will capture filters, sorting, grouping, column configuration, and the active view. The actual data is not saved or shared."}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary",lineHeight:1.6},children:"Save the current report configuration and generate a shareable link that others can use to view the same filters, sorting, and column layout."}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Preset name *"}),e.jsx(r.TextField,{required:!0,value:n,onChange:a=>S(a.target.value),placeholder:"e.g., Q4 Active Users Report",error:!!h,helperText:h,autoFocus:!0,fullWidth:!0,size:"small",sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-error fieldset":{borderColor:"error.main"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",color:"error.main",mt:.75}}})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Description (optional)"}),e.jsx(r.TextField,{value:s,onChange:a=>c(a.target.value),placeholder:"Briefly describe what this preset shows...",multiline:!0,rows:3,fullWidth:!0,size:"small",sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary",lineHeight:1.6}}})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1,display:"block",textTransform:"uppercase"},children:"Share with (optional)"}),e.jsxs(r.Box,{sx:{display:"flex",gap:1,alignItems:"flex-start"},children:[e.jsx(r.TextField,{value:d,onChange:a=>I(a.target.value),onKeyPress:v,placeholder:"Enter email address",error:!!f,helperText:f,fullWidth:!0,size:"small",InputProps:{startAdornment:e.jsx(k.Email,{sx:{fontSize:18,color:"text.secondary",mr:1}})},sx:{"& .MuiOutlinedInput-root":{fontSize:"0.875rem",borderRadius:"4px",bgcolor:"background.paper","& fieldset":{borderColor:"grey.300"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"},"&.Mui-error fieldset":{borderColor:"error.main"}},"& .MuiInputBase-input":{py:1.25,color:"text.primary"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",color:"error.main",mt:.75}}}),e.jsx(r.Button,{onClick:y,variant:"outlined",startIcon:e.jsx(k.Add,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",borderColor:"grey.300",px:2,py:1.25,minHeight:40,borderRadius:"4px",flexShrink:0,"&:hover":{borderColor:"primary.main",bgcolor:"grey.50"}},children:"Add"})]}),u.length>0&&e.jsx(r.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1,mt:1.5},children:u.map(a=>e.jsx(r.Chip,{label:a,onDelete:()=>w(a),deleteIcon:e.jsx(k.Delete,{sx:{fontSize:16}}),sx:{bgcolor:"primary.lighter",color:"primary.main",fontSize:"0.8125rem",height:28,"& .MuiChip-deleteIcon":{color:"primary.main","&:hover":{color:"primary.dark"}}}},a))}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary",mt:1,display:"block",lineHeight:1.5},children:u.length>0?`An email with the shareable link will be sent to ${u.length} recipient${u.length>1?"s":""}`:"Add email addresses to send the shareable link automatically"})]})]})}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"grey.50"},children:[e.jsx(r.Button,{onClick:o,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:3,py:1,minHeight:36,borderRadius:"4px",transition:"all 0.2s ease","&:hover":{bgcolor:"divider",color:"text.primary"}},children:"Cancel"}),e.jsx(r.Button,{onClick:j,variant:"contained",startIcon:e.jsx(k.Share,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"background.paper",px:3,py:1,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Create & share"})]})]})})}function au({presetName:t,onClear:o}){return e.jsx(r.Chip,{icon:e.jsx(k.Link,{sx:{fontSize:14}}),label:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:["Preset:"," ",e.jsx(r.Box,{component:"span",sx:{fontWeight:600},children:t})]}),onDelete:o,deleteIcon:e.jsx(r.IconButton,{size:"small",title:"Exit preset view",sx:{p:0},children:e.jsx(k.Close,{sx:{fontSize:14}})}),sx:{bgcolor:n=>E(n.palette.primary.main,.12),borderColor:"primary.light",border:1,fontSize:"body2.fontSize",fontWeight:500,"& .MuiChip-deleteIcon":{color:"primary.main","&:hover":{color:"primary.main"}}}})}function lu({presets:t,reportId:o,onOpenPreset:n,onDeletePreset:i,onClose:s}){const[c,d]=p.useState(null),l=u=>new Date(u).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"});return e.jsx(r.Box,{onClick:s,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:u=>u.stopPropagation(),elevation:0,sx:{position:"relative",width:680,maxWidth:"calc(100vw - 120px)",maxHeight:"min(720px, calc(100vh - 200px))",display:"flex",flexDirection:"column",borderRadius:"12px",bgcolor:"common.white",outline:"none",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",animation:"slideIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.95) translateY(-12px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:"Manage Presets"}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",mt:.5,display:"block"},children:[t.length," saved ",t.length===1?"preset":"presets"]})]}),e.jsx(r.IconButton,{onClick:s,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"#f1f3f4",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{flex:1,overflow:"auto",px:3,py:2,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"divider",borderRadius:4,"&:hover":{bgcolor:"#bdc1c6"}}},children:t.length===0?e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8},children:[e.jsx(k.Share,{sx:{fontSize:48,color:"divider",mb:2}}),e.jsx(r.Typography,{variant:"body1",sx:{fontSize:"0.875rem",color:"text.secondary",textAlign:"center"},children:"No presets created yet"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"#80868b",textAlign:"center",mt:.5},children:"Create a preset to share report configurations"})]}):e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:t.map(u=>e.jsxs(r.Paper,{elevation:0,sx:{p:2.5,border:"1px solid divider",borderRadius:"8px",bgcolor:"common.white",transition:"all 0.2s ease","&:hover":{borderColor:"divider",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.1), 0 1px 3px 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",mb:1.5},children:e.jsxs(r.Box,{sx:{flex:1,minWidth:0},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"0.9375rem",fontWeight:500,color:"text.primary",mb:.5},children:u.name}),u.description&&e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.5},children:u.description})]})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5,mb:2},children:[e.jsx(r.Chip,{label:`Created ${l(u.createdAt)}`,size:"small",sx:{height:22,fontSize:"0.75rem",bgcolor:"#f1f3f4",color:"text.secondary","& .MuiChip-label":{px:1}}}),e.jsx(r.Chip,{label:`By ${u.createdBy}`,size:"small",sx:{height:22,fontSize:"0.75rem",bgcolor:"#f1f3f4",color:"text.secondary","& .MuiChip-label":{px:1}}})]}),e.jsx(r.Divider,{sx:{my:1.5,borderColor:"#f1f3f4"}}),e.jsx(r.Box,{sx:{display:"flex",gap:1},children:e.jsx(r.Button,{onClick:()=>i(u.id,u.name),variant:"outlined",size:"small",startIcon:e.jsx(k.Delete,{sx:{fontSize:16}}),sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"error.main",borderColor:"divider",px:1.5,py:.75,borderRadius:"4px","&:hover":{borderColor:"error.main",bgcolor:"rgba(217, 48, 37, 0.04)"}},children:"Delete"})})]},u.id))})}),e.jsx(r.Box,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end",display:"flex"},children:e.jsx(r.Button,{onClick:s,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"common.white",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Close"})})]})})}const Ui={maxFileSizeBytes:2*1024*1024,maxFileSizeHardBytes:3*1024*1024,maxRows:1e4,maxRowsHard:5e4,maxImageColumns:5},cu=[/^https?:\/\/.*\.(jpg|jpeg|png|gif|webp|svg|avif|bmp)/i,/^data:image\//i,/^\/.*\.(jpg|jpeg|png|gif|webp|svg)/i],du=[/image/i,/photo/i,/avatar/i,/thumbnail/i,/picture/i,/logo/i,/icon/i,/banner/i];function uu(t,o){const n=[];for(const i of t){if(i.type!=="string")continue;const s=du.some(l=>l.test(i.name));let c=!1;const d=o.slice(0,10).map(l=>l[i.name]).filter(l=>typeof l=="string"&&l.length>0);d.length>0&&(c=d.filter(u=>cu.some(m=>m.test(u))).length/d.length>.6),(s||c)&&n.push(i.name)}return n}function an(t,o){if(t.length===0||o.length===0)return 0;const n=t.slice(0,Math.min(50,t.length)),s=o.map(d=>{const l=n.map(m=>String(m[d]??"")).filter(m=>m.length>0);if(l.length===0)return 5;const u=l.reduce((m,h)=>m+h.length,0);return Math.ceil(u/l.length)+1}).reduce((d,l)=>d+l,0)+1;return o.reduce((d,l)=>d+l.length+1,0)+s*t.length}function pu(t,o){const n=an(t,o);return Math.ceil(n*3.5)}function xu(t,o){const n=an(t,o);return Math.ceil(n*.7)}function mu(t,o,n){switch(t){case"csv":return an(o,n);case"excel":return xu(o,n);case"json":return pu(o,n)}}function ci(t,o){return Math.ceil(t/o)}function fu(t,o,n,i,s=Ui){const c=[],d=mu(t,o,n),l=o.length;if(l>s.maxRowsHard){const h=ci(l,s.maxRows);c.push({type:"row_count",severity:"error",message:`Export blocked: ${l.toLocaleString()} rows exceeds the maximum of ${s.maxRowsHard.toLocaleString()}`,detail:`Consider using filters to reduce the dataset before exporting, or split into ${h} smaller exports of ~${s.maxRows.toLocaleString()} rows each.`,suggestedBatches:h,value:l,limit:s.maxRowsHard})}else if(l>s.maxRows){const h=ci(l,s.maxRows);c.push({type:"row_count",severity:"warning",message:`Large export: ${l.toLocaleString()} rows`,detail:`This is a large export that may take a moment to complete. For faster results, consider splitting into ${h} smaller export${h>1?"s":""} of ~${s.maxRows.toLocaleString()} rows each.`,suggestedBatches:h,value:l,limit:s.maxRows})}if(d>s.maxFileSizeHardBytes?c.push({type:"file_size",severity:"error",message:`File size blocked: estimated ${Ur(d)} exceeds the ${Ur(s.maxFileSizeHardBytes)} limit`,detail:"Reduce the number of rows or columns and try again. Applying filters before exporting is the most effective way to reduce file size.",value:d,limit:s.maxFileSizeHardBytes}):d>s.maxFileSizeBytes&&c.push({type:"file_size",severity:"warning",message:`Large file: estimated ${Ur(d)}`,detail:`This exceeds the recommended ${Ur(s.maxFileSizeBytes)} size. The download will still proceed but may be slow on some connections.`,value:d,limit:s.maxFileSizeBytes}),t!=="excel"){const h=uu(i.filter(b=>n.includes(b.name)),o);if(h.length>0){const b=h.length>s.maxImageColumns;c.push({type:"image_columns",severity:b?"error":"warning",message:`Image column${h.length>1?"s":""} detected: ${h.map(f=>`"${f.replace(/_/g," ")}"`).join(", ")}`,detail:b?`Exporting ${h.length} image columns may produce a very large file. Consider hiding these columns before exporting.`:"Image URL columns are included in the export as plain text links — not embedded images.",value:h.length,limit:s.maxImageColumns})}}const u=c.some(h=>h.severity==="error"),m=c.some(h=>h.severity==="warning");return{violations:c,hasBlockingViolation:u,hasWarning:m,estimatedBytes:d}}function Ur(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function hu({violation:t}){const n=Tt().palette,i=t.severity==="error",s=i?n.error.main:n.warning.main,c=E(i?n.error.main:n.warning.main,.06),d=i?E(n.error.main,.25):E(n.warning.main,.3),l=i?k.ErrorOutline:k.WarningAmberOutlined;return e.jsxs(r.Box,{sx:{display:"flex",gap:1.25,p:1.5,borderRadius:"8px",bgcolor:c,border:"1px solid",borderColor:d},children:[e.jsx(l,{sx:{fontSize:17,color:s,flexShrink:0,mt:.125}}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",fontWeight:600,color:i?"error.main":"warning.dark",lineHeight:1.4},children:t.message}),t.detail&&e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",mt:.375,lineHeight:1.5},children:t.detail}),t.suggestedBatches&&t.suggestedBatches>1&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,mt:.75},children:[e.jsx(k.SplitscreenOutlined,{sx:{fontSize:14,color:"text.secondary"}}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary",fontWeight:500},children:["Suggestion: split into ",t.suggestedBatches," exports"]})]})]})]})}function gu({totalRows:t,visibleRows:o,hasGrouping:n,visibleColumnsCount:i,totalColumnsCount:s,schema:c,sampleRows:d=[],allRows:l=[],processedRows:u=[],onExport:m,onClose:h}){var N,W,H;const f=Tt().palette,g=Gt(),[T,y]=p.useState(g.export.allowedFormats[0]||"csv"),[w,v]=p.useState("visible"),[j,S]=p.useState("visible"),I=w==="visible"?o:t,a=j==="visible"?i:s,A=p.useMemo(()=>w==="visible"?u.length>0?u:new Array(o):l.length>0?l:new Array(t),[w,o,t,u,l]),B=p.useMemo(()=>j==="all"?c.map(J=>J.name):c.map(J=>J.name).slice(0,i),[j,c,i]),$=p.useMemo(()=>fu(T,A,B,c,Ui),[T,A,B,c]),Y=()=>{$.hasBlockingViolation||(m({format:T,scope:w,columnScope:j}),h())},Q={csv:"CSV",excel:"Excel (.xlsx)",json:"JSON"},te={alignItems:"flex-start",px:1.5,py:.875,borderRadius:"8px",mx:0,transition:"background-color 0.15s","&:hover":{bgcolor:"action.hover"}},x={color:"text.secondary","&.Mui-checked":{color:"primary.main"},pt:.125};return e.jsx(r.Box,{onClick:h,sx:{position:"fixed",inset:0,bgcolor:E(((N=f.common)==null?void 0:N.black)??"#000",.4),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.2s ease","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:J=>J.stopPropagation(),elevation:0,sx:{width:480,maxWidth:"calc(100vw - 48px)",maxHeight:"min(680px, calc(100vh - 80px))",display:"flex",flexDirection:"column",borderRadius:"14px",bgcolor:"background.paper",overflow:"hidden",boxShadow:`0 8px 32px ${E(((W=f.common)==null?void 0:W.black)??"#000",.14)}, 0 2px 8px ${E(((H=f.common)==null?void 0:H.black)??"#000",.08)}`,animation:"slideIn 0.2s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes slideIn":{from:{opacity:0,transform:"scale(0.96) translateY(-8px)"},to:{opacity:1,transform:"scale(1) translateY(0)"}}},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{sx:{fontSize:"1rem",fontWeight:600,color:"text.primary"},children:"Export Report"}),e.jsx(qt,{content:Jt.export,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:h,size:"small",sx:{color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(k.Close,{sx:{fontSize:18}})})]}),e.jsxs(r.Box,{sx:{flex:1,overflowY:"auto",px:3,py:2.5,display:"flex",flexDirection:"column",gap:2.5,"&::-webkit-scrollbar":{width:6},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:E(f.text.primary,.15),borderRadius:3}},children:[$.violations.length>0&&e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:$.violations.map((J,ue)=>e.jsx(hu,{violation:J},ue))}),e.jsxs(r.FormControl,{component:"fieldset",children:[e.jsx(r.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",letterSpacing:"0.08em",mb:1,textTransform:"uppercase"},children:"Format"}),e.jsxs(r.RadioGroup,{value:T,onChange:J=>y(J.target.value),children:[g.export.allowedFormats.includes("csv")&&e.jsx(r.FormControlLabel,{value:"csv",control:e.jsx(r.Radio,{size:"small",sx:x}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"CSV"}),e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:"Comma-separated values, compatible with Excel"})]}),sx:{...te,mb:.5}}),g.export.allowedFormats.includes("excel")&&e.jsx(r.FormControlLabel,{value:"excel",control:e.jsx(r.Radio,{size:"small",sx:x}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Excel (.xlsx)"}),e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:"Native Excel format with formatting support"})]}),sx:{...te,mb:.5}}),g.export.allowedFormats.includes("json")&&e.jsx(r.FormControlLabel,{value:"json",control:e.jsx(r.Radio,{size:"small",sx:x}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"JSON"}),e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:"Structured data with metadata and filters"})]}),sx:te})]})]}),e.jsxs(r.FormControl,{component:"fieldset",children:[e.jsx(r.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",letterSpacing:"0.08em",mb:1,textTransform:"uppercase"},children:"Rows"}),e.jsxs(r.RadioGroup,{value:w,onChange:J=>v(J.target.value),children:[e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small",sx:x}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Visible rows"}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export ",o.toLocaleString()," rows (filtered and searched)"]})]}),sx:{...te,mb:.5}}),e.jsx(r.FormControlLabel,{value:"all",control:e.jsx(r.Radio,{size:"small",sx:x}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"All rows"}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export ",t.toLocaleString()," rows (complete original dataset)"]})]}),sx:te})]})]}),e.jsxs(r.FormControl,{component:"fieldset",children:[e.jsx(r.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:700,color:"text.secondary",letterSpacing:"0.08em",mb:1,textTransform:"uppercase"},children:"Columns"}),e.jsxs(r.RadioGroup,{value:j,onChange:J=>S(J.target.value),children:[e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small",sx:x}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Visible columns only"}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export ",i," visible column",i!==1?"s":""]})]}),sx:{...te,mb:.5}}),e.jsx(r.FormControlLabel,{value:"all",control:e.jsx(r.Radio,{size:"small",sx:x}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"All columns"}),e.jsxs(r.Typography,{sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export all ",s," columns (including hidden)"]})]}),sx:te})]})]}),e.jsxs(r.Box,{children:[e.jsx(r.Divider,{sx:{mb:2}}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:[{label:"Format",value:Q[T]},{label:"Rows to export",value:I.toLocaleString()},{label:"Columns to export",value:String(a)},{label:"Estimated file size",value:Ur($.estimatedBytes),highlight:$.hasBlockingViolation?"error.main":$.hasWarning?"warning.main":void 0}].map(({label:J,value:ue,highlight:pe})=>e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary"},children:J}),e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"0.8125rem",color:pe??"text.primary"},children:ue})]},J))})]})]}),e.jsxs(r.Box,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:E(f.text.primary,.015)},children:[$.hasBlockingViolation&&e.jsxs(r.Box,{sx:{flex:1,display:"flex",alignItems:"center",gap:.75},children:[e.jsx(k.ErrorOutline,{sx:{fontSize:15,color:"error.main"}}),e.jsx(r.Typography,{sx:{fontSize:"0.75rem",color:"error.main",fontWeight:500},children:"Reduce rows or columns to enable download"})]}),e.jsx(r.Button,{onClick:h,variant:"text",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",px:2.5,borderRadius:"8px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsxs(r.Button,{onClick:Y,disabled:$.hasBlockingViolation,variant:"contained",disableElevation:!0,startIcon:e.jsx(k.Download,{sx:{fontSize:16}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2.5,borderRadius:"8px"},children:["Download ",Q[T]]})]})]})})}function yu({warning:t,onDismiss:o}){return e.jsx(r.Box,{sx:{position:"fixed",top:16,right:16,zIndex:50,maxWidth:448},children:e.jsxs(r.Alert,{severity:"warning",icon:e.jsx(k.Warning,{sx:{fontSize:20}}),action:e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:"warning.main"},children:e.jsx(k.Close,{sx:{fontSize:16}})}),sx:{borderLeft:4,borderColor:"warning.main",boxShadow:3},children:[e.jsx(r.AlertTitle,{sx:{fontWeight:600},children:"Feature Limit Reached"}),e.jsx(r.Box,{sx:{fontSize:"body2.fontSize",mb:1},children:t.message}),e.jsxs(r.Box,{sx:{fontSize:"caption.fontSize",opacity:.9},children:["Please remove some"," ",t.type==="filter"?"filters":t.type==="sort"?"sort levels":"grouping levels"," ","before adding more."]})]})})}function bu({error:t,onDismiss:o,autoDismiss:n=!0,autoDismissDelay:i=5e3}){p.useEffect(()=>{if(n){const l=setTimeout(()=>{o()},i);return()=>clearTimeout(l)}},[n,i,o]);const c=(()=>{switch(t.type){case"system":return{severity:"error",icon:e.jsx(k.Cancel,{sx:{fontSize:20}})};case"processing":return{severity:"warning",icon:e.jsx(k.Warning,{sx:{fontSize:20}})};case"ui":default:return{severity:"info",icon:e.jsx(k.InfoOutlined,{sx:{fontSize:20}})}}})(),d=Aa(t);return e.jsx(r.Box,{sx:{position:"fixed",top:16,right:16,zIndex:50,maxWidth:448},children:e.jsxs(r.Alert,{severity:c.severity,icon:c.icon,action:e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:`${c.severity}.main`},children:e.jsx(k.Close,{sx:{fontSize:16}})}),sx:{borderLeft:4,borderColor:`${c.severity}.main`,boxShadow:3},children:[e.jsxs(r.AlertTitle,{sx:{fontWeight:600},children:[t.context.charAt(0).toUpperCase()+t.context.slice(1)," Error"]}),e.jsx(r.Box,{sx:{fontSize:"body2.fontSize"},children:d}),t.details&&process.env.NODE_ENV==="development"&&e.jsx(r.Box,{component:"pre",sx:{fontSize:"caption.fontSize",mt:1,fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:JSON.stringify(t.details,null,2)})]})})}class vu extends p.Component{constructor(o){super(o),this.handleReset=()=>{this.setState({hasError:!1,error:null})},this.state={hasError:!1,error:null}}static getDerivedStateFromError(o){return{hasError:!0,error:o}}componentDidCatch(o,n){Ut.error("urm:error-boundary","Caught unhandled component error",o,n),this.props.onError&&this.props.onError(o,n)}render(){var o,n;return this.state.hasError?this.props.fallback?this.props.fallback:e.jsx(r.Paper,{sx:{bgcolor:i=>E(i.palette.error.main,.12),border:1,borderColor:"error.light",borderRadius:2,p:3,m:2},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(k.Warning,{color:"error",sx:{fontSize:24,flexShrink:0}}),e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"h6",sx:{color:"error.main",fontWeight:600},children:this.props.context?`${this.props.context} Error`:"Something went wrong"}),e.jsx(r.Typography,{variant:"body2",sx:{color:"error.main",mt:1},children:((o=this.state.error)==null?void 0:o.message)||"An unexpected error occurred"}),process.env.NODE_ENV==="development"&&e.jsx(r.Box,{component:"pre",sx:{mt:1.5,fontSize:"caption.fontSize",color:"error.main",bgcolor:i=>E(i.palette.error.main,.12),p:1.5,borderRadius:1,overflow:"auto",maxHeight:160},children:(n=this.state.error)==null?void 0:n.stack}),e.jsx(r.Button,{onClick:this.handleReset,variant:"contained",color:"error",startIcon:e.jsx(k.Refresh,{sx:{fontSize:16}}),sx:{mt:2},children:"Try Again"})]})]})}):this.props.children}}function Nr({children:t,feature:o,onError:n}){return e.jsx(vu,{context:o,onError:(i,s)=>{n&&n(i)},fallback:e.jsxs(r.Alert,{severity:"warning",sx:{m:1},icon:e.jsx(k.Warning,{sx:{fontSize:20}}),children:[e.jsxs(r.AlertTitle,{children:[o," temporarily unavailable"]}),"Other features continue to work normally"]}),children:t})}const Su=[{value:"equals",label:"Equals",group:"Text"},{value:"contains",label:"Contains",group:"Text"},{value:"startsWith",label:"Starts with",group:"Text"},{value:"endsWith",label:"Ends with",group:"Text"},{value:"gt",label:"Greater than (>)",group:"Numeric"},{value:"lt",label:"Less than (<)",group:"Numeric"},{value:"gte",label:"At least (≥)",group:"Numeric"},{value:"lte",label:"At most (≤)",group:"Numeric"},{value:"isTrue",label:"Is true",group:"Boolean"},{value:"isFalse",label:"Is false",group:"Boolean"},{value:"NULL",label:"Is empty (NULL)",group:"Null checks"},{value:"NOT_NULL",label:"Is not empty",group:"Null checks"}],ju=[{value:"csv",label:"CSV",desc:"Comma-separated values"},{value:"excel",label:"Excel (.xlsx)",desc:"Native Excel format"},{value:"json",label:"JSON",desc:"Structured data with metadata"}];function Lr({children:t,active:o}){return e.jsx(r.Box,{hidden:!o,sx:{pt:2.5,pb:1,display:o?"flex":"none",flexDirection:"column",gap:2.5},children:t})}function Cu({open:t,onClose:o,config:n,onApply:i}){const[s,c]=p.useState(0),[d,l]=p.useState(n),u=()=>l(n),m=()=>l(Ue),h=()=>{i(d),o()},b={sort:w=>l(v=>({...v,sort:{...v.sort,...w}})),filter:w=>l(v=>({...v,filter:{...v.filter,...w}})),columns:w=>l(v=>({...v,columns:{...v.columns,...w}})),grouping:w=>l(v=>({...v,grouping:{...v.grouping,...w}})),export:w=>l(v=>({...v,export:{...v.export,...w}}))},f=w=>{const v=d.filter.allowedOperators,j=v.includes(w)?v.filter(S=>S!==w):[...v,w];j.length!==0&&b.filter({allowedOperators:j})},g=w=>{const v=d.export.allowedFormats,j=v.includes(w)?v.filter(S=>S!==w):[...v,w];j.length!==0&&b.export({allowedFormats:j})},T=[{label:"Sort",icon:e.jsx(k.SwapVert,{sx:{fontSize:17}})},{label:"Filter",icon:e.jsx(k.FilterList,{sx:{fontSize:17}})},{label:"Columns",icon:e.jsx(k.ViewColumn,{sx:{fontSize:17}})},{label:"Grouping",icon:e.jsx(k.Layers,{sx:{fontSize:17}})},{label:"Export",icon:e.jsx(k.Download,{sx:{fontSize:17}})}],y=w=>JSON.stringify(d[w])===JSON.stringify(Ue[w]);return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,TransitionProps:{onEnter:u},PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(60,64,67,0.2)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1,borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:[e.jsx(r.Box,{sx:{width:32,height:32,borderRadius:"8px",bgcolor:w=>E(w.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",fontSize:"1.1rem"},children:"⚙️"}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle1",sx:{fontWeight:600,lineHeight:1.2},children:"Developer Configuration"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"Set runtime constraints · Ctrl+Shift+D"})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:"text.secondary"},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:e.jsx(r.Tabs,{value:s,onChange:(w,v)=>c(v),variant:"fullWidth",sx:{minHeight:44,"& .MuiTab-root":{minHeight:44,fontSize:"0.8125rem",textTransform:"none",fontWeight:500,gap:.5}},children:T.map((w,v)=>e.jsx(r.Tab,{label:w.label,icon:w.icon,iconPosition:"start"},v))})}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",flex:1,px:3,py:0},children:[e.jsxs(Lr,{active:s===0,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum sort levels"}),!y("sort")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users can sort by at most this many columns simultaneously."}),e.jsx(r.Slider,{value:d.sort.maxLevels,onChange:(w,v)=>b.sort({maxLevels:v}),min:1,max:10,step:1,marks:!0,valueLabelDisplay:"on"}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"1 level (single)"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"10 levels (maximum)"})]})]}),e.jsxs(r.Alert,{severity:"info",sx:{borderRadius:2,fontSize:"0.8125rem"},children:['The "Add sort column" button is hidden once users reach this limit. Default is'," ",e.jsx("strong",{children:"5"}),"."]})]}),e.jsxs(Lr,{active:s===1,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum filter conditions"}),!y("filter")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users can apply at most this many simultaneous filter conditions."}),e.jsx(r.Slider,{value:d.filter.maxConditions,onChange:(w,v)=>b.filter({maxConditions:v}),min:1,max:20,step:1,marks:!0,valueLabelDisplay:"on"}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"1 condition"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:"20 conditions"})]})]}),e.jsx(r.Divider,{}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,mb:.5},children:"Allowed filter operators"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1.5},children:"Only checked operators appear in the filter type dropdown. At least one must remain checked."}),["Text","Numeric","Boolean","Null checks"].map(w=>e.jsxs(r.Box,{sx:{mb:1.5},children:[e.jsx(r.Typography,{sx:{fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",color:"text.secondary",fontSize:"0.6875rem",display:"block",mb:.5},children:w}),e.jsx(r.FormGroup,{row:!0,sx:{gap:.5},children:Su.filter(v=>v.group===w).map(v=>e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{size:"small",checked:d.filter.allowedOperators.includes(v.value),onChange:()=>f(v.value)}),label:e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem"},children:v.label}),sx:{mr:1.5}},v.value))})]},w))]})]}),e.jsxs(Lr,{active:s===2,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum visible columns"}),!y("columns")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users cannot make more than this many columns visible simultaneously."}),e.jsx(r.Slider,{value:d.columns.maxVisible,onChange:(w,v)=>b.columns({maxVisible:v}),min:1,max:50,step:1,valueLabelDisplay:"on"})]}),e.jsx(r.Divider,{}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,mb:.5},children:"Column width range (px)"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users cannot resize columns outside this minimum / maximum range."}),e.jsxs(r.Box,{sx:{display:"flex",gap:2},children:[e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:.5},children:"Minimum width"}),e.jsx(r.Slider,{value:d.columns.minColumnWidth,onChange:(w,v)=>b.columns({minColumnWidth:v}),min:40,max:400,step:10,valueLabelDisplay:"on",valueLabelFormat:w=>`${w}px`})]}),e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:.5},children:"Maximum width"}),e.jsx(r.Slider,{value:d.columns.maxColumnWidth,onChange:(w,v)=>b.columns({maxColumnWidth:v}),min:100,max:2e3,step:50,valueLabelDisplay:"on",valueLabelFormat:w=>`${w}px`})]})]})]})]}),e.jsxs(Lr,{active:s===3,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum group levels"}),!y("grouping")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Box,{sx:{display:"flex",gap:1.5,mb:2},children:[1,2,3].map(w=>e.jsxs(r.Box,{onClick:()=>b.grouping({maxLevels:w}),sx:{flex:1,py:2.5,borderRadius:"10px",border:"2px solid",cursor:"pointer",textAlign:"center",transition:"all 0.15s ease",borderColor:d.grouping.maxLevels===w?"primary.main":"divider",bgcolor:d.grouping.maxLevels===w?v=>E(v.palette.primary.main,.06):"transparent","&:hover":{borderColor:"primary.light",bgcolor:v=>E(v.palette.primary.main,.04)}},children:[e.jsx(r.Typography,{variant:"h5",sx:{fontWeight:700,color:d.grouping.maxLevels===w?"primary.main":"text.secondary"},children:w}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:["Single","Double","Triple"][w-1]})]},w))}),e.jsxs(r.FormGroup,{row:!0,sx:{gap:2},children:[e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:d.grouping.allowNested,onChange:w=>b.grouping({allowNested:w.target.checked})}),label:e.jsx(r.Typography,{variant:"body2",children:"Allow nested groups"})}),e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:d.grouping.allowCollapse,onChange:w=>b.grouping({allowCollapse:w.target.checked})}),label:e.jsx(r.Typography,{variant:"body2",children:"Allow collapse / expand"})})]})]}),e.jsx(r.Alert,{severity:"info",sx:{borderRadius:2,fontSize:"0.8125rem"},children:'The "Add group level" button is hidden when users reach the configured limit.'})]}),e.jsx(Lr,{active:s===4,children:e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Allowed export formats"}),!y("export")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1.5},children:"Only checked formats appear in the Export dialog and the bulk export action. At least one must remain checked."}),e.jsx(r.FormGroup,{sx:{gap:1},children:ju.map(w=>e.jsxs(r.Box,{onClick:()=>g(w.value),sx:{display:"flex",alignItems:"center",gap:1.5,p:1.5,borderRadius:"8px",border:"1px solid",cursor:"pointer",transition:"all 0.15s ease",borderColor:d.export.allowedFormats.includes(w.value)?"primary.main":"divider",bgcolor:d.export.allowedFormats.includes(w.value)?v=>E(v.palette.primary.main,.04):"transparent","&:hover":{borderColor:"primary.light"}},children:[e.jsx(r.Checkbox,{size:"small",checked:d.export.allowedFormats.includes(w.value),onChange:()=>g(w.value),onClick:v=>v.stopPropagation()}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500},children:w.label}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:w.desc})]})]},w.value))})]})})]}),e.jsxs(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid",borderColor:"divider",bgcolor:w=>E(w.palette.action.hover,.4),justifyContent:"space-between",flexShrink:0},children:[e.jsx(r.Button,{startIcon:e.jsx(k.RestartAlt,{sx:{fontSize:18}}),onClick:m,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary","&:hover":{color:"text.primary",bgcolor:w=>E(w.palette.text.primary,.06)}},children:"Reset to defaults"}),e.jsxs(r.Box,{sx:{display:"flex",gap:1},children:[e.jsx(r.Button,{onClick:o,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px"},children:"Cancel"}),e.jsx(r.Button,{onClick:h,size:"small",variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2.5,borderRadius:"18px"},children:"Apply"})]})]})]})}const wu=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ku={1:"1st",2:"2nd",3:"3rd",4:"4th",5:"5th",6:"6th",7:"7th",8:"8th",9:"9th",10:"10th",11:"11th",12:"12th",13:"13th",14:"14th",15:"15th",16:"16th",17:"17th",18:"18th",19:"19th",20:"20th",21:"21st",22:"22nd",23:"23rd",24:"24th",25:"25th",26:"26th",27:"27th",28:"28th"};function lo(t,o,n,i,s=new Date){const[c,d]=o.split(":").map(Number),l=new Date(s);if(l.setSeconds(0,0),l.setHours(c,d,0,0),t==="daily")return l<=s&&l.setDate(l.getDate()+1),l.toISOString();if(t==="weekly"){const u=n??1,m=l.getDay();let h=u-m;return h<0&&(h+=7),h===0&&l<=s&&(h=7),l.setDate(l.getDate()+h),l.toISOString()}if(t==="monthly"){const u=Math.min(i??1,28);return l.setDate(u),l<=s&&(l.setMonth(l.getMonth()+1),l.setDate(u)),l.toISOString()}return l.toISOString()}function Tu(t){const o=Yi(t.time);return t.frequency==="daily"?`Daily at ${o}`:t.frequency==="weekly"?`Every ${wu[t.dayOfWeek??1]} at ${o}`:t.frequency==="monthly"?`Monthly on the ${ku[t.dayOfMonth??1]??`${t.dayOfMonth}th`} at ${o}`:o}function Yi(t){const[o,n]=t.split(":").map(Number),i=o>=12?"PM":"AM";return`${o%12||12}:${String(n).padStart(2,"0")} ${i}`}function Iu(t){const o=new Date(t).getTime()-Date.now();if(o<=0)return"now";const n=Math.floor(o/1e3),i=Math.floor(n/86400),s=Math.floor(n%86400/3600),c=Math.floor(n%3600/60);return i>0?`in ${i}d ${s}h`:s>0?`in ${s}h ${c}m`:c>0?`in ${c}m`:"in less than a minute"}function zu(t){const o=new Date(t),n=new Date,i=o.toDateString()===n.toDateString(),s=Yi(`${String(o.getHours()).padStart(2,"0")}:${String(o.getMinutes()).padStart(2,"0")}`);return i?`Today at ${s}`:`${o.toLocaleDateString("en-US",{month:"short",day:"numeric"})} at ${s}`}function Gi(t){return`urm_schedules_${t}`}function qi(t){try{const o=localStorage.getItem(Gi(t));return o?JSON.parse(o).map(i=>({...i,runCount:typeof i.runCount=="number"?i.runCount:0,isActive:typeof i.isActive=="boolean"?i.isActive:!0,createdAt:i.createdAt||new Date().toISOString()})):[]}catch{return[]}}function Ji(t,o){try{localStorage.setItem(Gi(t),JSON.stringify(o))}catch{}}const Eu=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:2,label:"Tuesday"},{value:3,label:"Wednesday"},{value:4,label:"Thursday"},{value:5,label:"Friday"},{value:6,label:"Saturday"}],Bu=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,Ki={name:"",frequency:"daily",dayOfWeek:1,dayOfMonth:1,time:"09:00",format:"csv",scope:"all",email:""},Ht={"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:"8px"},"& .MuiInputLabel-root":{fontSize:"0.875rem"},"& .MuiFormHelperText-root":{fontSize:"0.75rem",mx:.5},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}};function Du({initial:t=Ki,isEditing:o=!1,onSave:n,onBack:i}){const[s,c]=p.useState(t),[d,l]=p.useState(!1),[u,m]=p.useState(!1),h=(g,T)=>c(y=>({...y,[g]:T})),b=s.email.trim().length>0&&!Bu.test(s.email.trim()),f=s.name.trim().length>0&&/^\d{2}:\d{2}$/.test(s.time)&&(s.frequency!=="monthly"||s.dayOfMonth>=1&&s.dayOfMonth<=28)&&!b;return e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,mb:.5},children:[e.jsx(r.IconButton,{size:"small",onClick:i,sx:{color:"text.secondary",ml:-.75,"&:hover":{bgcolor:g=>E(g.palette.text.primary,.06)}},children:e.jsx(k.ArrowBack,{sx:{fontSize:18}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:o?"Edit schedule":"New schedule"})]}),e.jsx(r.TextField,{label:"Schedule name *",size:"small",fullWidth:!0,value:s.name,onChange:g=>{h("name",g.target.value),d&&g.target.value.trim()&&l(!1)},onBlur:()=>l(!0),placeholder:"e.g. Weekly Sales Report",autoFocus:!0,inputProps:{maxLength:50},error:d&&!s.name.trim(),helperText:d&&!s.name.trim()?"Schedule name is required":`${s.name.length}/50`,sx:Ht}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:Ht,children:[e.jsx(r.InputLabel,{children:"Frequency"}),e.jsxs(r.Select,{value:s.frequency,label:"Frequency",onChange:g=>h("frequency",g.target.value),children:[e.jsx(r.MenuItem,{value:"daily",children:"Daily"}),e.jsx(r.MenuItem,{value:"weekly",children:"Weekly"}),e.jsx(r.MenuItem,{value:"monthly",children:"Monthly"})]})]}),s.frequency==="weekly"&&e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:Ht,children:[e.jsx(r.InputLabel,{children:"Day of week"}),e.jsx(r.Select,{value:s.dayOfWeek,label:"Day of week",onChange:g=>h("dayOfWeek",Number(g.target.value)),children:Eu.map(g=>e.jsx(r.MenuItem,{value:g.value,children:g.label},g.value))})]}),s.frequency==="monthly"&&e.jsx(r.TextField,{label:"Day of month (1–28)",size:"small",type:"number",fullWidth:!0,value:s.dayOfMonth,onChange:g=>h("dayOfMonth",Number(g.target.value)),inputProps:{min:1,max:28},error:s.dayOfMonth<1||s.dayOfMonth>28,helperText:s.dayOfMonth<1||s.dayOfMonth>28?"Day must be between 1 and 28":"Max 28 — works safely across all months including February",sx:Ht}),e.jsx(r.TextField,{label:"Time",size:"small",type:"time",fullWidth:!0,value:s.time,onChange:g=>h("time",g.target.value),InputLabelProps:{shrink:!0},helperText:"24-hour format · Tab must be open for the schedule to fire",sx:Ht}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:Ht,children:[e.jsx(r.InputLabel,{children:"Export format"}),e.jsxs(r.Select,{value:s.format,label:"Export format",onChange:g=>h("format",g.target.value),children:[e.jsx(r.MenuItem,{value:"csv",children:"CSV — Comma-separated values"}),e.jsx(r.MenuItem,{value:"excel",children:"Excel (.xlsx) — Native format"}),e.jsx(r.MenuItem,{value:"json",children:"JSON — Structured data"})]})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontWeight:500,color:"text.secondary",display:"block",mb:.75},children:"Data scope"}),e.jsxs(r.RadioGroup,{row:!0,value:s.scope,onChange:g=>h("scope",g.target.value),sx:{gap:2},children:[e.jsx(r.FormControlLabel,{value:"all",control:e.jsx(r.Radio,{size:"small"}),label:e.jsx(r.Typography,{variant:"body2",children:"All rows"})}),e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small"}),label:e.jsx(r.Typography,{variant:"body2",children:"Filtered rows only"})})]})]}),e.jsxs(r.Box,{children:[e.jsx(r.TextField,{label:"Email reminder (optional)",size:"small",fullWidth:!0,type:"email",value:s.email,onChange:g=>h("email",g.target.value),onBlur:()=>m(!0),placeholder:"user@company.com",error:u&&b,helperText:u&&b?"Enter a valid email address":void 0,InputProps:{startAdornment:e.jsx(k.Email,{sx:{fontSize:15,color:"text.disabled",mr:1}})},sx:Ht}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:.5,mt:.5,px:.5},children:[e.jsx(k.InfoOutlined,{sx:{fontSize:12,color:"text.disabled",mt:.2,flexShrink:0}}),e.jsx(r.Typography,{variant:"caption",color:"text.disabled",sx:{lineHeight:1.5},children:"Opens your device's email app when the schedule fires. Requires a default mail app (e.g. Outlook, Mail) on this device."})]})]}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"flex-end",gap:1,pt:.5},children:[e.jsx(r.Button,{onClick:i,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px","&:hover":{bgcolor:g=>E(g.palette.text.primary,.06)}},children:"Cancel"}),e.jsx(r.Button,{onClick:()=>f&&n(s),disabled:!f,size:"small",variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",px:2.5,borderRadius:"18px"},children:o?"Save changes":"Create schedule"})]})]})}function Ou({scheduleName:t,onConfirm:o,onCancel:n}){return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"14px",boxShadow:i=>{var s;return`0 8px 32px ${E(((s=i.palette.common)==null?void 0:s.black)??"#000",.14)}`}}},children:[e.jsxs(r.DialogContent,{sx:{pt:3,pb:2,px:3},children:[e.jsx(r.Box,{sx:{width:44,height:44,borderRadius:"12px",bgcolor:i=>E(i.palette.error.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:2},children:e.jsx(k.WarningAmberOutlined,{sx:{fontSize:22,color:"error.main"}})}),e.jsx(r.Typography,{sx:{fontSize:"0.9375rem",fontWeight:600,color:"text.primary",mb:1},children:"Delete Schedule"}),e.jsxs(r.Typography,{sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.65},children:["Are you sure you want to delete"," ",e.jsxs(r.Box,{component:"span",sx:{fontWeight:600,color:"text.primary"},children:['"',t,'"']}),"? This action cannot be undone."]})]}),e.jsx(r.Divider,{}),e.jsxs(r.DialogActions,{sx:{px:2.5,py:1.5,gap:1},children:[e.jsx(r.Button,{onClick:n,variant:"text",sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,color:"text.secondary",borderRadius:"7px","&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsx(r.Button,{onClick:o,variant:"contained",color:"error",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,borderRadius:"7px",px:2},children:"Delete"})]})]})}function Au({schedule:t,tick:o,onToggle:n,onRunNow:i,onEdit:s,onDelete:c}){const d=t.isActive;return e.jsxs(r.Box,{sx:{border:"1px solid",borderColor:d?"primary.main":"divider",borderRadius:"10px",p:1.75,bgcolor:d?l=>E(l.palette.primary.main,.025):"background.paper",transition:"border-color 0.15s ease, background-color 0.15s ease"},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,flex:1,minWidth:0,color:d?"text.primary":"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.name}),e.jsx(r.Chip,{label:d?"Active":"Paused",size:"small",sx:{height:18,fontSize:"0.6875rem",fontWeight:600,flexShrink:0,bgcolor:d?l=>E(l.palette.success.main,.1):l=>E(l.palette.text.primary,.06),color:d?"success.dark":"text.secondary"}})]}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",display:"block",mb:1},children:Tu(t)}),e.jsxs(r.Box,{sx:{display:"flex",flexWrap:"wrap",gap:.5,mb:1},children:[e.jsx(r.Chip,{label:t.format.toUpperCase(),size:"small",sx:{height:20,fontSize:"0.6875rem",fontWeight:500,bgcolor:l=>E(l.palette.primary.main,.08),color:"primary.main"}}),e.jsx(r.Chip,{label:t.scope==="all"?"All rows":"Filtered rows",size:"small",sx:{height:20,fontSize:"0.6875rem",bgcolor:l=>E(l.palette.text.primary,.06),color:"text.secondary"}}),t.email&&e.jsx(r.Chip,{icon:e.jsx(k.Email,{sx:{fontSize:11}}),label:t.email,size:"small",sx:{height:20,fontSize:"0.6875rem",maxWidth:220,bgcolor:l=>E(l.palette.text.primary,.06),color:"text.secondary","& .MuiChip-label":{overflow:"hidden",textOverflow:"ellipsis"}}})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:1},children:[e.jsxs(r.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1.5,alignItems:"center"},children:[d&&e.jsxs(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:500},children:["Next: ",Iu(t.nextRunAt)]}),t.lastRunAt?e.jsxs(r.Typography,{variant:"caption",color:"text.secondary",children:["Last: ",zu(t.lastRunAt)," · ",t.runCount," run",t.runCount!==1?"s":""]}):e.jsx(r.Typography,{variant:"caption",color:"text.disabled",children:"Never run"})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,flexShrink:0},children:[e.jsx(r.Tooltip,{title:"Edit",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>s(t),sx:{color:"text.secondary","&:hover":{color:"primary.main",bgcolor:l=>E(l.palette.primary.main,.08)}},children:e.jsx(k.Edit,{sx:{fontSize:15}})})}),e.jsx(r.Tooltip,{title:d?"Pause":"Resume",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>n(t.id),sx:{color:d?"warning.main":"success.main","&:hover":{bgcolor:d?l=>E(l.palette.warning.main,.08):l=>E(l.palette.success.main,.08)}},children:d?e.jsx(k.Pause,{sx:{fontSize:15}}):e.jsx(k.PlayArrow,{sx:{fontSize:15}})})}),e.jsx(r.Tooltip,{title:"Export now",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>i(t),sx:{color:"primary.main","&:hover":{bgcolor:l=>E(l.palette.primary.main,.08)}},children:e.jsx(k.Download,{sx:{fontSize:15}})})}),e.jsx(r.Tooltip,{title:"Delete",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>c(t.id),sx:{color:"error.main","&:hover":{bgcolor:l=>E(l.palette.error.main,.08)}},children:e.jsx(k.Delete,{sx:{fontSize:15}})})})]})]})]})}function Mu({open:t,onClose:o,reportId:n,reportName:i,onRunNow:s}){const[c,d]=p.useState([]),[l,u]=p.useState({type:"list"}),[m,h]=p.useState(0),[b,f]=p.useState(null);p.useEffect(()=>{t&&(d(qi(n)),u({type:"list"}))},[t,n]),p.useEffect(()=>{if(!t)return;const B=setInterval(()=>h($=>$+1),3e4);return()=>clearInterval(B)},[t]);const g=p.useCallback(B=>{d(B),Ji(n,B)},[n]),T=B=>{const $=lo(B.frequency,B.time,B.dayOfWeek,B.dayOfMonth),Y={id:`sched-${Date.now()}`,reportId:n,name:B.name.trim(),frequency:B.frequency,dayOfWeek:B.frequency==="weekly"?B.dayOfWeek:void 0,dayOfMonth:B.frequency==="monthly"?B.dayOfMonth:void 0,time:B.time,format:B.format,scope:B.scope,email:B.email.trim()||void 0,isActive:!0,createdAt:new Date().toISOString(),nextRunAt:$,runCount:0};g([...c,Y]),u({type:"list"})},y=B=>{if(l.type!=="edit")return;const $=l.schedule,Y=lo(B.frequency,B.time,B.dayOfWeek,B.dayOfMonth);g(c.map(Q=>Q.id===$.id?{...$,name:B.name.trim(),frequency:B.frequency,dayOfWeek:B.frequency==="weekly"?B.dayOfWeek:void 0,dayOfMonth:B.frequency==="monthly"?B.dayOfMonth:void 0,time:B.time,format:B.format,scope:B.scope,email:B.email.trim()||void 0,nextRunAt:Y}:Q)),u({type:"list"})},w=B=>{g(c.map($=>{if($.id!==B)return $;const Y=$.isActive?$.nextRunAt:lo($.frequency,$.time,$.dayOfWeek,$.dayOfMonth);return{...$,isActive:!$.isActive,nextRunAt:Y}}))},v=B=>{s(B);const $=new Date().toISOString();g(c.map(Y=>Y.id===B.id?{...Y,lastRunAt:$,runCount:Y.runCount+1}:Y))},j=B=>{const $=c.find(Y=>Y.id===B)??null;f($)},S=()=>{b&&(g(c.filter(B=>B.id!==b.id)),f(null))},I=B=>({name:B.name,frequency:B.frequency,dayOfWeek:B.dayOfWeek??1,dayOfMonth:B.dayOfMonth??1,time:B.time,format:B.format,scope:B.scope,email:B.email??""}),a=l.type!=="list",A=c.filter(B=>B.isActive).length;return e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,disableEscapeKeyDown:a,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(680px, calc(100vh - 180px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:6}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",py:1.5,px:2.5,borderBottom:"1px solid",borderColor:"divider",flexShrink:0,minHeight:0},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.25},children:[e.jsx(r.Box,{sx:{width:30,height:30,borderRadius:"7px",bgcolor:B=>E(B.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(k.Schedule,{sx:{fontSize:17,color:"primary.main"}})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"baseline",gap:.75},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:600,lineHeight:1},children:"Scheduled Reports"}),e.jsx(qt,{content:Jt.schedule,isDev:process.env.NODE_ENV==="development"})]}),e.jsxs(r.Typography,{variant:"caption",color:"text.secondary",sx:{lineHeight:1},children:["· ",i]})]})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:"text.secondary","&:hover":{bgcolor:B=>E(B.palette.text.primary,.06)}},children:e.jsx(k.Close,{sx:{fontSize:18}})})]}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",flex:1,px:2.5,py:2},children:[a&&e.jsx(Du,{initial:l.type==="edit"?I(l.schedule):Ki,isEditing:l.type==="edit",onSave:l.type==="edit"?y:T,onBack:()=>u({type:"list"})}),l.type==="list"&&e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1.75,pt:1.5},children:[e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:c.length===0?"No schedules yet":`${A} of ${c.length} active`}),e.jsx(r.Button,{startIcon:e.jsx(k.Add,{sx:{fontSize:15}}),size:"small",variant:"contained",disableElevation:!0,onClick:()=>u({type:"create"}),sx:{textTransform:"none",fontWeight:500,fontSize:"0.8125rem",borderRadius:"18px",px:1.75,py:.625},children:"New schedule"})]}),c.length===0?e.jsxs(r.Box,{sx:{border:"1.5px dashed",borderColor:"divider",borderRadius:"10px",py:5,px:2,textAlign:"center"},children:[e.jsx(k.NotificationsActive,{sx:{fontSize:30,color:"text.disabled",mb:1.25,display:"block",mx:"auto"}}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"text.secondary"},children:"No scheduled reports yet"}),e.jsx(r.Typography,{variant:"caption",color:"text.disabled",sx:{display:"block",mt:.5},children:'Use "New schedule" above to set up automatic exports'})]}):e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:c.map(B=>e.jsx(Au,{schedule:B,tick:m,onToggle:w,onRunNow:v,onEdit:$=>u({type:"edit",schedule:$}),onDelete:j},B.id))})]})]}),l.type==="list"&&e.jsxs(r.DialogActions,{sx:{px:2.5,py:1.25,borderTop:"1px solid",borderColor:"divider",flexShrink:0,display:"flex",alignItems:"center",gap:1},children:[e.jsxs(r.Box,{sx:{flex:1,display:"flex",alignItems:"center",gap:.75,px:1.25,py:.75,borderRadius:"8px",bgcolor:B=>E(B.palette.warning.main,.06),border:"1px solid",borderColor:B=>E(B.palette.warning.main,.2)},children:[e.jsx(k.Schedule,{sx:{fontSize:13,color:"warning.main",flexShrink:0}}),e.jsx(r.Typography,{variant:"caption",sx:{color:"warning.dark",lineHeight:1.1},children:"Schedules require this browser tab to remain open."})]}),e.jsx(r.Button,{onClick:o,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary",px:2,borderRadius:"18px",flexShrink:0,"&:hover":{bgcolor:B=>E(B.palette.text.primary,.06)}},children:"Close"})]})]}),b&&e.jsx(Ou,{scheduleName:b.name,onConfirm:S,onCancel:()=>f(null)})]})}const _u=6e4;function $u({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:c,columnVisibility:d,columnOrder:l,filters:u,sortStack:m,onFired:h}){const b=p.useRef({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:c,columnVisibility:d,columnOrder:l,filters:u,sortStack:m,onFired:h});p.useEffect(()=>{b.current={reportId:t,reportName:o,uploadedData:n,processedData:i,schema:s,activeView:c,columnVisibility:d,columnOrder:l,filters:u,sortStack:m,onFired:h}});const f=p.useCallback(g=>{var B,$;const{reportName:T,uploadedData:y,processedData:w,schema:v,activeView:j,columnVisibility:S,columnOrder:I,filters:a,sortStack:A}=b.current;try{const Y=g.scope==="all"?y:w,Q=co(Y,v,a,A,j,S,I),te=`${g.name}_scheduled`;switch(g.format){case"csv":uo(Q,te,{scope:g.scope});break;case"excel":po(Q,te,{scope:g.scope});break;case"json":xo(Q,te,{scope:g.scope});break}if(g.email){const x=encodeURIComponent(`Scheduled Report: ${g.name}`),N=encodeURIComponent(`Your scheduled report "${g.name}" has been generated.
|
|
90
90
|
|
|
91
|
-
Report: ${
|
|
91
|
+
Report: ${T}
|
|
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=${x}&body=${N}`,"_blank")}($=(B=b.current).onFired)==null||$.call(B,g)}catch(Y){Ut.error("urm:scheduler",`Export failed for schedule: ${g.name}`,Y)}},[]);p.useEffect(()=>{if(!t)return;const g=()=>{const{reportId:y}=b.current;if(!y)return;const w=qi(y),v=new Date;let j=!1;const S=w.map(I=>{if(!I.isActive)return I;if(new Date(I.nextRunAt)<=v){f(I);const A=lo(I.frequency,I.time,I.dayOfWeek,I.dayOfMonth,v);return j=!0,{...I,lastRunAt:v.toISOString(),nextRunAt:A,runCount:I.runCount+1}}return I});j&&Ji(y,S)};g();const T=setInterval(g,_u);return()=>clearInterval(T)},[t,f])}function Xi({reportEngine:t}){var lr,Lt,Ft,M,Z;const{activeReport:o,paginatedData:n,processedData:i,displayData:s,tableMetrics:c,tableEngine:d,activeView:l,isDirty:u,currentTableState:m,viewChanges:h,showFilterPanel:b,setShowFilterPanel:f,filterFocusColumn:g,handleAddFilter:T,handleUpdateFilter:y,handleRemoveFilter:w,handleClearAllFilters:v,handleReplaceFilters:j,handleOpenFilterForColumn:S,handleCloseFilterPanel:I,handleClearFiltersForColumn:a,showSortPanel:A,setShowSortPanel:B,handleSort:$,handleUpdateSortStack:Y,handleSortAscending:Q,handleSortDescending:te,showManageViews:x,setShowManageViews:N,showCreateViewModal:W,setShowCreateViewModal:H,showEditViewModal:J,setShowEditViewModal:ue,showDeleteConfirmation:pe,setShowDeleteConfirmation:re,editingView:O,deletingView:F,handleSelectView:G,handleCreateView:se,handleUpdateCurrentView:ee,handleSaveColumnConfigToCurrentView:le,handleSaveColumnConfigToAllViews:ae,handleSaveAsNewView:P,handleRevertChanges:ne,handleToggleDefault:ce,handleToggleFavorite:ie,handleSoftDelete:he,handleRestoreView:q,handlePermanentDelete:Ae,handleEditView:We,handleSaveEditView:tt,handleConfirmDelete:Kt,handlePromoteToGlobal:hr,showManageColumns:At,setShowManageColumns:it,handleUpdateColumnVisibility:Re,handleUpdateColumnOrder:Ee,handleUpdateColumnWidth:gt,handleResetColumnLayout:st,showGroupPanel:rt,setShowGroupPanel:Je,handleGroup:It,handleToggleGroupCollapse:Xt,searchQuery:at,searchHistory:Ke,handleSearchChange:Pe,handleAddToSearchHistory:Zt,handleToggleSearchFavourite:yt,handleDeleteSearchHistory:zt,selectedRowIds:Qt,handleToggleRowSelection:lt,handleToggleAllRows:gr,handleRangeSelection:yr,handleClearSelection:br,handleUpdateSelectionAfterDelete:Mt,currentPage:vr,pageSize:Sr,paginationEngine:Xe,handlePageChange:ve,handlePageSizeChange:jr,isExporting:er,showExportModal:ot,setShowExportModal:L,showDirtyExportWarning:Ne,handleExport:Se,handleExportWithConfig:_e,handleExportSelected:Cr,handleExportAnyway:_t,handleSaveAndExport:bt,handleCancelExport:$t,showAuditHistory:Wt,setShowAuditHistory:Et,showCreatePreset:wr,setShowCreatePreset:Rt,showManagePresets:De,setShowManagePresets:X,generatedPreset:vt,activePreset:ge,handleOpenManagePresets:je,handleCreatePreset:Ze,handleCopyPresetLink:kr,handleOpenPreset:St,handleClearActivePreset:$e,handleOpenPresetById:tr,handleCopyPresetLinkById:Tr,handleDeletePresetById:rr,isViewerRole:or,userRole:Ir,featureLimitWarning:nr,setFeatureLimitWarning:ir,reportError:Le,setReportError:ct,handleError:dt,updateReport:Fe,showSnack:sr,favoriteRowIndices:Pt,resolvedFavoritesSet:zr,showFavoritesOnly:Er,handleToggleRowFavorite:Br,handleBulkSetFavorites:Dr,handleToggleFavoritesFilter:Or}=t,[Ar,Nt]=p.useState(!1);$u({reportId:o==null?void 0:o.id,reportName:(o==null?void 0:o.name)||"Report",uploadedData:(o==null?void 0:o.uploadedData)||[],processedData:i||[],schema:(o==null?void 0:o.schema)||[],activeView:l,columnVisibility:(o==null?void 0:o.columnVisibility)||((lr=l==null?void 0:l.snapshot)==null?void 0:lr.columnVisibility)||{},columnOrder:(o==null?void 0:o.columnOrder)||((Lt=l==null?void 0:l.snapshot)==null?void 0:Lt.columnOrder)||[],filters:(o==null?void 0:o.filters)||[],sortStack:(o==null?void 0:o.sortStack)||[],onFired:K=>{sr(`Scheduled export "${K.name}" completed`,"success")}});const Mr=p.useCallback((K,de)=>{if(!(o!=null&&o.uploadedData))return;const oe=[...o.uploadedData];oe[K]=de,Fe(o.id,{uploadedData:oe})},[o,Fe]),_r=p.useCallback(K=>{if(!(o!=null&&o.uploadedData))return;const de=o.uploadedData.indexOf(K);if(de===-1)return;const oe=o.uploadedData.filter((nt,Xr)=>Xr!==de),He=(o.favoriteRowIndices||[]).filter(nt=>nt!==de).map(nt=>nt>de?nt-1:nt);Fe(o.id,{uploadedData:oe,favoriteRowIndices:He}),Mt(K)},[o,Fe,Mt]),Me=p.useCallback((K,de)=>{if(!(o!=null&&o.uploadedData))return;const oe=o.uploadedData.indexOf(de),He=oe!==-1?oe+1:K+1,nt=[...o.uploadedData];nt.splice(He,0,{...de});const Oo=(o.favoriteRowIndices??[]).map($r=>$r>=He?$r+1:$r);Fe(o.id,{uploadedData:nt,favoriteRowIndices:Oo})},[o,Fe]),Ve=Gt(),{handleDevConfigChange:ar}=go(),[Kr,ut]=p.useState(!1);return p.useEffect(()=>{const K=de=>{de.ctrlKey&&de.shiftKey&&de.key==="D"&&(de.preventDefault(),ut(!0))};return document.addEventListener("keydown",K),()=>document.removeEventListener("keydown",K)},[]),!o||!o.schemaLocked||!o.schema||!o.uploadedData||!o.views?null:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",height:"100%",minHeight:0,overflow:"hidden",position:"relative"},children:[!or&&u&&l&&e.jsx(tu,{viewName:l.name,isDefaultView:l.isDefault,changes:h,onSaveToCurrentView:l.isDefault?void 0:ee,onSaveAsNewView:P,onCancel:ne}),e.jsxs(r.Box,{id:"table-content-area",sx:{flex:1,minHeight:0,overflow:"hidden",display:"flex",flexDirection:"column",position:"relative"},children:[nr&&e.jsx(yu,{warning:nr,onDismiss:()=>ir(null)}),Le&&e.jsx(bu,{error:Le,onDismiss:()=>ct(null)}),Ne&&e.jsx(ru,{onExportAnyway:_t,onSaveAndExport:bt,onCancel:$t}),e.jsx(Hd,{schema:o.schema,data:n,sortStack:o.sortStack,filters:o.filters,views:o.views,activeViewId:o.activeViewId,isDirty:u,isExporting:er,columnVisibility:o.columnVisibility||(l==null?void 0:l.snapshot.columnVisibility),columnOrder:o.columnOrder||(l==null?void 0:l.snapshot.columnOrder),columnWidths:o.columnWidths||(l==null?void 0:l.snapshot.columnWidths),grouping:o.grouping,onSort:$,onSortAscending:Q,onSortDescending:te,onOpenFilters:()=>f(!0),onOpenSort:()=>B(!0),onOpenFilterForColumn:S,onSelectView:G,onCreateView:()=>H(!0),onManageViews:()=>N(!0),onUpdateCurrentView:ee,onSaveAsNewView:P,onToggleDefault:ce,onToggleFavorite:ie,onRestoreView:q,onPermanentDelete:Ae,onExport:Se,onOpenColumns:()=>it(!0),onUpdateColumnWidth:gt,onUpdateColumnOrder:Ee,onUpdateColumnVisibility:Re,onClearFiltersForColumn:a,onResetLayout:st,onOpenGroup:()=>Je(!0),onToggleGroupCollapse:Xt,onOpenAuditHistory:()=>Et(!0),onOpenScheduledReports:()=>Nt(!0),searchQuery:at,searchHistory:Ke,onAddToSearchHistory:Zt,onToggleSearchFavourite:yt,onDeleteSearchHistory:zt,selectedRowIds:Qt,onSearchChange:Pe,onToggleRowSelection:lt,onToggleAllRows:gr,onRangeSelection:yr,onClearSelection:br,onExportSelected:Cr,currentPage:(Xe==null?void 0:Xe.currentPage)||vr,pageSize:(Xe==null?void 0:Xe.pageSize)||Sr,onPageChange:ve,onPageSizeChange:jr,totalRowsBeforePagination:(c==null?void 0:c.searchedRows)||i.length,isReadOnly:or,userRole:Ir,reportName:o.name,onEditRow:Mr,onDeleteRow:_r,onDuplicateRow:Me,favoriteRowIndices:Pt,resolvedFavoritesSet:zr,showFavoritesOnly:Er,onToggleRowFavorite:Br,onBulkSetFavorites:Dr,onToggleFavoritesFilter:Or,showDevPanel:Ve.display.showDevPanel,onOpenDevConfig:()=>ut(!0)})]}),b&&e.jsx(Nr,{feature:"Filters",onError:K=>{const de=Ct("ui","filters",K);dt(de)},children:e.jsx(Ud,{schema:o.schema,filters:o.filters??[],onAddFilter:T,onUpdateFilter:y,onRemoveFilter:w,onClearAll:v,onReplaceFilters:j,onClose:I,focusColumn:g})}),A&&e.jsx(Nr,{feature:"Sorting",onError:K=>{const de=Ct("ui","sorting",K);dt(de)},children:e.jsx(Gd,{schema:o.schema,sortStack:o.sortStack??[],onUpdateSortStack:Y,onClose:()=>B(!1)})}),x&&e.jsx(Nr,{feature:"Views",onError:K=>{const de=Ct("ui","views",K);dt(de)},children:e.jsx(qd,{views:o.views,activeViewId:o.activeViewId??"",onSelectView:G,onCreateView:()=>{N(!1),H(!0)},onEditView:We,onDeleteView:he,onRestoreView:q,onPermanentDelete:Ae,onPromoteToGlobal:hr,isAdmin:((Ft=Ve.views)==null?void 0:Ft.isAdmin)??!1,onClose:()=>N(!1)})}),W&&m&&(()=>{var oe;const K=(o.views??[]).filter(He=>!He.isDeleted).length,de=((oe=Ve.views)==null?void 0:oe.maxViews)??10;return e.jsx(si,{currentSnapshot:m,onSave:se,onClose:()=>H(!1),atViewLimit:K>=de,maxViews:de})})(),J&&O&&e.jsx(si,{currentSnapshot:O.snapshot,onSave:tt,onClose:()=>{ue(!1)},isEditMode:!0,initialName:O.name,initialDescription:O.description,initialIsDefault:O.isDefault}),pe&&F&&e.jsx(Jd,{viewName:F.name,onConfirm:Kt,onCancel:()=>{re(!1)}}),At&&l&&e.jsx(Xd,{schema:o.schema,columnVisibility:o.columnVisibility||l.snapshot.columnVisibility,columnOrder:o.columnOrder||l.snapshot.columnOrder,columnWidths:o.columnWidths||l.snapshot.columnWidths,views:o.views,activeViewId:o.activeViewId,onUpdateColumnVisibility:Re,onUpdateColumnOrder:Ee,onUpdateColumnWidth:gt,onResetLayout:st,onSelectView:K=>{G(K)},onSaveToCurrentView:K=>{le(K),it(!1)},onSaveToAllViews:K=>{ae(K),it(!1)},onClose:()=>it(!1)}),rt&&e.jsx(Nr,{feature:"Grouping",onError:K=>{const de=Ct("ui","grouping",K);dt(de)},children:e.jsx(Zd,{schema:o.schema,grouping:o.grouping||null,onApply:It,onClose:()=>Je(!1)})}),Wt&&e.jsx(iu,{auditHistory:o.auditHistory||[],onClose:()=>Et(!1)}),wr&&e.jsx(su,{onSave:Ze,onClose:()=>Rt(!1)}),De&&e.jsx(lu,{presets:o.presets||[],reportId:o.id,onOpenPreset:tr,onCopyLink:Tr,onDeletePreset:rr,onClose:()=>X(!1)}),ge&&e.jsx(r.Box,{sx:{mt:2},children:e.jsx(au,{presetName:ge.name,onClear:$e})}),ot&&e.jsx(Nr,{feature:"Export",onError:K=>{const de=Ct("ui","export",K);dt(de)},children:e.jsx(gu,{totalRows:(c==null?void 0:c.totalRows)||((M=o.uploadedData)==null?void 0:M.length)||0,visibleRows:(c==null?void 0:c.searchedRows)||i.length,visibleColumnsCount:((Z=d==null?void 0:d.columnEngine)==null?void 0:Z.visibleColumns.length)||o.schema.length,totalColumnsCount:o.schema.length,hasGrouping:(c==null?void 0:c.isGrouped)||!1,onExport:_e,onClose:()=>{L(!1)}})}),o&&e.jsx(Mu,{open:Ar,onClose:()=>Nt(!1),reportId:o.id,reportName:o.name,onRunNow:K=>{const de=K.scope==="all"?o.uploadedData||[]:i||[],oe=co(de,o.schema||[],o.filters||[],o.sortStack||[],l,o.columnVisibility,o.columnOrder);K.format==="csv"&&uo(oe,K.name),K.format==="excel"&&po(oe,K.name),K.format==="json"&&xo(oe,K.name),sr(`"${K.name}" exported successfully`,"success")}}),e.jsx(Cu,{open:Kr,onClose:()=>ut(!1),config:Ve,onApply:ar})]})}function Zi({open:t,message:o,severity:n,onClose:i}){return e.jsx(r.Snackbar,{open:t,autoHideDuration:2e3,onClose:(s,c)=>{c!=="escapeKeyDown"&&i()},anchorOrigin:{vertical:"top",horizontal:"right"},children:e.jsx(r.Alert,{severity:n,variant:"filled",sx:{width:"100%",boxShadow:3},children:o})})}function Qi({hasExternalData:t=!1}){const o=go(),{reports:n,activeReportId:i,activeReport:s,uploadState:c,schema:d,hasSchemaConflicts:l,isModalOpen:u,setIsModalOpen:m,setActiveReportId:h,createReport:b,handleFileUpload:f,handleUploadError:g,handleRetry:T,handleConfirm:y,snack:w,handleSnackClose:v}=o,j=t&&c==="uploading"&&n.length===0;return e.jsxs(r.Box,{sx:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsx(el,{onCreateReport:()=>m(!0),reports:n,activeReportId:i,onReportClick:h}),e.jsx(r.Box,{component:"main",sx:{flex:1,overflow:"hidden",display:"flex",flexDirection:"column",m:0,p:0},children:j?e.jsxs(r.Box,{sx:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2},children:[e.jsx(r.CircularProgress,{size:40,thickness:3}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",sx:{minWidth:260,textAlign:"center"},children:"Fetching API data — please wait..."})]}):n.length===0?e.jsx(Vi,{title:"No reports yet",description:"Create your first report to start analyzing your data."}):s?e.jsx(e.Fragment,{children:s.schemaLocked&&s.schema&&s.uploadedData&&s.views?e.jsx(Xi,{reportEngine:o}):e.jsx(r.Box,{sx:{p:3},children:c==="preview"&&s.schema&&s.uploadedData?e.jsx(ud,{schema:s.schema,onConfirm:y,hasConflicts:l}):s.uploadError?e.jsx(pd,{error:s.uploadError,onRetry:T}):e.jsx(dd,{onFileUpload:f,onError:g,isUploading:c==="uploading"})})}):null}),!t&&e.jsx(cd,{isOpen:u,onClose:()=>m(!1),onCreate:b}),e.jsx(Zi,{open:w.open,message:w.message,severity:w.severity,onClose:v})]})}function Wu({data:t,dataSource:o,reportName:n,autoLoad:i=!0,config:s}={}){return e.jsx(en,{mode:"builder",data:t,dataSource:o,reportName:n,autoLoad:i,config:s,children:e.jsx(Qi,{hasExternalData:!!(t||o)})})}function es(){const t=go(),{snack:o,handleSnackClose:n}=t;return e.jsxs(r.Box,{sx:{minHeight:"100vh"},children:[e.jsx(r.Box,{component:"main",children:t.activeReport?e.jsx(Xi,{reportEngine:t}):e.jsx(Vi,{title:"No report data",description:"This viewer requires report data to be loaded."})}),e.jsx(Zi,{open:o.open,message:o.message,severity:o.severity,onClose:n})]})}function Ru({data:t,autoLoad:o=!0,config:n}){return e.jsx(en,{data:t,mode:"viewer",autoLoad:o,config:n,children:e.jsx(es,{})})}exports.URMBuilder=Wu;exports.URMBuilderRaw=Qi;exports.URMProvider=en;exports.URMViewer=Ru;exports.URMViewerRaw=es;exports.useURMContext=go;
|