dts-universal-report-module 1.0.5 → 1.0.6
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 +9678 -8425
- 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"),os=require("xlsx"),k=require("@mui/icons-material"),r=require("@mui/material"),Fn=require("react-dom"),ns=require("@emotion/react"),St=require("react-dnd"),_o=require("react-dnd-html5-backend");function Ln(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 oo=Ln(p),Vr=Ln(os);function is(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 Vn(t,o="",n=0){if(n>2)return{[o]:t};const i={};for(const a of Object.keys(t)){const l=o?`${o}.${a}`:a,c=t[a];c!==null&&typeof c=="object"&&!Array.isArray(c)&&n<2?Object.assign(i,Vn(c,l,n+1)):i[l]=c}return i}function Kr(t){return t.map(o=>typeof o!="object"||o===null||Array.isArray(o)?o:Vn(o))}function Tr(t){if(!Array.isArray(t)||t.length===0)return[];const o=Kr(t),n=new Set;o.forEach(a=>{typeof a=="object"&&a!==null&&Object.keys(a).forEach(l=>n.add(l))});const i=[];return n.forEach(a=>{const l=new Set;let c=0;o.forEach(h=>{typeof h=="object"&&h!==null&&a in h&&(c++,l.add(is(h[a])))});const d=c===o.length,u=l.size>1&&!l.has("null");let f="mixed";if(l.size===1)f=Array.from(l)[0];else if(l.size===2&&l.has("null")){const h=Array.from(l).filter(m=>m!=="null");h.length===1&&(f=h[0])}i.push({name:a,type:f,required:d,hasConflict:u})}),i}function ss(t){return t.some(o=>o.hasConflict)}function ct(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 Xo(t){return t==null}function as(t){return(o,n,i)=>{const a=Xo(o),l=Xo(n);if(a&&l)return 0;if(a)return 1;if(l)return-1;let c=0;switch(t){case"number":const d=Number(o),u=Number(n);c=d-u;break;case"boolean":c=(o?1:0)-(n?1:0);break;case"string":c=String(o).localeCompare(String(n));break;case"array":case"object":c=JSON.stringify(o).localeCompare(JSON.stringify(n));break;case"mixed":case"null":default:c=String(o).localeCompare(String(n));break}return i==="asc"?c:-c}}function ls(t,o,n){if(!n||n.length===0)return t;const i=[...n].sort((a,l)=>a.priority-l.priority);return[...t].sort((a,l)=>{for(const c of i){const d=o.find(h=>h.name===c.column);if(!d)continue;const f=as(d.type)(a[c.column],l[c.column],c.direction);if(f!==0)return f}return 0})}function cs(t){return t===null?"asc":t==="asc"?"desc":null}function ds(t){return t==="string"||t==="boolean"}function us(t){return t.filter(o=>ds(o.type))}function ps(t,o){const n={};return o.forEach(i=>{if(i.type==="number"){const a=t.map(l=>l[i.name]).filter(l=>typeof l=="number");a.length>0&&(n[i.name]=a.reduce((l,c)=>l+c,0))}}),n}function xs(t,o,n){if(!n.enabled||n.levels.length===0)return t;const i=Hn(t,n.levels,o);return Un(i,n.collapsedGroups||[])}function Hn(t,o,n,i="",a=0){if(a>=o.length)return t;const l=o[a].column,c=new Map;t.forEach(f=>{const h=f[l],m=h==null?"(empty)":String(h);c.has(m)||c.set(m,[]),c.get(m).push(f)});const d=[];return Array.from(c.keys()).sort().forEach(f=>{const h=c.get(f),m=`${l}:${f}`,v=i?`${i}|${m}`:m,w=ps(h,n),z=a<o.length-1?Hn(h,o,n,v,a+1):h,y={key:v,level:a,column:l,value:f,rowCount:h.length,aggregates:w,children:z};d.push(y)}),d}function Un(t,o,n=[]){for(const i of t)if("key"in i&&"level"in i&&"children"in i){const a=o.includes(i.key);n.push({isGroupHeader:!0,groupKey:i.key,groupLevel:i.level,groupColumn:i.column,groupValue:i.value,rowCount:i.rowCount,aggregates:i.aggregates,isCollapsed:a}),!a&&i.children&&Un(i.children,o,n)}else n.push(i);return n}function fs(t,o){const n=t.collapsedGroups||[],i=n.includes(o)?n.filter(a=>a!==o):[...n,o];return{...t,collapsedGroups:i}}function Gn(t,o){return t==null?"":typeof t=="number"?`Σ ${t.toLocaleString()}`:String(t)}function Yn(t,o,n){return`${o}: ${n}`}function Br(t,o){if(!o||!o.enabled||!o.levels||o.levels.length===0)return[...t];const n=o.levels.map(a=>a.column),i=t.filter(a=>!n.includes(a));return[...n,...i]}function qn(t,o,n){if(!o||!o.enabled||!o.levels||o.levels.length===0)return[...t];const i=o.levels.map(l=>l.column),a=t.filter(l=>!i.includes(l));if(n){const l=[],c=new Set(i),d=new Set(a);let u=0;for(const f of n)c.has(f)?l.push(f):d.has(f)&&u<a.length?(l.push(a[u]),u++):d.has(f)||l.push(f);for(let f=u;f<a.length;f++)l.includes(a[f])||l.push(a[f]);return l}return[...t]}function jo(t){const o={},n=[],i={};return t.forEach(a=>{o[a.name]=!0,n.push(a.name),i[a.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 hs(t,o,n,i,a,l,c,d){const u={},f=[],h={};n.forEach(w=>{u[w.name]=!0,f.push(w.name),h[w.name]=150});const v=qn(a||f,c||null,d||f);return{filters:t||[],sortStack:o||[],columnVisibility:i||u,columnOrder:v,columnWidths:l||h,grouping:c||null}}function ms(t,o){const n=u=>{if(u==null)return u;if(Array.isArray(u))return u.map(f=>n(f));if(typeof u=="object"){const f={};return Object.keys(u).sort().forEach(h=>{f[h]=n(u[h])}),f}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 a=[...t.columnOrder||[]].sort().join(","),l=[...o.columnOrder||[]].sort().join(",");if(a!==l)return!1;const c=[...o.columnOrder||[]].sort().join(",");if((o.columnOrder||[]).join(",")!==c){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 gs(t){return!t||t.length===0?"None":t.sort((o,n)=>o.priority-n.priority).map(o=>`${o.column} ${o.direction==="asc"?"↑":"↓"}`).join(", ")}function ys(t,o){var y,j,b;const n=[],i=JSON.stringify(t.filters),a=JSON.stringify(o.filters);if(i!==a){const g=t.filters.length,S=o.filters.length;g>S?n.push({category:"filters",label:"Filters Added",description:`${g-S} new filter${g-S>1?"s":""} added`}):g<S?n.push({category:"filters",label:"Filters Removed",description:`${S-g} filter${S-g>1?"s":""} removed`}):n.push({category:"filters",label:"Filters Modified",description:"Filter conditions have been changed"})}const l=JSON.stringify(t.sortStack),c=JSON.stringify(o.sortStack);if(l!==c){const g=t.sortStack.length,S=o.sortStack.length;g>S?n.push({category:"sorting",label:"Sorting Added",description:`${g-S} new sort rule${g-S>1?"s":""} added`}):g<S?n.push({category:"sorting",label:"Sorting Removed",description:`${S-g} sort rule${S-g>1?"s":""} removed`}):n.push({category:"sorting",label:"Sorting Modified",description:"Sort rules or order have been changed"})}const d=JSON.stringify(t.columnVisibility),u=JSON.stringify(o.columnVisibility);if(d!==u){const g=Object.values(t.columnVisibility).filter(s=>s).length,S=Object.values(o.columnVisibility).filter(s=>s).length;g>S?n.push({category:"visibility",label:"Columns Shown",description:`${g-S} column${g-S>1?"s":""} made visible`}):g<S?n.push({category:"visibility",label:"Columns Hidden",description:`${S-g} column${S-g>1?"s":""} hidden`}):n.push({category:"visibility",label:"Column Visibility Changed",description:"Column visibility settings have been modified"})}const f=JSON.stringify(t.columnOrder),h=JSON.stringify(o.columnOrder);f!==h&&n.push({category:"order",label:"Column Order Changed",description:"Columns have been reordered"});const m=JSON.stringify(t.columnWidths),v=JSON.stringify(o.columnWidths);if(m!==v){const g=Object.keys(t.columnWidths).filter(S=>t.columnWidths[S]!==o.columnWidths[S]).length;n.push({category:"widths",label:"Column Widths Adjusted",description:`${g} column width${g>1?"s":""} modified`})}const w=JSON.stringify(t.grouping),z=JSON.stringify(o.grouping);if(w!==z){const g=(y=t.grouping)==null?void 0:y.enabled,S=(j=o.grouping)==null?void 0:j.enabled;if(g&&!S){const s=((b=t.grouping)==null?void 0:b.levels.length)||0;n.push({category:"grouping",label:"Grouping Applied",description:`${s} grouping level${s>1?"s":""} added`})}else!g&&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 Qo(){try{return localStorage.getItem("urm:debug")==="true"}catch{return!1}}function Zo(t){return`[${t}]`}const Vt={warn(t,o,...n){Qo()&&console.warn(Zo(t),o,...n)},error(t,o,...n){Qo()&&console.error(Zo(t),o,...n)}},Jn="urm_report_";function bs(t,o){try{const n=`${Jn}${t}`;localStorage.setItem(n,JSON.stringify(o))}catch(n){Vt.error("urm:persistence","Failed to save report state",n)}}function vs(t){try{const o=`${Jn}${t}`,n=localStorage.getItem(o);return n?JSON.parse(n):null}catch(o){return Vt.error("urm:persistence","Failed to load report state",o),null}}function no(t,o,n=0){const i=[];for(const a of t){const l=o.includes(a.key);if(i.push({type:"group",key:a.key,level:n,column:a.column,value:a.value,rowCount:a.rowCount,aggregates:a.aggregates,collapsed:l}),!l&&a.children&&a.children.length>0){const c=a.children[0];if(Ss(c)){const d=a.children,u=no(d,o,n+1);i.push(...u)}else{const d=a.children;for(const u of d)i.push({type:"row",parentGroupKey:a.key,level:n+1,data:u})}}}return i}function Ss(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 Po(t){return t.filter(o=>o.type==="row").map(o=>o.type==="row"?o.data:null).filter(o=>o!==null)}function $o(t,o){const n=new Date,i=n.getFullYear(),a=String(n.getMonth()+1).padStart(2,"0"),l=String(n.getDate()).padStart(2,"0"),c=`${i}-${a}-${l}`;return`${t.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")}_${c}.${o}`}function Qr(t,o,n,i,a,l,c){let d,u;l?(d={...l},u=c||o.map(h=>h.name)):a?(d={...a.snapshot.columnVisibility},u=c||[...a.snapshot.columnOrder]):(d={},u=[],o.forEach(h=>{d[h.name]=!0,u.push(h.name)}));const f=Object.entries(d).filter(([h,m])=>!m).map(([h,m])=>h);return{data:t,schema:o,appliedFilters:n,appliedSortStack:i,columnVisibility:d,columnOrder:u,grouping:(a==null?void 0:a.snapshot.grouping)??null,hiddenColumns:f,viewMeta:a?{id:a.id,name:a.name,isDefault:a.isDefault}:void 0}}function Zr(t,o="export",n){const{data:i,columnOrder:a,grouping:l}=t,c=a.filter(m=>t.columnVisibility[m]);let d;if(l&&l.enabled){const m=no(i);d=Po(m)}else d=i;const u=c.join(","),f=d.map(m=>c.map(v=>{const w=m[v];if(w==null)return"";const z=String(w);return z.includes(",")||z.includes('"')||z.includes(`
|
|
2
|
-
`)?`"${z.replace(/"/g,'""')}"`:z}).join(",")),
|
|
3
|
-
`);Kn(h,$o(o,"csv"),"text/csv;charset=utf-8;")}function eo(t,o="export",n){const{data:i,columnOrder:a,grouping:l}=t,c=a.filter(m=>t.columnVisibility[m]);let d;if(l&&l.enabled){const m=no(i);d=Po(m)}else d=i;const u=[c,...d.map(m=>c.map(v=>m[v]??""))],f=Vr.utils.aoa_to_sheet(u),h=Vr.utils.book_new();Vr.utils.book_append_sheet(h,f,"Data"),Vr.writeFile(h,$o(o,"xlsx"))}function to(t,o="export",n){const{data:i,appliedFilters:a,appliedSortStack:l,viewMeta:c,hiddenColumns:d,columnOrder:u,grouping:f}=t;let h;if(f&&f.enabled){const w=no(i);h=Po(w)}else h=i;const m={meta:{exportedAt:new Date().toISOString(),reportName:o,view:(c==null?void 0:c.name)||"Default View",filters:a.map(w=>({field:w.column,operator:w.operator,value:w.value})),sortStack:l.map(w=>({field:w.column,direction:w.direction,priority:w.priority})),grouping:f||{},hiddenColumns:d,columnOrder:u,exportConfig:n||{scope:"visible"}},data:h},v=JSON.stringify(m,null,2);Kn(v,$o(o,"json"),"application/json;charset=utf-8;")}function Kn(t,o,n){const i=new Blob([t],{type:n}),a=URL.createObjectURL(i),l=document.createElement("a");l.href=a,l.download=o,document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(a)}const en=10;function Cs(t,o){const n=o.trim();if(!n)return t;const i=t.findIndex(l=>l.query.toLowerCase()===n.toLowerCase());let a;return i!==-1?a=[{...t[i],lastUsed:Date.now()},...t.slice(0,i),...t.slice(i+1)]:a=[{query:n,isFavourite:!1,lastUsed:Date.now()},...t],a.length>en&&(a=[...a].sort((c,d)=>c.isFavourite&&!d.isFavourite?-1:!c.isFavourite&&d.isFavourite?1:d.lastUsed-c.lastUsed).slice(0,en)),a}function js(t,o){return t.map(n=>n.query===o?{...n,isFavourite:!n.isFavourite}:n)}function ws(t,o){return t.filter(n=>n.query!==o)}function ks(t){const o=t.filter(i=>i.isFavourite).sort((i,a)=>a.lastUsed-i.lastUsed),n=t.filter(i=>!i.isFavourite).sort((i,a)=>a.lastUsed-i.lastUsed);return[...o,...n]}const Ts={owner:["view_report","edit_columns","edit_filters","edit_sorting","edit_views","create_views","delete_views","delete_report","export_data"],editor:["view_report","edit_columns","edit_filters","edit_sorting","edit_views","create_views","delete_views","export_data"],viewer:["view_report","export_data"]};function zs(t,o){return!t||t.owner===o?"owner":t.editors.includes(o)?"editor":(t.viewers.includes(o),"viewer")}function mt(t,o){return Ts[o].includes(t)}function gt(t){return`You do not have permission to ${{view_report:"view this report",edit_columns:"modify columns",edit_filters:"modify filters",edit_sorting:"modify sorting",edit_views:"edit views",create_views:"create views",delete_views:"delete views",delete_report:"delete this report",export_data:"export data"}[t]||"perform this action"}.`}function Is(t){return t==="viewer"}const tn=1e3;function Es(){return`EVT_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Xn(t,o,n,i,a,l){return{id:Es(),user:o,reportId:t,feature:n,action:i,timestamp:new Date().toISOString(),previousState:a,newState:l}}function Qn(t,o){const n=[o,...t];return n.length>tn?n.slice(0,tn):n}function Ds(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 Bs(t){return{filters:"Filters",sorting:"Sorting",grouping:"Grouping",columns:"Columns",views:"Views",theme:"Theme",export:"Export",presets:"Presets",system:"System"}[t]||t}function Os(t){return{filters:"bg-blue-100 text-blue-800 border-blue-200",sorting:"bg-purple-100 text-purple-800 border-purple-200",grouping:"bg-green-100 text-green-800 border-green-200",columns:"bg-orange-100 text-orange-800 border-orange-200",views:"bg-pink-100 text-pink-800 border-pink-200",theme:"bg-gray-100 text-gray-800 border-gray-200",export:"bg-cyan-100 text-cyan-800 border-cyan-200",presets:"bg-indigo-100 text-indigo-800 border-indigo-200",system:"bg-red-100 text-red-800 border-red-200"}[t]||"bg-gray-100 text-gray-800 border-gray-200"}function As(t){const o=new Date(t),i=new Date().getTime()-o.getTime(),a=Math.floor(i/6e4),l=Math.floor(i/36e5),c=Math.floor(i/864e5);return a<1?"Just now":a<60?`${a} minute${a>1?"s":""} ago`:l<24?`${l} hour${l>1?"s":""} ago`:c<7?`${c} day${c>1?"s":""} ago`:o.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}function rn(t){return t==null?"None":typeof t=="string"||typeof t=="number"||typeof t=="boolean"?String(t):JSON.stringify(t,null,2)}const on=100;function Ms(){return`preset_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function Ws(t){var l;const o=(l=t.views)==null?void 0:l.find(c=>c.id===t.activeViewId),n=o==null?void 0:o.snapshot.columnOrder,i=t.columnOrder||[],a=qn(i,t.grouping||null,n);return{filters:t.filters?[...t.filters]:[],sortStack:t.sortStack?[...t.sortStack]:[],columnVisibility:t.columnVisibility?{...t.columnVisibility}:{},columnOrder:a,columnWidths:t.columnWidths?{...t.columnWidths}:{},grouping:t.grouping?{...t.grouping}:null,activeViewId:t.activeViewId}}function Rs(t,o,n,i){return{id:Ms(),name:t,description:o,createdBy:n,createdAt:Date.now(),config:i}}function _s(t,o){const n=t||[];if(n.length>=on)throw new Error(`Maximum of ${on} presets reached. Please delete old presets first.`);return[...n,o]}function Ps(t,o){return(t||[]).filter(i=>i.id!==o)}function nn(t,o){if(t)return t.find(n=>n.id===o)}function $s(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("preset")}function Ns(t){const o=t.columnOrder,n=Br(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 Fs(t,o){return{totalRows:t.length,totalColumns:o.length}}const Ls={MAX_CACHE_ENTRIES:3};function Vs(t,o){let n=null;return function(...a){const l=()=>{n=null,t(...a)};n&&clearTimeout(n),n=setTimeout(l,o)}}class Hr{constructor(o=Ls.MAX_CACHE_ENTRIES){this.cache=new Map,this.maxEntries=o}get(o){const n=this.cache.get(o);return n?n.value:null}set(o,n){var i;if(this.cache.size>=this.maxEntries&&!this.cache.has(o)){const a=(i=Array.from(this.cache.entries()).sort((l,c)=>l[1].timestamp-c[1].timestamp)[0])==null?void 0:i[0];a&&this.cache.delete(a)}this.cache.set(o,{key:o,value:n,timestamp:Date.now()})}has(o){return this.cache.has(o)}clear(){this.cache.clear()}size(){return this.cache.size}}class Hs{constructor(){this.metrics=new Map}start(o){this.metrics.set(o,performance.now())}end(o){const n=this.metrics.get(o);if(!n)return 0;const i=performance.now()-n;return this.metrics.delete(o),i}measure(o,n){this.start(o);const i=n(),a=this.end(o);return{result:i,duration:a}}async measureAsync(o,n){this.start(o);const i=await n(),a=this.end(o);return{result:i,duration:a}}}function vt(t,o,n,i){const a=n instanceof Error?n.message:n,l={type:t,context:o,message:a,details:i,timestamp:Date.now(),recoverable:Us(t,o)};return process.env.NODE_ENV==="development"&&Vt.error("urm:error-handling","[Report Error]",{type:t,context:o,message:a,details:i}),l}function Us(t,o){return t==="ui"||t==="processing"&&["filters","sorting","grouping","columns"].includes(o)?!0:t!=="system"}function Gs(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 Ys(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 qs(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 Js(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 Zn(t,o){const n=[],i=[],a=new Set(o.map(l=>l.name));return t.forEach(l=>{a.has(l.column)?n.push(l):i.push(l.column)}),{validRules:n,invalidColumns:i}}function ei(t,o){if(!t||!t.levels||t.levels.length===0)return{validGrouping:null,invalidColumns:[]};const n=new Set(o.map(l=>l.name)),i=[],a=[];return t.levels.forEach(l=>{n.has(l.column)?i.push(l):a.push(l.column)}),i.length===0?{validGrouping:null,invalidColumns:a}:{validGrouping:{...t,levels:i},invalidColumns:a}}function Ks(t,o){const n=[],i=new Set(o.map(l=>l.name)),a={...t};if(a.filters&&Array.isArray(a.filters)){const l=a.filters.filter(c=>{const d=i.has(c.column);return d||n.push(`Filter for column "${c.column}" ignored (column not found)`),d});a.filters=l.length>0?l:void 0}if(a.sortStack&&Array.isArray(a.sortStack)){const{validRules:l,invalidColumns:c}=Zn(a.sortStack,o);c.length>0&&n.push(`Sort rules for columns ignored: ${c.join(", ")}`),a.sortStack=l.length>0?l:void 0}if(a.grouping){const{validGrouping:l,invalidColumns:c}=ei(a.grouping,o);c.length>0&&n.push(`Grouping for columns ignored: ${c.join(", ")}`),a.grouping=l}if(a.columnVisibility){const l={};Object.entries(a.columnVisibility).forEach(([c,d])=>{i.has(c)?l[c]=d:n.push(`Column visibility for "${c}" ignored (column not found)`)}),a.columnVisibility=Object.keys(l).length>0?l:void 0}if(a.columnOrder&&Array.isArray(a.columnOrder)){const l=a.columnOrder.filter(c=>{const d=i.has(c);return d||n.push(`Column "${c}" in order ignored (column not found)`),d});a.columnOrder=l.length>0?l:void 0}if(a.columnWidths){const l={};Object.entries(a.columnWidths).forEach(([c,d])=>{i.has(c)?l[c]=d:n.push(`Column width for "${c}" ignored (column not found)`)}),a.columnWidths=Object.keys(l).length>0?l:void 0}return{sanitizedConfig:a,warnings:n}}function Xs(t,o){return vt("processing","export",t,{retryAvailable:!!(o!=null&&o.onRetry)})}function sn(t,o,n,i){const a=Xn(t,o,"system","error_occurred",null,{errorType:n.type,errorContext:n.context,errorMessage:n.message,recoverable:n.recoverable,timestamp:n.timestamp});return Qn(i||[],a)}function Qs(t){return t==null}function Zs(t,o){const{operator:n,value:i}=o;if(n==="NULL")return t==null;if(n==="NOT_NULL")return t!=null;if(Qs(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 ea(t,o){return!o||o.length===0?t:t.filter(n=>o.every(i=>Zs(n[i.column],i)))}function an(t){switch(t){case"string":return[{value:"equals",label:"Equals"},{value:"contains",label:"Contains"},{value:"startsWith",label:"Starts with"},{value:"endsWith",label:"Ends with"},{value:"NULL",label:"Is NULL"},{value:"NOT_NULL",label:"Is NOT NULL"}];case"number":return[{value:"equals",label:"="},{value:"gt",label:">"},{value:"lt",label:"<"},{value:"gte",label:"≥"},{value:"lte",label:"≤"}];case"boolean":return[{value:"isTrue",label:"Is true"},{value:"isFalse",label:"Is false"},{value:"NULL",label:"Is NULL"},{value:"NOT_NULL",label:"Is NOT NULL"}];case"mixed":case"null":case"array":case"object":default:return[]}}function Ur(t){return t!=="isTrue"&&t!=="isFalse"&&t!=="NULL"&&t!=="NOT_NULL"}function ta({data:t,filters:o}){return{filteredData:p.useMemo(()=>!o||o.length===0?t:ea(t,o),[t,o])}}function ra(t,o,n,i){if(!n||n.trim()==="")return t;const a=n.toLowerCase().trim(),l=o.filter(c=>i.includes(c.name));return t.filter(c=>l.some(d=>{const u=c[d.name];return u==null?!1:String(u).toLowerCase().includes(a)}))}function oa({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 na({data:t,sortStack:o,schema:n}){return{sortedData:p.useMemo(()=>!o||o.length===0?t:ls(t,n,o),[t,o,n])}}function ia({data:t,grouping:o,schema:n}){const i=p.useMemo(()=>!o||!o.enabled||o.levels.length===0?t:xs(t,n,o),[t,o,n]),a=(o==null?void 0:o.enabled)&&((o==null?void 0:o.levels.length)||0)>0;return{groupedData:i,isGrouped:a}}function sa({schema:t,columnVisibility:o,columnOrder:n}){const i=p.useMemo(()=>n.filter(d=>o[d]!==!1),[n,o]),a=p.useMemo(()=>Object.entries(o).filter(([d,u])=>!u).map(([d,u])=>d),[o]),l=p.useMemo(()=>n.map(d=>t.find(f=>f.name===d)||{name:d,type:"string"}),[n,t]),c=p.useMemo(()=>i.map(d=>t.find(f=>f.name===d)||{name:d,type:"string"}),[i,t]);return{visibleColumns:i,hiddenColumns:a,allColumns:l,visibleColumnSchemas:c,hiddenCount:a.length}}function aa({views:t,activeViewId:o,currentState:n}){const i=p.useMemo(()=>t.find(f=>f.id===o),[t,o]),a=p.useMemo(()=>i?ms(n,i.snapshot):!1,[i,n]),l=p.useMemo(()=>t.find(f=>f.isDefault),[t]),c=p.useMemo(()=>t.filter(f=>!f.isDefault&&!f.isDeleted),[t]),d=p.useMemo(()=>t.filter(f=>f.isFavorite&&!f.isDeleted),[t]),u=p.useMemo(()=>t.filter(f=>f.isDeleted),[t]);return{activeView:i,isDirty:a,defaultView:l,customViews:c,favoriteViews:d,deletedViews:u,isDefaultView:(i==null?void 0:i.isDefault)||!1}}function la({data:t,enabled:o=!1,pageSize:n=100,initialPage:i=1}){const[a,l]=p.useState(i),c=t.length,d=Math.ceil(c/n),u=p.useMemo(()=>{if(!o)return t;const w=(a-1)*n,z=w+n;return t.slice(w,z)},[t,o,a,n]),f=p.useCallback(w=>{const z=Math.max(1,Math.min(w,d));l(z)},[d]),h=p.useCallback(()=>{a<d&&l(a+1)},[a,d]),m=p.useCallback(()=>{a>1&&l(a-1)},[a]),v=p.useCallback(()=>{l(1)},[]);return{paginatedData:u,currentPage:a,totalPages:d,pageSize:n,totalRows:c,goToPage:f,nextPage:h,prevPage:m,resetPage:v,hasNextPage:a<d,hasPrevPage:a>1}}function ca(t){const{rawData:o,schema:n,filters:i,sortStack:a,grouping:l,searchQuery:c,columnVisibility:d,columnOrder:u,columnWidths:f,views:h,activeViewId:m,pagination:v}=t,w=p.useMemo(()=>({filters:i,sortStack:a,grouping:l,columnVisibility:d,columnOrder:u,columnWidths:f}),[i,a,l,d,u,f]),z=aa({views:h,activeViewId:m,currentState:w}),y=sa({schema:n,columnVisibility:d,columnOrder:u}),{filteredData:j}=ta({data:o,filters:i}),{sortedData:b}=na({data:j,sortStack:a,schema:n}),{groupedData:g,isGrouped:S}=ia({data:b,grouping:l,schema:n}),{searchedData:s}=oa({data:g,searchQuery:c,schema:n,visibleColumns:y.visibleColumns}),I=la({data:s,enabled:(v==null?void 0:v.enabled)||!1,pageSize:(v==null?void 0:v.pageSize)||100,initialPage:(v==null?void 0:v.currentPage)||1}),A=v!=null&&v.enabled?I.paginatedData:s,H=p.useMemo(()=>({totalRows:o.length,filteredRows:j.length,sortedRows:b.length,groupedRows:S?g.length:b.length,searchedRows:s.length,visibleRows:A.length,hiddenColumns:y.hiddenCount,activeFilters:i.length,activeSorts:a.length,isGrouped:S}),[o.length,j.length,b.length,g.length,s.length,A.length,y.hiddenCount,i.length,a.length,S]);return{data:A,filteredData:j,sortedData:b,groupedData:g,searchedData:s,viewEngine:z,columnEngine:y,paginationEngine:I,metrics:H,isGrouped:S,isPaginated:(v==null?void 0:v.enabled)||!1}}let da=0;function ua(t){t!=null&&t.__urm_row_id__===void 0&&Object.defineProperty(t,"__urm_row_id__",{value:da++,writable:!1,enumerable:!1,configurable:!1})}const yt="user-demo-001";function pa(t={}){var Go,Yo,qo,Jo,Ko;const{mode:o="builder",autoLoad:n=!0,initialData:i,dataSource:a,reportName:l,sharedReportId:c,config:d={}}=t,[u,f]=p.useState([]),[h,m]=p.useState(""),[v,w]=p.useState(!1),[z,y]=p.useState(!1),[j,b]=p.useState({message:"",severity:"info",open:!1}),g=(C,T="info")=>{b({message:C,severity:T,open:!0})},S=()=>b(C=>({...C,open:!1})),s=u.find(C=>C.id===h),[I,A]=p.useState("idle"),[H,N]=p.useState(!1),[K,te]=p.useState(!1),[se,x]=p.useState(!1),[V,$]=p.useState(!1),[J,oe]=p.useState(!1),[ue,pe]=p.useState(!1),[_,O]=p.useState(void 0),[L,re]=p.useState(null),[Q,X]=p.useState(null),[ae,Z]=p.useState(!1),[W,ee]=p.useState(!1),[ie,ne]=p.useState(null),[ke,U]=p.useState(!1),[Oe,Le]=p.useState(!1),[dt,$r]=p.useState({enabled:!1,levels:[],collapsedGroups:[]}),[Re,jt]=p.useState(""),[Ae,Ge]=p.useState(new Set),[Ke,Xe]=p.useState(1),[_e,wt]=p.useState(15),[Yt,rt]=p.useState(!1),[Qe,$e]=p.useState(!1),[dr,qt]=p.useState(!1),[ot,kt]=p.useState(null),[At,ut]=p.useState(!1),[ur,Nr]=p.useState(null),[Mt,pr]=p.useState(null);p.useRef(new Hs),p.useRef(new Hr),p.useRef(new Hr),p.useRef(new Hr),p.useRef(new Hr);const[Wt,Ze]=p.useState(null),Tt=p.useRef(null),je=p.useMemo(()=>s?zs(s.permissions,yt):"owner",[s]),xr=Is(je),zt=p.useMemo(()=>!(s!=null&&s.uploadedData)||!(s!=null&&s.schema)?{totalRows:0,totalColumns:0}:Fs(s.uploadedData,s.schema),[s==null?void 0:s.uploadedData,s==null?void 0:s.schema]),nt=p.useCallback(()=>{s&&(Tt.current=Ys(s))},[s]),P=p.useCallback((C,T)=>{f(B=>B.map(E=>E.id===C?{...E,...T}:E))},[]),et=p.useCallback(C=>{if(!s)return;Ze(C);const T=sn(s.id,yt,C,s.auditHistory||[]);P(s.id,{auditHistory:T}),g(C.message,"error"),C.recoverable&&Tt.current&&setTimeout(()=>{qs(s,Tt.current,P),g("Previous state restored","success")},100)},[s,P]),ge=p.useCallback((C,T,B,E)=>{if(!s)return;const q=Xn(s.id,yt,C,T,B,E),Y=s.auditHistory||[],ye=Qn(Y,q);setTimeout(()=>{P(s.id,{auditHistory:ye})},0)},[s,P]);p.useEffect(()=>{if(s!=null&&s.schemaLocked&&s.schema&&(!s.views||s.views.length===0)){const C=jo(s.schema);(()=>{try{const T=localStorage.getItem("urm_dev_config");return T?JSON.parse(T):null}catch{return null}})(),P(s.id,{views:[C],activeViewId:C.id,filters:C.snapshot.filters,sortStack:C.snapshot.sortStack,columnVisibility:C.snapshot.columnVisibility,columnOrder:C.snapshot.columnOrder,columnWidths:C.snapshot.columnWidths,grouping:C.snapshot.grouping})}},[s==null?void 0:s.schemaLocked,s==null?void 0:s.schema,s==null?void 0:s.id,P]),p.useEffect(()=>{if(i&&n&&!z&&u.length===0){const C=Kr(i),T={id:`auto-report-${Date.now()}`,name:l||(o==="viewer"?"Data View":"Imported Data"),description:"Auto-generated from external data",schemaLocked:!0,uploadedData:C,schema:Tr(C),permissions:{owner:yt,editors:[],viewers:[]}};f([T]),m(T.id),y(!0),A("confirmed")}},[i,n,z,u.length,o,l]),p.useEffect(()=>{if(!a||z)return;let C=!1,T=null;const B=async()=>{try{A("uploading");let E;if(a.type==="api"){const Y=await fetch(a.url,{headers:a.headers||{}});if(!Y.ok)throw new Error(`HTTP ${Y.status}: ${Y.statusText}`);E=await Y.json()}else E=await a.fetch();if(C)return;if(!Array.isArray(E))throw new Error("Data source must return an array of objects");const q=Tr(E);if(z)f(Y=>Y.map(ye=>ye.id===h?{...ye,uploadedData:E}:ye)),A("confirmed");else{const Y={id:`auto-report-${Date.now()}`,name:l||(o==="viewer"?"Data View":"Imported Data"),description:`Loaded from ${a.type==="api"?a.url:"callback"}`,schemaLocked:!0,uploadedData:Kr(E),schema:Tr(Kr(E)),permissions:{owner:yt,editors:[],viewers:[]}};f([Y]),m(Y.id),y(!0),A("confirmed")}}catch(E){C||(A("error"),s&&P(s.id,{uploadError:(E==null?void 0:E.message)||"Failed to load data from source"}))}};return B(),a.refreshInterval&&a.refreshInterval>0&&(T=setInterval(B,a.refreshInterval)),()=>{C=!0,T&&clearInterval(T)}},[a,l,o]);const Pe=(Go=s==null?void 0:s.views)==null?void 0:Go.find(C=>C.id===s.activeViewId),Rt=p.useMemo(()=>s!=null&&s.uploadedData?(s.uploadedData.forEach(ua),s.showFavoritesOnly?!s.favoriteRowIndices||s.favoriteRowIndices.length===0?[]:s.uploadedData.filter((C,T)=>s.favoriteRowIndices.includes(T)):s.uploadedData):[],[s==null?void 0:s.uploadedData,s==null?void 0:s.showFavoritesOnly,s==null?void 0:s.favoriteRowIndices]),fr=p.useMemo(()=>{var T;if(!(s!=null&&s.uploadedData)||!((T=s==null?void 0:s.favoriteRowIndices)!=null&&T.length))return new Set;const C=new Set;return s.favoriteRowIndices.forEach(B=>{const E=s.uploadedData[B];E!==void 0&&C.add(E)}),C},[s==null?void 0:s.uploadedData,s==null?void 0:s.showFavoritesOnly,s==null?void 0:s.favoriteRowIndices]),pt=ca({rawData:Rt,schema:(s==null?void 0:s.schema)||[],filters:(s==null?void 0:s.filters)||[],sortStack:(s==null?void 0:s.sortStack)||[],grouping:(s==null?void 0:s.grouping)||null,searchQuery:Re||"",columnVisibility:(s==null?void 0:s.columnVisibility)||(Pe==null?void 0:Pe.snapshot.columnVisibility)||{},columnOrder:(s==null?void 0:s.columnOrder)||(Pe==null?void 0:Pe.snapshot.columnOrder)||[],columnWidths:(s==null?void 0:s.columnWidths)||(Pe==null?void 0:Pe.snapshot.columnWidths)||{},views:(s==null?void 0:s.views)||[],activeViewId:(s==null?void 0:s.activeViewId)||"",pagination:{enabled:!0,pageSize:_e,currentPage:Ke}}),{data:hr=[],searchedData:Ye=[],groupedData:Jt=[],metrics:_t={totalRows:0,searchedRows:0,isGrouped:!1},isGrouped:Kt=!1,paginationEngine:Te}=pt||{},F=((Yo=pt.viewEngine)==null?void 0:Yo.activeView)||Pe,Me=((qo=pt.viewEngine)==null?void 0:qo.isDirty)||!1;p.useEffect(()=>{if(!(!F||!s)&&!s.columnOrder){const C=F.snapshot.columnOrder,T=Br(C,F.snapshot.grouping);P(s.id,{columnOrder:T})}},[s==null?void 0:s.activeViewId]);const Ce=p.useMemo(()=>!(s!=null&&s.schema)||!F?null:hs(s.filters||[],s.sortStack||[],s.schema,s.columnVisibility,s.columnOrder,s.columnWidths,s.grouping,F.snapshot.columnOrder),[s==null?void 0:s.filters,s==null?void 0:s.sortStack,s==null?void 0:s.schema,s==null?void 0:s.columnVisibility,s==null?void 0:s.columnOrder,s==null?void 0:s.columnWidths,s==null?void 0:s.grouping,F]),it=p.useMemo(()=>!F||!Ce||!Me?[]:ys(Ce,F.snapshot),[F,Ce,Me]),Ne=p.useCallback((C,T,B)=>{const E={id:`report-${Date.now()}`,name:C,description:T,schemaLocked:!1,permissions:{owner:yt,editors:[],viewers:[]}};if(B&&Array.isArray(B)&&B.length>0){const q=Tr(B),Y=jo(q);E.uploadedData=B,E.schema=q,E.schemaLocked=!0,E.views=[Y],E.activeViewId=Y.id,E.sortStack=Y.snapshot.sortStack,E.filters=Y.snapshot.filters,E.columnVisibility=Y.snapshot.columnVisibility,E.columnOrder=Y.snapshot.columnOrder,E.columnWidths=Y.snapshot.columnWidths,E.grouping=Y.snapshot.grouping}f(q=>[...q,E]),m(E.id),w(!1),A("confirmed")},[]),mr=p.useCallback(C=>{s&&(A("uploading"),setTimeout(()=>{const T=Tr(C);P(s.id,{uploadedData:C,schema:T,uploadError:void 0}),A("preview")},500))},[s,P]),gr=p.useCallback(C=>{s&&(P(s.id,{uploadError:C}),A("idle"))},[s,P]),Xt=p.useCallback(()=>{s&&(P(s.id,{uploadError:void 0,uploadedData:void 0,schema:void 0}),A("idle"))},[s,P]),yr=p.useCallback(()=>{s&&(P(s.id,{schemaLocked:!0}),A("confirmed"))},[s,P]),br=p.useCallback(C=>{if(!s)return;if(!mt("edit_sorting",je)){g(gt("edit_sorting"),"error");return}const T=s.sortStack??[],B=T.find(E=>E.column===C);if(B){const E=cs(B.direction);if(E===null){const q=T.filter(Y=>Y.column!==C).map((Y,ye)=>({...Y,priority:ye+1}));P(s.id,{sortStack:q.length>0?q:void 0})}else{const q=T.map(Y=>Y.column===C?{...Y,direction:E}:Y);P(s.id,{sortStack:q})}}else{if(T.length>=3)return;const E={column:C,direction:"asc",priority:T.length+1};P(s.id,{sortStack:[...T,E]})}},[s,je,P]),Qt=p.useCallback(C=>{if(s)if(s.schema){const{validRules:T,invalidColumns:B}=Zn(C,s.schema);B.length>0&&g(`Removed invalid sort columns: ${B.join(", ")}`),nt();try{P(s.id,{sortStack:T.length>0?T:void 0})}catch(E){const q=vt("processing","sorting",E);et(q)}}else P(s.id,{sortStack:C.length>0?C:void 0})},[s,P,nt,et]),Zt=p.useCallback(C=>{if(!s)return;const T=s.sortStack??[],B=T.find(E=>E.column===C);if(!(B&&B.direction==="asc"))if(B){const E=T.map(q=>q.column===C?{...q,direction:"asc"}:q);P(s.id,{sortStack:E})}else{if(T.length>=3)return;const E={column:C,direction:"asc",priority:T.length+1};P(s.id,{sortStack:[...T,E]})}},[s,P]),Ve=p.useCallback(C=>{if(!s)return;const T=s.sortStack??[],B=T.find(E=>E.column===C);if(!(B&&B.direction==="desc"))if(B){const E=T.map(q=>q.column===C?{...q,direction:"desc"}:q);P(s.id,{sortStack:E})}else{if(T.length>=3)return;const E={column:C,direction:"desc",priority:T.length+1};P(s.id,{sortStack:[...T,E]})}},[s,P]),st=p.useCallback(C=>{var B;if(!s)return;if(!mt("edit_filters",je)){g(gt("edit_filters"),"error");return}const T=(B=s.schema)==null?void 0:B.find(E=>E.name===C.column);if(T&&C.value!==void 0){const E=Js(T.type,C.operator,C.value);if(!E.isValid){g(E.errorMessage||"Invalid filter value","error");return}}nt();try{const E=s.filters??[];ge("filters","filter_added",E,[...E,C]),P(s.id,{filters:[...E,C]})}catch(E){const q=vt("processing","filters",E);et(q)}},[s,je,P,nt,et,ge]),Pt=p.useCallback((C,T)=>{if(!s)return;if(!mt("edit_filters",je)){g(gt("edit_filters"),"error");return}const B=s.filters??[],E=[...B];ge("filters","filter_updated",B[C],T),E[C]=T,P(s.id,{filters:E})},[s,je,P,ge]),It=p.useCallback(C=>{if(!s)return;if(!mt("edit_filters",je)){g(gt("edit_filters"),"error");return}const T=s.filters??[],B=T.filter((E,q)=>q!==C);ge("filters","filter_removed",T[C],null),P(s.id,{filters:B.length>0?B:void 0})},[s,je,P,ge]),xt=p.useCallback(()=>{if(!s)return;if(!mt("edit_filters",je)){g(gt("edit_filters"),"error");return}const C=s.filters??[];ge("filters","filter_cleared",C,null),P(s.id,{filters:void 0})},[s,je,P,ge]),at=p.useCallback(C=>{var q;if(!s)return;const T=(q=s.views)==null?void 0:q.find(Y=>Y.id===C);if(!T)return;const B=T.snapshot.columnOrder,E=Br(B,T.snapshot.grouping);P(s.id,{filters:T.snapshot.filters.length>0?[...T.snapshot.filters]:void 0,sortStack:T.snapshot.sortStack.length>0?[...T.snapshot.sortStack]:void 0,columnVisibility:{...T.snapshot.columnVisibility},columnOrder:E,columnWidths:{...T.snapshot.columnWidths},grouping:T.snapshot.grouping,activeViewId:C}),Ge(new Set),x(!1)},[s,P]),$t=p.useCallback((C,T,B)=>{if(!(s!=null&&s.schema)||!Ce)return;const E={id:`view-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:C,description:T||void 0,isDefault:B,isFavorite:!1,isDeleted:!1,createdAt:Date.now(),updatedAt:Date.now(),snapshot:{...Ce}},q=s.views??[],Y=B?q.map(ye=>({...ye,isDefault:!1})):q;P(s.id,{views:[...Y,E],activeViewId:E.id}),g(`"${C}" view created`,"success")},[s,Ce,P]),Nt=p.useCallback(()=>{var T;if(!F||!Ce||F.isDefault||!s)return;const C=(T=s.views)==null?void 0:T.map(B=>B.id===F.id?{...B,snapshot:{...Ce}}:B);P(s.id,{views:C}),g(`"${F.name}" view updated`,"success")},[F,Ce,s,P]),vr=p.useCallback(C=>{var E;if(!F||!Ce||!s)return;const T=C??Ce.columnWidths,B=(E=s.views)==null?void 0:E.map(q=>q.id===F.id?{...q,snapshot:{...q.snapshot,columnVisibility:Ce.columnVisibility,columnOrder:Ce.columnOrder,columnWidths:T},updatedAt:Date.now()}:q);P(s.id,{views:B,columnWidths:T}),g(`Column configuration saved to "${F.name}"`,"success")},[F,Ce,s,P]),Sr=p.useCallback(C=>{var Y,ye;if(!Ce||!s||!F)return;const T=C??Ce.columnWidths,B={...F,snapshot:{...F.snapshot,columnVisibility:Ce.columnVisibility,columnOrder:Ce.columnOrder,columnWidths:T},updatedAt:Date.now()},E=(Y=s.views)==null?void 0:Y.map(ze=>ze.id===F.id?B:{...ze,snapshot:{...ze.snapshot,columnVisibility:Ce.columnVisibility,columnOrder:Ce.columnOrder,columnWidths:T},updatedAt:Date.now()});P(s.id,{views:E,columnWidths:T});const q=(((ye=s.views)==null?void 0:ye.length)||0)-1;g(`Column configuration saved to current view and ${q} other view${q===1?"":"s"}`,"success")},[Ce,s,F,P]),Cr=p.useCallback(()=>{$(!0)},[]),jr=p.useCallback(()=>{if(!F||!s)return;const C=F.snapshot.columnOrder,T=Br(C,F.snapshot.grouping);P(s.id,{filters:F.snapshot.filters.length>0?[...F.snapshot.filters]:void 0,sortStack:F.snapshot.sortStack.length>0?[...F.snapshot.sortStack]:void 0,columnVisibility:{...F.snapshot.columnVisibility},columnOrder:T,columnWidths:{...F.snapshot.columnWidths},grouping:F.snapshot.grouping}),g("Changes reverted to last saved state","success")},[F,s,P]),er=p.useCallback(C=>{if(!(s!=null&&s.views))return;const T=s.views.map(E=>({...E,isDefault:E.id===C}));P(s.id,{views:T});const B=s.views.find(E=>E.id===C);B&&g(`"${B.name}" set as default view`,"success")},[s,P]),wr=p.useCallback(C=>{if(!(s!=null&&s.views))return;const T=s.views.map(E=>E.id===C?{...E,isFavorite:!E.isFavorite,updatedAt:Date.now()}:E);P(s.id,{views:T});const B=s.views.find(E=>E.id===C);B&&!B.isFavorite?g(`"${B.name}" added to favorites`,"success"):B&&g(`"${B.name}" removed from favorites`,"info")},[s,P]),Be=p.useCallback(C=>{if(!(s!=null&&s.views))return;const T=s.views.map(Y=>Y.id===C?{...Y,isDeleted:!0,updatedAt:Date.now()}:Y),B=s.activeViewId===C,E=T.find(Y=>Y.isDefault&&!Y.isDeleted);P(s.id,{views:T,activeViewId:B&&E?E.id:s.activeViewId,filters:B&&E?E.snapshot.filters.length>0?E.snapshot.filters:void 0:s.filters,sortStack:B&&E?E.snapshot.sortStack.length>0?E.snapshot.sortStack:void 0:s.sortStack});const q=s.views.find(Y=>Y.id===C);q&&g(`"${q.name}" moved to Recently Deleted`,"info")},[s,P]),ft=p.useCallback(C=>{if(!(s!=null&&s.views))return;const T=s.views.map(E=>E.id===C?{...E,isDeleted:!1,updatedAt:Date.now()}:E);P(s.id,{views:T});const B=s.views.find(E=>E.id===C);B&&g(`"${B.name}" restored`,"success")},[s,P]),tr=p.useCallback(C=>{if(!(s!=null&&s.views))return;const T=s.views.find(ze=>ze.id===C),B=s.views.filter(ze=>!ze.isDeleted||ze.id===C);if((T==null?void 0:T.isDefault)&&B.filter(ze=>ze.isDefault).length===1){g("Cannot delete the last default view","error");return}const q=s.views.filter(ze=>ze.id!==C),Y=s.activeViewId===C,ye=q.find(ze=>ze.isDefault&&!ze.isDeleted);P(s.id,{views:q,activeViewId:Y&&ye?ye.id:s.activeViewId,filters:Y&&ye?ye.snapshot.filters.length>0?ye.snapshot.filters:void 0:s.filters,sortStack:Y&&ye?ye.snapshot.sortStack.length>0?ye.snapshot.sortStack:void 0:s.sortStack}),T&&g(`"${T.name}" permanently deleted`,"success")},[s,P]),Fr=p.useCallback(C=>{re(C),oe(!0),x(!1)},[]),ht=p.useCallback((C,T)=>{if(!L||!(s!=null&&s.views))return;const B=s.views.map(E=>E.id===L?{...E,name:C,description:T||void 0}:E);P(s.id,{views:B}),re(null)},[L,s,P]),kr=p.useCallback(C=>{X(C),pe(!0),x(!1)},[]),rr=p.useCallback(()=>{if(!Q||!(s!=null&&s.views))return;const C=s.views.filter(E=>E.id!==Q),T=s.activeViewId===Q,B=C.find(E=>E.isDefault);P(s.id,{views:C,activeViewId:T&&B?B.id:s.activeViewId,filters:T&&B?B.snapshot.filters.length>0?B.snapshot.filters:void 0:s.filters,sortStack:T&&B?B.snapshot.sortStack.length>0?B.snapshot.sortStack:void 0:s.sortStack}),X(null),pe(!1)},[Q,s,P]);p.useEffect(()=>{if(!Re||!Re.trim())return;const C=Ye.filter(T=>!(T!=null&&T.isGroupHeader));C.length!==0&&Ge(new Set(C))},[Re,Ye]),p.useEffect(()=>{Te!=null&&Te.resetPage?Te.resetPage():Xe(1)},[s==null?void 0:s.filters,Re,s==null?void 0:s.activeViewId]),p.useEffect(()=>{Te&&Te.currentPage!==Ke&&Xe(Te.currentPage)},[Te==null?void 0:Te.currentPage]);const D=p.useCallback(C=>{Te!=null&&Te.goToPage&&Te.goToPage(C),Xe(C)},[Te]),G=p.useCallback(C=>{const T=(Ke-1)*_e,B=Math.floor(T/C)+1;wt(C),Xe(B)},[Ke,_e]),de=p.useCallback((C,T)=>{if(!s)return;if(!mt("edit_columns",je)){g(gt("edit_columns"),"error");return}const E={...s.columnVisibility||(F==null?void 0:F.snapshot.columnVisibility)||{},[C]:T};P(s.id,{columnVisibility:E})},[s,F,je,P]),We=p.useCallback(C=>{if(s){if(!mt("edit_columns",je)){g(gt("edit_columns"),"error");return}P(s.id,{columnOrder:C})}},[s,je,P]),le=p.useCallback((C,T)=>{if(!s)return;if(!mt("edit_columns",je)){g(gt("edit_columns"),"error");return}const E={...s.columnWidths||(F==null?void 0:F.snapshot.columnWidths)||{},[C]:T};P(s.id,{columnWidths:E})},[s,F,je,P]),ce=p.useCallback(C=>{if(!s)return;const B=(s.filters??[]).filter(E=>E.column!==C);P(s.id,{filters:B.length>0?B:void 0})},[s,P]),Se=p.useCallback(()=>{if(!F||!(s!=null&&s.schema))return;const C={},T=[],B={};s.schema.forEach(E=>{C[E.name]=!0,T.push(E.name),B[E.name]=150}),P(s.id,{columnVisibility:C,columnOrder:T,columnWidths:B,filters:void 0,sortStack:void 0}),g("Reset to default layout - all filters and sorts cleared","success")},[F,s,P]),Fe=p.useCallback(Vs(C=>{jt(C)},300),[]),So=p.useCallback(C=>{Fe(C)},[Fe]),Et=p.useCallback(C=>{if(!C.trim()||!s)return;const T=s.searchHistory||[],B=Cs(T,C);P(s.id,{searchHistory:B})},[s,P]),Co=p.useCallback(C=>{if(!s)return;const T=s.searchHistory||[],B=js(T,C);P(s.id,{searchHistory:B})},[s,P]),Bi=p.useCallback(C=>{if(!s)return;const T=s.searchHistory||[],B=ws(T,C);P(s.id,{searchHistory:B})},[s,P]),Oi=p.useCallback(C=>{Ge(T=>{const B=new Set(T);return B.has(C)?B.delete(C):B.add(C),B})},[]),Ai=p.useCallback((C,T)=>{Ge(B=>{const E=new Set(B);for(const q of T)C?E.add(q):E.delete(q);return E})},[]),Mi=p.useCallback((C,T,B)=>{Ge(E=>{const q=new Set(E),Y=Math.min(C,T),ye=Math.max(C,T);for(let ze=Y;ze<=ye;ze++)B[ze]!==void 0&&q.add(B[ze]);return q})},[]),Wi=p.useCallback(()=>{Ge(new Set)},[]),Ri=p.useCallback(C=>{Ge(T=>{const B=new Set(T);return B.delete(C),B})},[]),_i=p.useCallback(C=>{if(!(s!=null&&s.uploadedData))return;const T=s.uploadedData.indexOf(C);if(T===-1)return;const B=s.favoriteRowIndices||[],q=B.includes(T)?B.filter(Y=>Y!==T):[...B,T];P(s.id,{favoriteRowIndices:q})},[s,P]),Pi=p.useCallback((C,T)=>{if(!(s!=null&&s.uploadedData))return;const B=s.favoriteRowIndices||[],E=C.map(Y=>s.uploadedData.indexOf(Y)).filter(Y=>Y!==-1),q=T?[...B,...E.filter(Y=>!B.includes(Y))]:B.filter(Y=>!E.includes(Y));P(s.id,{favoriteRowIndices:q})},[s,P]),$i=p.useCallback(()=>{if(!s)return;const C=s.favoriteRowIndices||[],T=!s.showFavoritesOnly;if(T&&C.length===0){g("No rows marked as favorite","warning");return}P(s.id,{showFavoritesOnly:T}),Ge(new Set),g(T?`Showing ${C.length} favorite row${C.length===1?"":"s"}`:"Showing all data","info")},[s,P]),Ni=p.useCallback(C=>{if(s){if(!mt("edit_columns",je)){g(gt("edit_columns"),"error");return}if(C&&s.schema){const{validGrouping:T,invalidColumns:B}=ei(C,s.schema);B.length>0&&g(`Removed invalid grouping columns: ${B.join(", ")}`,"warning"),nt();try{const E=s.grouping;T===null?ge("grouping","group_cleared",E,null):E?ge("grouping","group_reordered",E,T):ge("grouping","group_level_added",null,T);const q=(F==null?void 0:F.snapshot.columnOrder)||s.columnOrder||[],Y=Br(q,T);P(s.id,{grouping:T,columnOrder:Y}),JSON.stringify(Y)!==JSON.stringify(s.columnOrder)&&ge("columns","column_reordered",s.columnOrder,Y),Le(!1)}catch(E){const q=vt("processing","grouping",E);et(q)}}else{const T=s.grouping;ge("grouping","group_cleared",T,null);const B=(F==null?void 0:F.snapshot.columnOrder)||s.columnOrder||[];P(s.id,{grouping:C,columnOrder:[...B]}),JSON.stringify(B)!==JSON.stringify(s.columnOrder)&&ge("columns","column_reordered",s.columnOrder,B),Le(!1)}}},[s,F,je,P,nt,et,ge]),Fi=p.useCallback(C=>{if(!s)return;const T=s.grouping;if(!T)return;const B=fs(T,C);P(s.id,{grouping:B})},[s,P]),Li=p.useCallback(()=>{ut(!0)},[]),or=p.useCallback(C=>{s!=null&&s.schema&&(Z(!0),setTimeout(()=>{try{let T;C.scope==="visible"?T=Ye:T=s.uploadedData||[];let B;C.columnScope==="all"?(B={},s.schema.forEach(ze=>{B[ze.name]=!0})):B=s.columnVisibility||(F==null?void 0:F.snapshot.columnVisibility)||{};const E=s.columnOrder||(F==null?void 0:F.snapshot.columnOrder),q=Qr(T,s.schema,s.filters??[],s.sortStack??[],F,B,E),Y=s.name;let ye;switch(C.format){case"csv":Zr(q,Y,C),ye="export_csv";break;case"excel":eo(q,Y,C),ye="export_excel";break;case"json":to(q,Y,C),ye="export_json";break}ge("export",ye,null,{format:C.format,scope:C.scope,columnScope:C.columnScope,rowCount:T.length,viewName:(F==null?void 0:F.name)||"Default View"}),g(`Export completed successfully (${C.format.toUpperCase()})`,"success")}catch(T){const B=Xs(T,{onRetry:()=>or(C)});g(`Export failed: ${B.message}`,{action:{label:"Retry",onClick:()=>or(C)}});const E=sn(s.id,yt,B,s.auditHistory||[]);P(s.id,{auditHistory:E}),Vt.error("urm:report-engine","Export failed",T)}finally{Z(!1)}},500))},[s,F,Ye,P,ge]),Vi=p.useCallback(C=>{if(s!=null&&s.schema){if(Me&&F&&!F.isDefault){ne(C.format),ee(!0),ut(!1);return}or(C),ut(!1)}},[s,F,Me,or]),Lr=p.useCallback(C=>{or({format:C,scope:"visible",columnScope:"visible"})},[or]),Hi=p.useCallback(()=>{ie&&Lr(ie),ee(!1),ne(null)},[ie,Lr]),Ui=p.useCallback(()=>{Nt(),ie&&Lr(ie),ee(!1),ne(null)},[Nt,ie,Lr]),Gi=p.useCallback(()=>{ee(!1),ne(null)},[]),Yi=p.useCallback(C=>{!(s!=null&&s.schema)||Ae.size===0||(Z(!0),setTimeout(()=>{try{const T=Array.from(Ae),B=Qr(T,s.schema,s.filters??[],s.sortStack??[],F),E=`${s.name.toLowerCase().replace(/\s+/g,"_")}_selected_export`;switch(C){case"csv":Zr(B,E);break;case"excel":eo(B,E);break;case"json":to(B,E);break}g(`Exported ${T.length} selected rows`,"info")}catch(T){g("Export failed. Please try again.","error"),Vt.error("urm:report-engine","Bulk export failed",T)}finally{Z(!1)}},500))},[s,F,Ae,Jt]),qi=p.useCallback((C,T)=>{if(s)try{const B=Ws(s),E=Rs(C,T,yt,B),q=_s(s.presets,E);P(s.id,{presets:q}),ge("presets","preset_created",null,{presetId:E.id,name:E.name}),$e(!1),g(`Preset "${C}" saved successfully`,"success")}catch(B){g(B instanceof Error?B.message:"Failed to create preset","error")}},[s,P,ge]),Ji=p.useCallback(()=>{kt(null),g("Exited preset view","info")},[]),Ki=p.useCallback(()=>{qt(!0)},[]),Xi=p.useCallback((C,T)=>{if(!s)return;const B=Ps(s.presets,C);P(s.id,{presets:B}),ge("presets","preset_deleted",{presetId:C,name:T},null),ot===C&&kt(null),g(`Preset "${T}" deleted`,"success")},[s,ot,P,ge]);p.useEffect(()=>{if(!c||u.length===0)return;const C=u.find(T=>T.id===c);C&&C.id!==h&&m(C.id)},[c,u,h]),p.useEffect(()=>{if(!s)return;const C=$s();if(C&&s.presets&&s.schemaLocked&&s.schema){const T=nn(s.presets,C);if(T){const{sanitizedConfig:B,warnings:E}=Ks(T.config,s.schema);E.length>0&&E.forEach(Y=>g(Y,"warning"));const q=Ns(B);P(s.id,q),kt(C),ge("presets","preset_applied",null,{presetId:T.id,name:T.name}),g(`Loaded preset: ${T.name}`,"info")}else g("Preset not found","info")}},[s==null?void 0:s.schemaLocked]);const Qi=ot?nn(s==null?void 0:s.presets,ot):void 0;p.useEffect(()=>{s!=null&&s.views&&s.views.length>0&&s.activeViewId&&bs(s.id,{views:s.views,activeViewId:s.activeViewId})},[s==null?void 0:s.views,s==null?void 0:s.activeViewId,s==null?void 0:s.id]),p.useEffect(()=>{if(s!=null&&s.schemaLocked&&s.schema&&(!s.views||s.views.length===0)){const C=vs(s.id);if(C&&C.views.length>0){const T=C.views.find(B=>B.id===C.activeViewId);if(T)P(s.id,{views:C.views,activeViewId:C.activeViewId,filters:T.snapshot.filters.length>0?T.snapshot.filters:void 0,sortStack:T.snapshot.sortStack.length>0?T.snapshot.sortStack:void 0});else{const B=C.views.find(E=>E.isDefault)||jo(s.schema);P(s.id,{views:C.views,activeViewId:B.id,filters:B.snapshot.filters.length>0?B.snapshot.filters:void 0,sortStack:B.snapshot.sortStack.length>0?B.snapshot.sortStack:void 0})}}}},[s==null?void 0:s.schemaLocked,s==null?void 0:s.schema,s==null?void 0:s.id]);const Zi=p.useCallback(C=>{O(C),N(!0)},[]),es=p.useCallback(()=>{N(!1),O(void 0)},[]),ts=(Jo=s==null?void 0:s.views)==null?void 0:Jo.find(C=>C.id===L),rs=(Ko=s==null?void 0:s.views)==null?void 0:Ko.find(C=>C.id===Q);return{reports:u,activeReport:s,activeReportId:h,setActiveReportId:m,isModalOpen:v,setIsModalOpen:w,createReport:Ne,updateReport:P,uploadState:I,handleFileUpload:mr,handleUploadError:gr,handleRetry:Xt,handleConfirm:yr,paginatedData:hr,processedData:Ye,displayData:Jt,tableMetrics:_t,isGrouped:Kt,tableEngine:pt,activeView:F,isDirty:Me,currentTableState:Ce,viewChanges:it,filters:s==null?void 0:s.filters,showFilterPanel:H,setShowFilterPanel:N,filterFocusColumn:_,handleAddFilter:st,handleUpdateFilter:Pt,handleRemoveFilter:It,handleClearAllFilters:xt,handleOpenFilterForColumn:Zi,handleCloseFilterPanel:es,handleClearFiltersForColumn:ce,sortStack:s==null?void 0:s.sortStack,showSortPanel:K,setShowSortPanel:te,handleSort:br,handleUpdateSortStack:Qt,handleSortAscending:Zt,handleSortDescending:Ve,views:s==null?void 0:s.views,showManageViews:se,setShowManageViews:x,showCreateViewModal:V,setShowCreateViewModal:$,showEditViewModal:J,setShowEditViewModal:oe,showDeleteConfirmation:ue,setShowDeleteConfirmation:pe,editingView:ts,deletingView:rs,editingViewId:L,deletingViewId:Q,handleSelectView:at,handleCreateView:$t,handleUpdateCurrentView:Nt,handleSaveColumnConfigToCurrentView:vr,handleSaveColumnConfigToAllViews:Sr,handleSaveAsNewView:Cr,handleRevertChanges:jr,handleToggleDefault:er,handleToggleFavorite:wr,handleSoftDelete:Be,handleRestoreView:ft,handlePermanentDelete:tr,handleEditView:Fr,handleSaveEditView:ht,handleDeleteView:kr,handleConfirmDelete:rr,showManageColumns:ke,setShowManageColumns:U,columnVisibility:s==null?void 0:s.columnVisibility,columnOrder:s==null?void 0:s.columnOrder,columnWidths:s==null?void 0:s.columnWidths,handleUpdateColumnVisibility:de,handleUpdateColumnOrder:We,handleUpdateColumnWidth:le,handleResetColumnLayout:Se,showGroupPanel:Oe,setShowGroupPanel:Le,grouping:s==null?void 0:s.grouping,groupingState:dt,handleGroup:Ni,handleToggleGroupCollapse:Fi,searchQuery:Re,searchHistory:ks((s==null?void 0:s.searchHistory)||[]),handleSearchChange:So,handleAddToSearchHistory:Et,handleToggleSearchFavourite:Co,handleDeleteSearchHistory:Bi,selectedRowIds:Ae,handleToggleRowSelection:Oi,handleToggleAllRows:Ai,handleRangeSelection:Mi,handleClearSelection:Wi,handleUpdateSelectionAfterDelete:Ri,favoriteRowIndices:(s==null?void 0:s.favoriteRowIndices)||[],resolvedFavoritesSet:fr,showFavoritesOnly:(s==null?void 0:s.showFavoritesOnly)||!1,handleToggleRowFavorite:_i,handleBulkSetFavorites:Pi,handleToggleFavoritesFilter:$i,currentPage:Ke,pageSize:_e,paginationEngine:Te,handlePageChange:D,handlePageSizeChange:G,isExporting:ae,showExportModal:At,setShowExportModal:ut,showDirtyExportWarning:W,handleExport:Li,handleExportWithConfig:Vi,handleExportSelected:Yi,handleExportAnyway:Hi,handleSaveAndExport:Ui,handleCancelExport:Gi,showAuditHistory:Yt,setShowAuditHistory:rt,auditHistory:s==null?void 0:s.auditHistory,showCreatePreset:Qe,setShowCreatePreset:$e,showManagePresets:dr,setShowManagePresets:qt,activePreset:Qi,activePresetId:ot,handleOpenManagePresets:Ki,handleCreatePreset:qi,handleClearActivePreset:Ji,handleDeletePresetById:Xi,userRole:je,isViewerRole:xr,currentUserId:yt,featureLimitWarning:Mt,setFeatureLimitWarning:pr,datasetMeta:zt,reportError:Wt,setReportError:Ze,handleError:et,schema:s==null?void 0:s.schema,hasSchemaConflicts:s!=null&&s.schema?ss(s.schema):!1,snack:j,handleSnackClose:S,showSnack:g}}const tt={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"]},display:{showDevPanel:!1}},ti="urm_dev_config";function xa(){try{const t=localStorage.getItem(ti);if(!t)return tt;const o=JSON.parse(t),n={sort:{...tt.sort,...o.sort},filter:{...tt.filter,...o.filter},columns:{...tt.columns,...o.columns},grouping:{...tt.grouping,...o.grouping},export:{...tt.export,...o.export},display:{...tt.display,...o.display}};return n.sort.maxLevels=Math.min(5,Math.max(1,n.sort.maxLevels)),n}catch{return tt}}function fa(t){try{localStorage.setItem(ti,JSON.stringify(t))}catch{}}function ha(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},display:{...t.display,...o.display}};return i.sort.maxLevels=Math.min(5,Math.max(1,i.sort.maxLevels)),i}const ri=p.createContext(tt);function Rr(){return p.useContext(ri)}const oi=p.createContext(void 0);function No(t){const{children:o,initialData:n,data:i,reportName:a,dataSource:l,mode:c="builder",autoLoad:d=!0,config:u,devConfig:f,showDevPanel:h=!1,sharedReportId:m}=t,w=pa({mode:c,autoLoad:d,initialData:i||n,dataSource:l,reportName:a,sharedReportId:m,config:u}),[z,y]=p.useState(()=>xa()),j=(()=>{const s=ha(z,f,!!f);return{...s,display:{...s.display,showDevPanel:h||s.display.showDevPanel}}})(),b=p.useCallback(S=>{y(S),fa(S)},[]),g={...w,activeDevConfig:j,handleDevConfigChange:b};return e.jsx(ri.Provider,{value:j,children:e.jsx(oi.Provider,{value:g,children:o})})}function io(){const t=p.useContext(oi);if(t===void 0)throw new Error("useReportContext must be used within a ReportProvider. Wrap your component tree with <ReportProvider>...</ReportProvider>");return t}function ma({onCreateReport:t,reports:o=[],activeReportId:n,onReportClick:i}){const a=o.find(l=>l.id===n);return e.jsx(r.Box,{component:"header",sx:{position:"sticky",top:0,zIndex:50,borderBottom:"1px solid",borderColor:"divider",bgcolor:"background.paper"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,height:64},children:[e.jsxs(r.Breadcrumbs,{separator:e.jsx(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&&a?"pointer":"default","&:hover":o.length>0&&a?{color:"primary.main"}:{}},onClick:()=>{o.length>0},children:"Reports"}),a&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"1.125rem",color:"primary.main",cursor:"pointer","&:hover":{textDecoration:"underline"}},onClick:()=>i==null?void 0:i(a.id),children:a.name}),e.jsx(r.Tooltip,{title:a.description||"No description",arrow:!0,placement:"bottom",children:e.jsx(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 Ht(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 ga="$$material";function ya(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Gr={exports:{}},Yr={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"),Ss=require("xlsx"),w=require("@mui/icons-material"),r=require("@mui/material"),ni=require("react-dom"),js=require("@emotion/react"),jt=require("react-dnd"),Yo=require("react-dnd-html5-backend");function ii(t){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(o,n,i.get?i:{enumerable:!0,get:()=>t[n]})}}return o.default=t,Object.freeze(o)}const po=ii(p),Kr=ii(Ss),Cs=/^\d{4}-\d{2}-\d{2}$/,ws=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/,ks=/^(\d{1,2})[\/\-\.](\d{1,2})[\/\-\.](\d{2,4})$|^([A-Za-z]+)\s+\d{1,2},?\s+\d{4}$/,Ts=9783072e5,zs=41024448e5,Is=978307200,Es=4102444800;function Bs(t){return t==null||t===""?"unknown":typeof t=="number"?Number.isInteger(t)&&t>=Ts&&t<=zs?"timestamp_ms":Number.isInteger(t)&&t>=Is&&t<=Es?"timestamp_s":"unknown":typeof t!="string"?"unknown":ws.test(t)||Cs.test(t)?"iso":ks.test(t.trim())?"locale_string":"unknown"}function Ds(t,o){const n=o.map(d=>d[t]).filter(d=>d!=null&&d!=="");if(n.length===0)return"unknown";const i={iso:0,timestamp_ms:0,timestamp_s:0,locale_string:0,unknown:0};for(const d of n){const l=Bs(d);i[l]++}const s=n.length,c=.7;for(const d of["iso","timestamp_ms","timestamp_s","locale_string"])if(i[d]/s>=c)return d;return"unknown"}function Os(t,o){if(t==null||t==="")return null;try{switch(o){case"timestamp_ms":{const n=new Date(Number(t));return isNaN(n.getTime())?null:n}case"timestamp_s":{const n=new Date(Number(t)*1e3);return isNaN(n.getTime())?null:n}case"iso":{const n=new Date(String(t));return isNaN(n.getTime())?null:n}case"locale_string":{const n=new Date(String(t));return isNaN(n.getTime())?null:n}default:return null}}catch{return null}}const ln=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Ms=["January","February","March","April","May","June","July","August","September","October","November","December"];function De(t){return String(t).padStart(2,"0")}function As(t){const o=Date.now()-t.getTime(),n=Math.abs(o),i=o>0,s=Math.floor(n/1e3),c=Math.floor(s/60),d=Math.floor(c/60),l=Math.floor(d/24),u=Math.floor(l/7),m=Math.floor(l/30),f=Math.floor(l/365);let b;return s<60?b="just now":c<60?b=`${c} minute${c!==1?"s":""}`:d<24?b=`${d} hour${d!==1?"s":""}`:l<7?b=`${l} day${l!==1?"s":""}`:u<5?b=`${u} week${u!==1?"s":""}`:m<12?b=`${m} month${m!==1?"s":""}`:b=`${f} year${f!==1?"s":""}`,s<60?b:i?`${b} ago`:`in ${b}`}function $s(t,o){const n=t.getFullYear(),i=t.getMonth(),s=t.getDate(),c=t.getHours(),d=t.getMinutes();switch(o){case"YYYY-MM-DD":return`${n}-${De(i+1)}-${De(s)}`;case"DD/MM/YYYY":return`${De(s)}/${De(i+1)}/${n}`;case"MM/DD/YYYY":return`${De(i+1)}/${De(s)}/${n}`;case"MMM DD, YYYY":return`${ln[i]} ${De(s)}, ${n}`;case"DD MMM YYYY":return`${De(s)} ${ln[i]} ${n}`;case"MMMM D, YYYY":return`${Ms[i]} ${s}, ${n}`;case"YYYY-MM-DD HH:mm":return`${n}-${De(i+1)}-${De(s)} ${De(c)}:${De(d)}`;case"DD/MM/YYYY HH:mm":return`${De(s)}/${De(i+1)}/${n} ${De(c)}:${De(d)}`;case"MM/DD/YYYY HH:mm":return`${De(i+1)}/${De(s)}/${n} ${De(c)}:${De(d)}`;case"relative":return As(t);case"locale":return t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"});default:return t.toLocaleDateString()}}function Rs(t,o,n){if(!n||o==="unknown")return String(t);const i=Os(t,o);return!i||isNaN(i.getTime())?String(t):$s(i,n)}function _s(t){return t==null?"null":Array.isArray(t)?"array":typeof t=="object"?"object":typeof t=="number"?"number":typeof t=="boolean"?"boolean":typeof t=="string"?"string":"mixed"}function si(t,o="",n=0){if(n>2)return{[o]:t};const i={};for(const s of Object.keys(t)){const c=o?`${o}.${s}`:s,d=t[s];d!==null&&typeof d=="object"&&!Array.isArray(d)&&n<2?Object.assign(i,si(d,c,n+1)):i[c]=d}return i}function no(t){return t.map(o=>typeof o!="object"||o===null||Array.isArray(o)?o:si(o))}function Rr(t){if(!Array.isArray(t)||t.length===0)return[];const o=no(t),n=new Set;o.forEach(d=>{typeof d=="object"&&d!==null&&Object.keys(d).forEach(l=>n.add(l))});const i=[];n.forEach(d=>{const l=new Set;let u=0;o.forEach(h=>{typeof h=="object"&&h!==null&&d in h&&(u++,l.add(_s(h[d])))});const m=u===o.length,f=l.size>1&&!l.has("null");let b="mixed";if(l.size===1)b=Array.from(l)[0];else if(l.size===2&&l.has("null")){const h=Array.from(l).filter(g=>g!=="null");h.length===1&&(b=h[0])}i.push({name:d,type:b,required:m,hasConflict:f})});const c=o.slice(0,50);for(const d of i){if(d.type!=="string"&&d.type!=="number")continue;const l=Ds(d.name,c);l!=="unknown"&&(d.type="date",d.dateFormat=l)}return i}function Ws(t){return t.some(o=>o.hasConflict)}function Ve(t){if(!t)return"";const n=t.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return n.charAt(0).toUpperCase()+n.slice(1)}function cn(t){return t==null}function Ps(t){return(o,n,i)=>{const s=cn(o),c=cn(n);if(s&&c)return 0;if(s)return 1;if(c)return-1;let d=0;switch(t){case"number":const l=Number(o),u=Number(n);d=l-u;break;case"boolean":d=(o?1:0)-(n?1:0);break;case"string":d=String(o).localeCompare(String(n));break;case"array":case"object":d=JSON.stringify(o).localeCompare(JSON.stringify(n));break;case"mixed":case"null":default:d=String(o).localeCompare(String(n));break}return i==="asc"?d:-d}}function Ns(t,o,n){if(!n||n.length===0)return t;const i=[...n].sort((s,c)=>s.priority-c.priority);return[...t].sort((s,c)=>{for(const d of i){const l=o.find(f=>f.name===d.column);if(!l)continue;const m=Ps(l.type)(s[d.column],c[d.column],d.direction);if(m!==0)return m}return 0})}function Fs(t){return t===null?"asc":t==="asc"?"desc":null}function Ls(t){return t==="string"||t==="boolean"}function Vs(t){return t.filter(o=>Ls(o.type))}function Hs(t,o){const n={};return o.forEach(i=>{if(i.type==="number"){const s=t.map(c=>c[i.name]).filter(c=>typeof c=="number");s.length>0&&(n[i.name]=s.reduce((c,d)=>c+d,0))}}),n}function Us(t,o,n){if(!n.enabled||n.levels.length===0)return t;const i=ai(t,n.levels,o);return li(i,n.collapsedGroups||[])}function ai(t,o,n,i="",s=0){if(s>=o.length)return t;const c=o[s].column,d=new Map;t.forEach(m=>{const f=m[c],b=f==null?"(empty)":String(f);d.has(b)||d.set(b,[]),d.get(b).push(m)});const l=[];return Array.from(d.keys()).sort().forEach(m=>{const f=d.get(m),b=`${c}:${m}`,h=i?`${i}|${b}`:b,g=Hs(f,n),z=s<o.length-1?ai(f,o,n,h,s+1):f,v={key:h,level:s,column:c,value:m,rowCount:f.length,aggregates:g,children:z};l.push(v)}),l}function li(t,o,n=[]){for(const i of t)if("key"in i&&"level"in i&&"children"in i){const s=o.includes(i.key);n.push({isGroupHeader:!0,groupKey:i.key,groupLevel:i.level,groupColumn:i.column,groupValue:i.value,rowCount:i.rowCount,aggregates:i.aggregates,isCollapsed:s}),!s&&i.children&&li(i.children,o,n)}else n.push(i);return n}function Ys(t,o){const n=t.collapsedGroups||[],i=n.includes(o)?n.filter(s=>s!==o):[...n,o];return{...t,collapsedGroups:i}}function ci(t,o){return t==null?"":typeof t=="number"?`Σ ${t.toLocaleString()}`:String(t)}function di(t,o,n){return`${o}: ${n}`}function Fr(t,o){if(!o||!o.enabled||!o.levels||o.levels.length===0)return[...t];const n=o.levels.map(s=>s.column),i=t.filter(s=>!n.includes(s));return[...n,...i]}function ui(t,o,n){if(!o||!o.enabled||!o.levels||o.levels.length===0)return[...t];const i=o.levels.map(c=>c.column),s=t.filter(c=>!i.includes(c));if(n){const c=[],d=new Set(i),l=new Set(s);let u=0;for(const m of n)d.has(m)?c.push(m):l.has(m)&&u<s.length?(c.push(s[u]),u++):l.has(m)||c.push(m);for(let m=u;m<s.length;m++)c.includes(s[m])||c.push(s[m]);return c}return[...t]}function Eo(t){const o={},n=[],i={};return t.forEach(s=>{o[s.name]=!0,n.push(s.name),i[s.name]=150}),{id:"default-view",name:"Default View",description:"Unfiltered, unsorted baseline view",isDefault:!0,snapshot:{filters:[],sortStack:[],columnVisibility:o,columnOrder:n,columnWidths:i,grouping:null}}}function Gs(t,o,n,i,s,c,d,l){const u={},m=[],f={};n.forEach(g=>{u[g.name]=!0,m.push(g.name),f[g.name]=150});const h=ui(s||m,d||null,l||m);return{filters:t||[],sortStack:o||[],columnVisibility:i||u,columnOrder:h,columnWidths:c||f,grouping:d||null}}function qs(t,o){const n=u=>{if(u==null)return u;if(Array.isArray(u))return u.map(m=>n(m));if(typeof u=="object"){const m={};return Object.keys(u).sort().forEach(f=>{m[f]=n(u[f])}),m}return u},i=u=>JSON.stringify(n(u));if(i(t.filters)!==i(o.filters)||i(t.sortStack)!==i(o.sortStack)||i(t.columnVisibility)!==i(o.columnVisibility))return!0;const s=[...t.columnOrder||[]].sort().join(","),c=[...o.columnOrder||[]].sort().join(",");if(s!==c)return!1;const d=[...o.columnOrder||[]].sort().join(",");if((o.columnOrder||[]).join(",")!==d){if((t.columnOrder||[]).join(",")!==(o.columnOrder||[]).join(","))return!0}else{const u=[...t.columnOrder||[]].sort().join(",");if((t.columnOrder||[]).join(",")!==u)return!0}return i(t.columnWidths)!==i(o.columnWidths)||i(t.grouping)!==i(o.grouping)}function Js(t){return!t||t.length===0?"None":t.sort((o,n)=>o.priority-n.priority).map(o=>`${o.column} ${o.direction==="asc"?"↑":"↓"}`).join(", ")}function Ks(t,o){var v,j,S;const n=[],i=JSON.stringify(t.filters),s=JSON.stringify(o.filters);if(i!==s){const y=t.filters.length,T=o.filters.length;y>T?n.push({category:"filters",label:"Filters Added",description:`${y-T} new filter${y-T>1?"s":""} added`}):y<T?n.push({category:"filters",label:"Filters Removed",description:`${T-y} filter${T-y>1?"s":""} removed`}):n.push({category:"filters",label:"Filters Modified",description:"Filter conditions have been changed"})}const c=JSON.stringify(t.sortStack),d=JSON.stringify(o.sortStack);if(c!==d){const y=t.sortStack.length,T=o.sortStack.length;y>T?n.push({category:"sorting",label:"Sorting Added",description:`${y-T} new sort rule${y-T>1?"s":""} added`}):y<T?n.push({category:"sorting",label:"Sorting Removed",description:`${T-y} sort rule${T-y>1?"s":""} removed`}):n.push({category:"sorting",label:"Sorting Modified",description:"Sort rules or order have been changed"})}const l=JSON.stringify(t.columnVisibility),u=JSON.stringify(o.columnVisibility);if(l!==u){const y=Object.values(t.columnVisibility).filter(a=>a).length,T=Object.values(o.columnVisibility).filter(a=>a).length;y>T?n.push({category:"visibility",label:"Columns Shown",description:`${y-T} column${y-T>1?"s":""} made visible`}):y<T?n.push({category:"visibility",label:"Columns Hidden",description:`${T-y} column${T-y>1?"s":""} hidden`}):n.push({category:"visibility",label:"Column Visibility Changed",description:"Column visibility settings have been modified"})}const m=JSON.stringify(t.columnOrder),f=JSON.stringify(o.columnOrder);m!==f&&n.push({category:"order",label:"Column Order Changed",description:"Columns have been reordered"});const b=JSON.stringify(t.columnWidths),h=JSON.stringify(o.columnWidths);if(b!==h){const y=Object.keys(t.columnWidths).filter(T=>t.columnWidths[T]!==o.columnWidths[T]).length;n.push({category:"widths",label:"Column Widths Adjusted",description:`${y} column width${y>1?"s":""} modified`})}const g=JSON.stringify(t.grouping),z=JSON.stringify(o.grouping);if(g!==z){const y=(v=t.grouping)==null?void 0:v.enabled,T=(j=o.grouping)==null?void 0:j.enabled;if(y&&!T){const a=((S=t.grouping)==null?void 0:S.levels.length)||0;n.push({category:"grouping",label:"Grouping Applied",description:`${a} grouping level${a>1?"s":""} added`})}else!y&&T?n.push({category:"grouping",label:"Grouping Removed",description:"All grouping has been cleared"}):n.push({category:"grouping",label:"Grouping Modified",description:"Grouping configuration has been changed"})}return n}function dn(){try{return localStorage.getItem("urm:debug")==="true"}catch{return!1}}function un(t){return`[${t}]`}const Ht={warn(t,o,...n){dn()&&console.warn(un(t),o,...n)},error(t,o,...n){dn()&&console.error(un(t),o,...n)}},pi="urm_report_";function Xs(t,o){try{const n=`${pi}${t}`;localStorage.setItem(n,JSON.stringify(o))}catch(n){Ht.error("urm:persistence","Failed to save report state",n)}}function Zs(t){try{const o=`${pi}${t}`,n=localStorage.getItem(o);return n?JSON.parse(n):null}catch(o){return Ht.error("urm:persistence","Failed to load report state",o),null}}function xo(t,o,n=0){const i=[];for(const s of t){const c=o.includes(s.key);if(i.push({type:"group",key:s.key,level:n,column:s.column,value:s.value,rowCount:s.rowCount,aggregates:s.aggregates,collapsed:c}),!c&&s.children&&s.children.length>0){const d=s.children[0];if(Qs(d)){const l=s.children,u=xo(l,o,n+1);i.push(...u)}else{const l=s.children;for(const u of l)i.push({type:"row",parentGroupKey:s.key,level:n+1,data:u})}}}return i}function Qs(t){return t&&typeof t=="object"&&"key"in t&&"level"in t&&"column"in t&&"value"in t&&"rowCount"in t&&"aggregates"in t&&"children"in t}function Go(t){return t.filter(o=>o.type==="row").map(o=>o.type==="row"?o.data:null).filter(o=>o!==null)}function qo(t,o){const n=new Date,i=n.getFullYear(),s=String(n.getMonth()+1).padStart(2,"0"),c=String(n.getDate()).padStart(2,"0"),d=`${i}-${s}-${c}`;return`${t.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")}_${d}.${o}`}function so(t,o,n,i,s,c,d){let l,u;c?(l={...c},u=d||o.map(f=>f.name)):s?(l={...s.snapshot.columnVisibility},u=d||[...s.snapshot.columnOrder]):(l={},u=[],o.forEach(f=>{l[f.name]=!0,u.push(f.name)}));const m=Object.entries(l).filter(([f,b])=>!b).map(([f,b])=>f);return{data:t,schema:o,appliedFilters:n,appliedSortStack:i,columnVisibility:l,columnOrder:u,grouping:(s==null?void 0:s.snapshot.grouping)??null,hiddenColumns:m,viewMeta:s?{id:s.id,name:s.name,isDefault:s.isDefault}:void 0}}function ao(t,o="export",n){const{data:i,columnOrder:s,grouping:c}=t,d=s.filter(b=>t.columnVisibility[b]);let l;if(c&&c.enabled){const b=xo(i);l=Go(b)}else l=i;const u=d.join(","),m=l.map(b=>d.map(h=>{const g=b[h];if(g==null)return"";const z=String(g);return z.includes(",")||z.includes('"')||z.includes(`
|
|
2
|
+
`)?`"${z.replace(/"/g,'""')}"`:z}).join(",")),f=[u,...m].join(`
|
|
3
|
+
`);xi(f,qo(o,"csv"),"text/csv;charset=utf-8;")}function lo(t,o="export",n){const{data:i,columnOrder:s,grouping:c}=t,d=s.filter(b=>t.columnVisibility[b]);let l;if(c&&c.enabled){const b=xo(i);l=Go(b)}else l=i;const u=[d,...l.map(b=>d.map(h=>b[h]??""))],m=Kr.utils.aoa_to_sheet(u),f=Kr.utils.book_new();Kr.utils.book_append_sheet(f,m,"Data"),Kr.writeFile(f,qo(o,"xlsx"))}function co(t,o="export",n){const{data:i,appliedFilters:s,appliedSortStack:c,viewMeta:d,hiddenColumns:l,columnOrder:u,grouping:m}=t;let f;if(m&&m.enabled){const g=xo(i);f=Go(g)}else f=i;const b={meta:{exportedAt:new Date().toISOString(),reportName:o,view:(d==null?void 0:d.name)||"Default View",filters:s.map(g=>({field:g.column,operator:g.operator,value:g.value})),sortStack:c.map(g=>({field:g.column,direction:g.direction,priority:g.priority})),grouping:m||{},hiddenColumns:l,columnOrder:u,exportConfig:n||{scope:"visible"}},data:f},h=JSON.stringify(b,null,2);xi(h,qo(o,"json"),"application/json;charset=utf-8;")}function xi(t,o,n){const i=new Blob([t],{type:n}),s=URL.createObjectURL(i),c=document.createElement("a");c.href=s,c.download=o,document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(s)}const pn=10;function ea(t,o){const n=o.trim();if(!n)return t;const i=t.findIndex(c=>c.query.toLowerCase()===n.toLowerCase());let s;return i!==-1?s=[{...t[i],lastUsed:Date.now()},...t.slice(0,i),...t.slice(i+1)]:s=[{query:n,isFavourite:!1,lastUsed:Date.now()},...t],s.length>pn&&(s=[...s].sort((d,l)=>d.isFavourite&&!l.isFavourite?-1:!d.isFavourite&&l.isFavourite?1:l.lastUsed-d.lastUsed).slice(0,pn)),s}function ta(t,o){return t.map(n=>n.query===o?{...n,isFavourite:!n.isFavourite}:n)}function ra(t,o){return t.filter(n=>n.query!==o)}function oa(t){const o=t.filter(i=>i.isFavourite).sort((i,s)=>s.lastUsed-i.lastUsed),n=t.filter(i=>!i.isFavourite).sort((i,s)=>s.lastUsed-i.lastUsed);return[...o,...n]}const na={owner:["view_report","edit_columns","edit_filters","edit_sorting","edit_views","create_views","delete_views","delete_report","export_data","promote_global_view"],editor:["view_report","edit_columns","edit_filters","edit_sorting","edit_views","create_views","delete_views","export_data"],viewer:["view_report","export_data"]};function ia(t,o){return!t||t.owner===o?"owner":t.editors.includes(o)?"editor":(t.viewers.includes(o),"viewer")}function st(t,o){return na[o].includes(t)}function at(t){return`You do not have permission to ${{view_report:"view this report",edit_columns:"modify columns",edit_filters:"modify filters",edit_sorting:"modify sorting",edit_views:"edit views",create_views:"create views",delete_views:"delete views",delete_report:"delete this report",export_data:"export data",promote_global_view:"promote views to global"}[t]||"perform this action"}.`}function sa(t){return t==="viewer"}const xn=1e3;function No(t){return t&&t.charAt(0).toUpperCase()+t.slice(1)}function ct(t){if(!t)return"";const n=t.replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,"$1 $2");return No(n)}const aa={equals:"equals",contains:"contains",startsWith:"starts with",endsWith:"ends with",gt:"is greater than",lt:"is less than",gte:"is greater than or equal to",lte:"is less than or equal to",isTrue:"is true",isFalse:"is false",NULL:"is empty",NOT_NULL:"is not empty"};function Bo(t){if(!t||!t.column)return"a filter";const o=ct(t.column),n=aa[t.operator]??t.operator;return["isTrue","isFalse","NULL","NOT_NULL"].includes(t.operator)?`"${o}" ${n}`:`"${o}" ${n} "${t.value}"`}function mn(t){return!t||!t.enabled||t.levels.length===0?"grouping removed":`grouped by ${t.levels.map(n=>`"${ct(n.column)}"`).join(", ")}`}function la(t){var s,c,d;const{action:o,previousState:n,newState:i}=t;switch(o){case"filter_added":{const l=i&&Array.isArray(i)?i[i.length-1]:i;return{summary:`Filter added: ${Bo(l)}`}}case"filter_removed":return{summary:`Filter removed: ${Bo(n)}`};case"filter_updated":{const l=n,u=i;return(l==null?void 0:l.column)!==(u==null?void 0:u.column)?{summary:`Filter changed on "${ct(u==null?void 0:u.column)}"`,detail:`Previously filtered "${ct(l==null?void 0:l.column)}"`}:{summary:`Filter updated: ${Bo(u)}`}}case"filter_cleared":{const l=Array.isArray(n)?n.length:0;return{summary:l>0?`All filters cleared (${l} filter${l!==1?"s":""} removed)`:"All filters cleared"}}case"sort_level_added":{const l=i!=null&&i.column?ct(i.column):"",u=(i==null?void 0:i.direction)==="asc"?"ascending":"descending";return{summary:l?`Sort added: "${l}" ${u}`:"Sort level added"}}case"sort_level_removed":{const l=n!=null&&n.column?ct(n.column):"";return{summary:l?`Sort removed: "${l}"`:"Sort level removed"}}case"sort_reordered":return{summary:"Sort order changed"};case"sort_cleared":return{summary:"All sorting cleared"};case"group_level_added":return{summary:`Grouping applied: ${mn(i)}`};case"group_level_removed":{const l=n,u=(c=(s=l==null?void 0:l.levels)==null?void 0:s[0])!=null&&c.column?ct(l.levels[0].column):"";return{summary:u?`Group level removed: "${u}"`:"Group level removed"}}case"group_reordered":return{summary:`Grouping updated: ${mn(i)}`};case"group_cleared":return{summary:"Grouping removed"};case"column_hidden":{const l=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:l?`Column hidden: "${ct(l)}"`:"Column hidden"}}case"column_shown":{const l=(i==null?void 0:i.column)??(typeof i=="string"?i:"");return{summary:l?`Column shown: "${ct(l)}"`:"Column made visible"}}case"column_reordered":{const l=Array.isArray(n)?n:[],u=Array.isArray(i)?i:[];return l.length>0&&u.length>0?{summary:"Column order changed",detail:`${u.length} column${u.length!==1?"s":""} reordered`}:{summary:"Columns reordered"}}case"column_resized":{const l=(i==null?void 0:i.column)??"",u=(i==null?void 0:i.width)??"";return{summary:l?`Column resized: "${ct(l)}"`:"Column resized",detail:u?`New width: ${u}px`:void 0}}case"view_created":{const l=(i==null?void 0:i.name)??(i==null?void 0:i.viewName)??"";return{summary:l?`View created: "${l}"`:"New view created"}}case"view_updated":{const l=(i==null?void 0:i.name)??(n==null?void 0:n.name)??"";return{summary:l?`View updated: "${l}"`:"View updated"}}case"view_deleted":{const l=(n==null?void 0:n.name)??(n==null?void 0:n.viewName)??"";return{summary:l?`View deleted: "${l}"`:"View deleted"}}case"view_set_default":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Default view set to "${l}"`:"Default view changed"}}case"view_switched":{const l=(n==null?void 0:n.name)??"",u=(i==null?void 0:i.name)??"";return l&&u?{summary:`Switched to view "${u}"`,detail:`From "${l}"`}:u?{summary:`Switched to view "${u}"`}:{summary:"View switched"}}case"export_csv":case"export_excel":case"export_json":{const l=o==="export_csv"?"CSV":o==="export_excel"?"Excel":"JSON",u=i==null?void 0:i.rowCount,m=(i==null?void 0:i.scope)==="all"?"all rows":"filtered rows",f=(i==null?void 0:i.viewName)??"",b=typeof u=="number"?` (${u.toLocaleString()} rows)`:"";return{summary:`Exported as ${l}${b}`,detail:f?`${No(m)} · View: "${f}"`:No(m)}}case"export_triggered":{const l=((d=i==null?void 0:i.format)==null?void 0:d.toUpperCase())??"";return{summary:l?`Export triggered: ${l}`:"Export triggered"}}case"preset_created":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset created: "${l}"`:"New preset created"}}case"preset_applied":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset applied: "${l}"`:"Preset applied"}}case"preset_deleted":{const l=(n==null?void 0:n.name)??"";return{summary:l?`Preset deleted: "${l}"`:"Preset deleted"}}case"preset_link_copied":{const l=(i==null?void 0:i.name)??"";return{summary:l?`Preset link copied: "${l}"`:"Preset link copied to clipboard"}}case"theme_changed":{const l=typeof n=="string"?n:(n==null?void 0:n.theme)??"",u=typeof i=="string"?i:(i==null?void 0:i.theme)??"";return l&&u?{summary:`Theme changed from "${l}" to "${u}"`}:u?{summary:`Theme changed to "${u}"`}:{summary:"Theme changed"}}case"error_occurred":{const l=(i==null?void 0:i.message)??(i==null?void 0:i.error)??typeof i=="string"?i:"";return{summary:"An error was recorded",detail:l?`Details: ${String(l).slice(0,120)}`:void 0}}default:return{summary:da(o)}}}function ca(){return`EVT_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function mi(t,o,n,i,s,c){return{id:ca(),user:o,reportId:t,feature:n,action:i,timestamp:new Date().toISOString(),previousState:s,newState:c}}function fi(t,o){const n=[o,...t];return n.length>xn?n.slice(0,xn):n}function da(t){return{filter_added:"Filter Added",filter_removed:"Filter Removed",filter_updated:"Filter Updated",filter_cleared:"All Filters Cleared",sort_level_added:"Sort Level Added",sort_level_removed:"Sort Level Removed",sort_reordered:"Sort Reordered",sort_cleared:"All Sorting Cleared",group_level_added:"Group Level Added",group_level_removed:"Group Level Removed",group_reordered:"Group Reordered",group_cleared:"All Grouping Cleared",column_hidden:"Column Hidden",column_shown:"Column Shown",column_reordered:"Columns Reordered",column_resized:"Column Resized",view_created:"View Created",view_updated:"View Updated",view_deleted:"View Deleted",view_set_default:"View Set as Default",view_switched:"View Switched",theme_changed:"Theme Changed",export_triggered:"Export Triggered",export_csv:"Exported as CSV",export_excel:"Exported as Excel",export_json:"Exported as JSON",preset_created:"Preset Created",preset_applied:"Preset Applied",preset_deleted:"Preset Deleted",preset_link_copied:"Preset Link Copied",error_occurred:"Error Occurred"}[t]||t}function ua(t){return{filters:"Filters",sorting:"Sorting",grouping:"Grouping",columns:"Columns",views:"Views",theme:"Theme",export:"Export",presets:"Presets",system:"System"}[t]||t}function pa(t){return{filters:"#1976d2",sorting:"#7b1fa2",grouping:"#2e7d32",columns:"#e65100",views:"#c2185b",theme:"#546e7a",export:"#00838f",presets:"#303f9f",system:"#c62828"}[t]||"#546e7a"}function xa(t){const o=new Date(t),i=new Date().getTime()-o.getTime(),s=Math.floor(i/6e4),c=Math.floor(i/36e5),d=Math.floor(i/864e5);return s<1?"Just now":s<60?`${s} minute${s>1?"s":""} ago`:c<24?`${c} hour${c>1?"s":""} ago`:d<7?`${d} day${d>1?"s":""} ago`:o.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}const fn=100;function ma(){return`preset_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function fa(t){var c;const o=(c=t.views)==null?void 0:c.find(d=>d.id===t.activeViewId),n=o==null?void 0:o.snapshot.columnOrder,i=t.columnOrder||[],s=ui(i,t.grouping||null,n);return{filters:t.filters?[...t.filters]:[],sortStack:t.sortStack?[...t.sortStack]:[],columnVisibility:t.columnVisibility?{...t.columnVisibility}:{},columnOrder:s,columnWidths:t.columnWidths?{...t.columnWidths}:{},grouping:t.grouping?{...t.grouping}:null,activeViewId:t.activeViewId}}function ha(t,o,n,i){return{id:ma(),name:t,description:o,createdBy:n,createdAt:Date.now(),config:i}}function ga(t,o){const n=t||[];if(n.length>=fn)throw new Error(`Maximum of ${fn} presets reached. Please delete old presets first.`);return[...n,o]}function ya(t,o){return(t||[]).filter(i=>i.id!==o)}function hn(t,o){if(t)return t.find(n=>n.id===o)}function ba(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("preset")}function va(t){const o=t.columnOrder,n=Fr(o,t.grouping);return{filters:t.filters.length>0?[...t.filters]:void 0,sortStack:t.sortStack.length>0?[...t.sortStack]:void 0,columnVisibility:{...t.columnVisibility},columnOrder:n,columnWidths:{...t.columnWidths},grouping:t.grouping?{...t.grouping}:null,activeViewId:t.activeViewId}}function Sa(t,o){return{totalRows:t.length,totalColumns:o.length}}const ja={MAX_CACHE_ENTRIES:3};function Ca(t,o){let n=null;return function(...s){const c=()=>{n=null,t(...s)};n&&clearTimeout(n),n=setTimeout(c,o)}}class Xr{constructor(o=ja.MAX_CACHE_ENTRIES){this.cache=new Map,this.maxEntries=o}get(o){const n=this.cache.get(o);return n?n.value:null}set(o,n){var i;if(this.cache.size>=this.maxEntries&&!this.cache.has(o)){const s=(i=Array.from(this.cache.entries()).sort((c,d)=>c[1].timestamp-d[1].timestamp)[0])==null?void 0:i[0];s&&this.cache.delete(s)}this.cache.set(o,{key:o,value:n,timestamp:Date.now()})}has(o){return this.cache.has(o)}clear(){this.cache.clear()}size(){return this.cache.size}}class wa{constructor(){this.metrics=new Map}start(o){this.metrics.set(o,performance.now())}end(o){const n=this.metrics.get(o);if(!n)return 0;const i=performance.now()-n;return this.metrics.delete(o),i}measure(o,n){this.start(o);const i=n(),s=this.end(o);return{result:i,duration:s}}async measureAsync(o,n){this.start(o);const i=await n(),s=this.end(o);return{result:i,duration:s}}}function St(t,o,n,i){const s=n instanceof Error?n.message:n,c={type:t,context:o,message:s,details:i,timestamp:Date.now(),recoverable:ka(t,o)};return process.env.NODE_ENV==="development"&&Ht.error("urm:error-handling","[Report Error]",{type:t,context:o,message:s,details:i}),c}function ka(t,o){return t==="ui"||t==="processing"&&["filters","sorting","grouping","columns"].includes(o)?!0:t!=="system"}function Ta(t){const n={filters:"There was an issue applying filters",sorting:"Sorting could not be applied",grouping:"Grouping configuration failed",columns:"Column configuration could not be updated",views:"View operation failed",presets:"Preset could not be applied",export:"Export failed",upload:"File upload failed",search:"Search operation failed"}[t.context]||"An error occurred";return t.recoverable?`${n}. Your previous state has been restored.`:`${n}. Please refresh the page.`}function za(t){return{filters:t.filters?[...t.filters]:void 0,sortStack:t.sortStack?[...t.sortStack]:void 0,grouping:t.grouping?{...t.grouping}:void 0,columnVisibility:t.columnVisibility?{...t.columnVisibility}:void 0,columnOrder:t.columnOrder?[...t.columnOrder]:void 0,columnWidths:t.columnWidths?{...t.columnWidths}:void 0,activeViewId:t.activeViewId}}function Ia(t,o,n){n(t.id,{filters:o.filters,sortStack:o.sortStack,grouping:o.grouping,columnVisibility:o.columnVisibility,columnOrder:o.columnOrder,columnWidths:o.columnWidths,activeViewId:o.activeViewId})}function Ea(t,o,n){return["equals","contains","starts_with","ends_with","gt","gte","lt","lte"].includes(o)&&(n==null||n==="")?{isValid:!1,errorMessage:"Value is required for this operator"}:t==="number"&&["gt","gte","lt","lte","equals"].includes(o)&&isNaN(Number(n))?{isValid:!1,errorMessage:"Value must be a valid number"}:t==="date"&&n&&isNaN(Date.parse(n))?{isValid:!1,errorMessage:"Value must be a valid date"}:{isValid:!0}}function hi(t,o){const n=[],i=[],s=new Set(o.map(c=>c.name));return t.forEach(c=>{s.has(c.column)?n.push(c):i.push(c.column)}),{validRules:n,invalidColumns:i}}function gi(t,o){if(!t||!t.levels||t.levels.length===0)return{validGrouping:null,invalidColumns:[]};const n=new Set(o.map(c=>c.name)),i=[],s=[];return t.levels.forEach(c=>{n.has(c.column)?i.push(c):s.push(c.column)}),i.length===0?{validGrouping:null,invalidColumns:s}:{validGrouping:{...t,levels:i},invalidColumns:s}}function Ba(t,o){const n=[],i=new Set(o.map(c=>c.name)),s={...t};if(s.filters&&Array.isArray(s.filters)){const c=s.filters.filter(d=>{const l=i.has(d.column);return l||n.push(`Filter for column "${d.column}" ignored (column not found)`),l});s.filters=c.length>0?c:void 0}if(s.sortStack&&Array.isArray(s.sortStack)){const{validRules:c,invalidColumns:d}=hi(s.sortStack,o);d.length>0&&n.push(`Sort rules for columns ignored: ${d.join(", ")}`),s.sortStack=c.length>0?c:void 0}if(s.grouping){const{validGrouping:c,invalidColumns:d}=gi(s.grouping,o);d.length>0&&n.push(`Grouping for columns ignored: ${d.join(", ")}`),s.grouping=c}if(s.columnVisibility){const c={};Object.entries(s.columnVisibility).forEach(([d,l])=>{i.has(d)?c[d]=l:n.push(`Column visibility for "${d}" ignored (column not found)`)}),s.columnVisibility=Object.keys(c).length>0?c:void 0}if(s.columnOrder&&Array.isArray(s.columnOrder)){const c=s.columnOrder.filter(d=>{const l=i.has(d);return l||n.push(`Column "${d}" in order ignored (column not found)`),l});s.columnOrder=c.length>0?c:void 0}if(s.columnWidths){const c={};Object.entries(s.columnWidths).forEach(([d,l])=>{i.has(d)?c[d]=l:n.push(`Column width for "${d}" ignored (column not found)`)}),s.columnWidths=Object.keys(c).length>0?c:void 0}return{sanitizedConfig:s,warnings:n}}function Da(t,o){return St("processing","export",t,{retryAvailable:!!(o!=null&&o.onRetry)})}function gn(t,o,n,i){const s=mi(t,o,"system","error_occurred",null,{errorType:n.type,errorContext:n.context,errorMessage:n.message,recoverable:n.recoverable,timestamp:n.timestamp});return fi(i||[],s)}function Oa(t){return t==null}function Ma(t,o){const{operator:n,value:i}=o;if(n==="NULL")return t==null;if(n==="NOT_NULL")return t!=null;if(Oa(t))return!1;switch(n){case"equals":return String(t)===String(i);case"contains":return String(t).toLowerCase().includes(String(i).toLowerCase());case"startsWith":return String(t).toLowerCase().startsWith(String(i).toLowerCase());case"endsWith":return String(t).toLowerCase().endsWith(String(i).toLowerCase());case"gt":return Number(t)>Number(i);case"lt":return Number(t)<Number(i);case"gte":return Number(t)>=Number(i);case"lte":return Number(t)<=Number(i);case"isTrue":return t===!0;case"isFalse":return t===!1;default:return!0}}function Aa(t,o){return!o||o.length===0?t:t.filter(n=>o.every(i=>Ma(n[i.column],i)))}function yn(t){switch(t){case"string":return[{value:"equals",label:"Equals"},{value:"contains",label:"Contains"},{value:"startsWith",label:"Starts with"},{value:"endsWith",label:"Ends with"},{value:"NULL",label:"Is NULL"},{value:"NOT_NULL",label:"Is NOT NULL"}];case"number":return[{value:"equals",label:"="},{value:"gt",label:">"},{value:"lt",label:"<"},{value:"gte",label:"≥"},{value:"lte",label:"≤"}];case"boolean":return[{value:"isTrue",label:"Is true"},{value:"isFalse",label:"Is false"},{value:"NULL",label:"Is NULL"},{value:"NOT_NULL",label:"Is NOT NULL"}];case"mixed":case"null":case"array":case"object":default:return[]}}function Zr(t){return t!=="isTrue"&&t!=="isFalse"&&t!=="NULL"&&t!=="NOT_NULL"}function $a({data:t,filters:o}){return{filteredData:p.useMemo(()=>!o||o.length===0?t:Aa(t,o),[t,o])}}function Ra(t,o,n,i){if(!n||n.trim()==="")return t;const s=n.toLowerCase().trim(),c=o.filter(d=>i.includes(d.name));return t.filter(d=>c.some(l=>{const u=d[l.name];return u==null?!1:String(u).toLowerCase().includes(s)}))}function _a({data:t,searchQuery:o,schema:n,visibleColumns:i}){return{searchedData:p.useMemo(()=>!o||o.trim()===""?t:Ra(t,n,o,i),[t,o,n,i])}}function Wa({data:t,sortStack:o,schema:n}){return{sortedData:p.useMemo(()=>!o||o.length===0?t:Ns(t,n,o),[t,o,n])}}function Pa({data:t,grouping:o,schema:n}){const i=p.useMemo(()=>!o||!o.enabled||o.levels.length===0?t:Us(t,n,o),[t,o,n]),s=(o==null?void 0:o.enabled)&&((o==null?void 0:o.levels.length)||0)>0;return{groupedData:i,isGrouped:s}}function Na({schema:t,columnVisibility:o,columnOrder:n}){const i=p.useMemo(()=>n.filter(l=>o[l]!==!1),[n,o]),s=p.useMemo(()=>Object.entries(o).filter(([l,u])=>!u).map(([l,u])=>l),[o]),c=p.useMemo(()=>n.map(l=>t.find(m=>m.name===l)||{name:l,type:"string"}),[n,t]),d=p.useMemo(()=>i.map(l=>t.find(m=>m.name===l)||{name:l,type:"string"}),[i,t]);return{visibleColumns:i,hiddenColumns:s,allColumns:c,visibleColumnSchemas:d,hiddenCount:s.length}}function Fa({views:t,activeViewId:o,currentState:n}){const i=p.useMemo(()=>t.find(m=>m.id===o),[t,o]),s=p.useMemo(()=>i?qs(n,i.snapshot):!1,[i,n]),c=p.useMemo(()=>t.find(m=>m.isDefault),[t]),d=p.useMemo(()=>t.filter(m=>!m.isDefault&&!m.isDeleted),[t]),l=p.useMemo(()=>t.filter(m=>m.isFavorite&&!m.isDeleted),[t]),u=p.useMemo(()=>t.filter(m=>m.isDeleted),[t]);return{activeView:i,isDirty:s,defaultView:c,customViews:d,favoriteViews:l,deletedViews:u,isDefaultView:(i==null?void 0:i.isDefault)||!1}}function La({data:t,enabled:o=!1,pageSize:n=100,initialPage:i=1}){const[s,c]=p.useState(i),d=t.length,l=Math.ceil(d/n),u=p.useMemo(()=>{if(!o)return t;const g=(s-1)*n,z=g+n;return t.slice(g,z)},[t,o,s,n]),m=p.useCallback(g=>{const z=Math.max(1,Math.min(g,l));c(z)},[l]),f=p.useCallback(()=>{s<l&&c(s+1)},[s,l]),b=p.useCallback(()=>{s>1&&c(s-1)},[s]),h=p.useCallback(()=>{c(1)},[]);return{paginatedData:u,currentPage:s,totalPages:l,pageSize:n,totalRows:d,goToPage:m,nextPage:f,prevPage:b,resetPage:h,hasNextPage:s<l,hasPrevPage:s>1}}function Va(t){const{rawData:o,schema:n,filters:i,sortStack:s,grouping:c,searchQuery:d,columnVisibility:l,columnOrder:u,columnWidths:m,views:f,activeViewId:b,pagination:h}=t,g=p.useMemo(()=>({filters:i,sortStack:s,grouping:c,columnVisibility:l,columnOrder:u,columnWidths:m}),[i,s,c,l,u,m]),z=Fa({views:f,activeViewId:b,currentState:g}),v=Na({schema:n,columnVisibility:l,columnOrder:u}),{filteredData:j}=$a({data:o,filters:i}),{sortedData:S}=Wa({data:j,sortStack:s,schema:n}),{groupedData:y,isGrouped:T}=Pa({data:S,grouping:c,schema:n}),{searchedData:a}=_a({data:y,searchQuery:d,schema:n,visibleColumns:v.visibleColumns}),k=La({data:a,enabled:(h==null?void 0:h.enabled)||!1,pageSize:(h==null?void 0:h.pageSize)||100,initialPage:(h==null?void 0:h.currentPage)||1}),D=h!=null&&h.enabled?k.paginatedData:a,O=p.useMemo(()=>({totalRows:o.length,filteredRows:j.length,sortedRows:S.length,groupedRows:T?y.length:S.length,searchedRows:a.length,visibleRows:D.length,hiddenColumns:v.hiddenCount,activeFilters:i.length,activeSorts:s.length,isGrouped:T}),[o.length,j.length,S.length,y.length,a.length,D.length,v.hiddenCount,i.length,s.length,T]);return{data:D,filteredData:j,sortedData:S,groupedData:y,searchedData:a,viewEngine:z,columnEngine:v,paginationEngine:k,metrics:O,isGrouped:T,isPaginated:(h==null?void 0:h.enabled)||!1}}let Ha=0;function Ua(t){t!=null&&t.__urm_row_id__===void 0&&Object.defineProperty(t,"__urm_row_id__",{value:Ha++,writable:!1,enumerable:!1,configurable:!1})}const bt="user-demo-001";function Ya(t={}){var rn,on,nn,sn,an;const{mode:o="builder",autoLoad:n=!0,initialData:i,dataSource:s,reportName:c,sharedReportId:d,config:l={}}=t,[u,m]=p.useState([]),[f,b]=p.useState(""),[h,g]=p.useState(!1),[z,v]=p.useState(!1),[j,S]=p.useState({message:"",severity:"info",open:!1}),y=(C,B="info")=>{S({message:C,severity:B,open:!0})},T=()=>S(C=>({...C,open:!1})),a=u.find(C=>C.id===f),[k,D]=p.useState("idle"),[O,R]=p.useState(!1),[U,J]=p.useState(!1),[ee,x]=p.useState(!1),[N,_]=p.useState(!1),[H,q]=p.useState(!1),[de,ue]=p.useState(!1),[re,M]=p.useState(void 0),[L,G]=p.useState(null),[oe,Q]=p.useState(null),[le,ne]=p.useState(!1),[P,te]=p.useState(!1),[ie,se]=p.useState(null),[je,Y]=p.useState(!1),[Oe,Ae]=p.useState(!1),[dt,br]=p.useState({enabled:!1,levels:[],collapsedGroups:[]}),[kt,Tt]=p.useState(""),[qe,_e]=p.useState(new Set),[Me,zt]=p.useState(1),[ut,pt]=p.useState(15),[Je,It]=p.useState(!1),[qt,Ke]=p.useState(!1),[Xe,We]=p.useState(!1),[xt,Mt]=p.useState(null),[Jt,mt]=p.useState(!1),[Kt,vr]=p.useState(null),[Xt,Zt]=p.useState(null);p.useRef(new wa),p.useRef(new Xr),p.useRef(new Xr),p.useRef(new Xr),p.useRef(new Xr);const[Qt,er]=p.useState(null),Ze=p.useRef(null),Ce=p.useMemo(()=>a?ia(a.permissions,bt):"owner",[a]),At=sa(Ce),Sr=p.useMemo(()=>!(a!=null&&a.uploadedData)||!(a!=null&&a.schema)?{totalRows:0,totalColumns:0}:Sa(a.uploadedData,a.schema),[a==null?void 0:a.uploadedData,a==null?void 0:a.schema]),Qe=p.useCallback(()=>{a&&(Ze.current=za(a))},[a]),F=p.useCallback((C,B)=>{m($=>$.map(A=>A.id===C?{...A,...B}:A))},[]),et=p.useCallback(C=>{if(!a)return;er(C);const B=gn(a.id,bt,C,a.auditHistory||[]);F(a.id,{auditHistory:B}),y(C.message,"error"),C.recoverable&&Ze.current&&setTimeout(()=>{Ia(a,Ze.current,F),y("Previous state restored","success")},100)},[a,F]),pe=p.useCallback((C,B,$,A)=>{if(!a)return;const Z=mi(a.id,bt,C,B,$,A),X=a.auditHistory||[],be=fi(X,Z);setTimeout(()=>{F(a.id,{auditHistory:be})},0)},[a,F]);p.useEffect(()=>{if(a!=null&&a.schemaLocked&&a.schema&&(!a.views||a.views.length===0)){const C=Eo(a.schema);(()=>{try{const B=localStorage.getItem("urm_dev_config");return B?JSON.parse(B):null}catch{return null}})(),F(a.id,{views:[C],activeViewId:C.id,filters:C.snapshot.filters,sortStack:C.snapshot.sortStack,columnVisibility:C.snapshot.columnVisibility,columnOrder:C.snapshot.columnOrder,columnWidths:C.snapshot.columnWidths,grouping:C.snapshot.grouping})}},[a==null?void 0:a.schemaLocked,a==null?void 0:a.schema,a==null?void 0:a.id,F]),p.useEffect(()=>{if(i&&n&&!z&&u.length===0){const C=no(i),B={id:`auto-report-${Date.now()}`,name:c||(o==="viewer"?"Data View":"Imported Data"),description:"Auto-generated from external data",schemaLocked:!0,uploadedData:C,schema:Rr(C),permissions:{owner:bt,editors:[],viewers:[]}};m([B]),b(B.id),v(!0),D("confirmed")}},[i,n,z,u.length,o,c]),p.useEffect(()=>{if(!s||z)return;let C=!1,B=null;const $=async()=>{try{D("uploading");let A;if(s.type==="api"){const X=await fetch(s.url,{headers:s.headers||{}});if(!X.ok)throw new Error(`HTTP ${X.status}: ${X.statusText}`);A=await X.json()}else A=await s.fetch();if(C)return;if(!Array.isArray(A))throw new Error("Data source must return an array of objects");const Z=Rr(A);if(z)m(X=>X.map(be=>be.id===f?{...be,uploadedData:A}:be)),D("confirmed");else{const X={id:`auto-report-${Date.now()}`,name:c||(o==="viewer"?"Data View":"Imported Data"),description:`Loaded from ${s.type==="api"?s.url:"callback"}`,schemaLocked:!0,uploadedData:no(A),schema:Rr(no(A)),permissions:{owner:bt,editors:[],viewers:[]}};m([X]),b(X.id),v(!0),D("confirmed")}}catch(A){C||(D("error"),a&&F(a.id,{uploadError:(A==null?void 0:A.message)||"Failed to load data from source"}))}};return $(),s.refreshInterval&&s.refreshInterval>0&&(B=setInterval($,s.refreshInterval)),()=>{C=!0,B&&clearInterval(B)}},[s,c,o]);const Pe=(rn=a==null?void 0:a.views)==null?void 0:rn.find(C=>C.id===a.activeViewId),Et=p.useMemo(()=>a!=null&&a.uploadedData?(a.uploadedData.forEach(Ua),a.showFavoritesOnly?!a.favoriteRowIndices||a.favoriteRowIndices.length===0?[]:a.uploadedData.filter((C,B)=>a.favoriteRowIndices.includes(B)):a.uploadedData):[],[a==null?void 0:a.uploadedData,a==null?void 0:a.showFavoritesOnly,a==null?void 0:a.favoriteRowIndices]),jr=p.useMemo(()=>{var B;if(!(a!=null&&a.uploadedData)||!((B=a==null?void 0:a.favoriteRowIndices)!=null&&B.length))return new Set;const C=new Set;return a.favoriteRowIndices.forEach($=>{const A=a.uploadedData[$];A!==void 0&&C.add(A)}),C},[a==null?void 0:a.uploadedData,a==null?void 0:a.showFavoritesOnly,a==null?void 0:a.favoriteRowIndices]),ot=Va({rawData:Et,schema:(a==null?void 0:a.schema)||[],filters:(a==null?void 0:a.filters)||[],sortStack:(a==null?void 0:a.sortStack)||[],grouping:(a==null?void 0:a.grouping)||null,searchQuery:kt||"",columnVisibility:(a==null?void 0:a.columnVisibility)||(Pe==null?void 0:Pe.snapshot.columnVisibility)||{},columnOrder:(a==null?void 0:a.columnOrder)||(Pe==null?void 0:Pe.snapshot.columnOrder)||[],columnWidths:(a==null?void 0:a.columnWidths)||(Pe==null?void 0:Pe.snapshot.columnWidths)||{},views:(a==null?void 0:a.views)||[],activeViewId:(a==null?void 0:a.activeViewId)||"",pagination:{enabled:!0,pageSize:ut,currentPage:Me}}),{data:tr=[],searchedData:ft=[],groupedData:$t=[],metrics:rr={totalRows:0,searchedRows:0,isGrouped:!1},isGrouped:Cr=!1,paginationEngine:ke}=ot||{},K=((on=ot.viewEngine)==null?void 0:on.activeView)||Pe,nt=((nn=ot.viewEngine)==null?void 0:nn.isDirty)||!1;p.useEffect(()=>{if(!(!K||!a)&&!a.columnOrder){const C=K.snapshot.columnOrder,B=Fr(C,K.snapshot.grouping);F(a.id,{columnOrder:B})}},[a==null?void 0:a.activeViewId]);const ye=p.useMemo(()=>!(a!=null&&a.schema)||!K?null:Gs(a.filters||[],a.sortStack||[],a.schema,a.columnVisibility,a.columnOrder,a.columnWidths,a.grouping,K.snapshot.columnOrder),[a==null?void 0:a.filters,a==null?void 0:a.sortStack,a==null?void 0:a.schema,a==null?void 0:a.columnVisibility,a==null?void 0:a.columnOrder,a==null?void 0:a.columnWidths,a==null?void 0:a.grouping,K]),or=p.useMemo(()=>!K||!ye||!nt?[]:Ks(ye,K.snapshot),[K,ye,nt]),fe=p.useCallback((C,B,$)=>{const A={id:`report-${Date.now()}`,name:C,description:B,schemaLocked:!1,permissions:{owner:bt,editors:[],viewers:[]}};if($&&Array.isArray($)&&$.length>0){const Z=Rr($),X=Eo(Z);A.uploadedData=$,A.schema=Z,A.schemaLocked=!0,A.views=[X],A.activeViewId=X.id,A.sortStack=X.snapshot.sortStack,A.filters=X.snapshot.filters,A.columnVisibility=X.snapshot.columnVisibility,A.columnOrder=X.snapshot.columnOrder,A.columnWidths=X.snapshot.columnWidths,A.grouping=X.snapshot.grouping}m(Z=>[...Z,A]),b(A.id),g(!1),D("confirmed")},[]),tt=p.useCallback(C=>{a&&(D("uploading"),setTimeout(()=>{const B=Rr(C);F(a.id,{uploadedData:C,schema:B,uploadError:void 0}),D("preview")},500))},[a,F]),wr=p.useCallback(C=>{a&&(F(a.id,{uploadError:C}),D("idle"))},[a,F]),it=p.useCallback(()=>{a&&(F(a.id,{uploadError:void 0,uploadedData:void 0,schema:void 0}),D("idle"))},[a,F]),Re=p.useCallback(()=>{a&&(F(a.id,{schemaLocked:!0}),D("confirmed"))},[a,F]),nr=p.useCallback(C=>{if(!a)return;if(!st("edit_sorting",Ce)){y(at("edit_sorting"),"error");return}const B=a.sortStack??[],$=B.find(A=>A.column===C);if($){const A=Fs($.direction);if(A===null){const Z=B.filter(X=>X.column!==C).map((X,be)=>({...X,priority:be+1}));F(a.id,{sortStack:Z.length>0?Z:void 0})}else{const Z=B.map(X=>X.column===C?{...X,direction:A}:X);F(a.id,{sortStack:Z})}}else{if(B.length>=3)return;const A={column:C,direction:"asc",priority:B.length+1};F(a.id,{sortStack:[...B,A]})}},[a,Ce,F]),kr=p.useCallback(C=>{if(a)if(a.schema){const{validRules:B,invalidColumns:$}=hi(C,a.schema);$.length>0&&y(`Removed invalid sort columns: ${$.join(", ")}`),Qe();try{F(a.id,{sortStack:B.length>0?B:void 0})}catch(A){const Z=St("processing","sorting",A);et(Z)}}else F(a.id,{sortStack:C.length>0?C:void 0})},[a,F,Qe,et]),Rt=p.useCallback(C=>{if(!a)return;const B=a.sortStack??[],$=B.find(A=>A.column===C);if(!($&&$.direction==="asc"))if($){const A=B.map(Z=>Z.column===C?{...Z,direction:"asc"}:Z);F(a.id,{sortStack:A})}else{if(B.length>=3)return;const A={column:C,direction:"asc",priority:B.length+1};F(a.id,{sortStack:[...B,A]})}},[a,F]),Tr=p.useCallback(C=>{if(!a)return;const B=a.sortStack??[],$=B.find(A=>A.column===C);if(!($&&$.direction==="desc"))if($){const A=B.map(Z=>Z.column===C?{...Z,direction:"desc"}:Z);F(a.id,{sortStack:A})}else{if(B.length>=3)return;const A={column:C,direction:"desc",priority:B.length+1};F(a.id,{sortStack:[...B,A]})}},[a,F]),ir=p.useCallback(C=>{var $;if(!a)return;if(!st("edit_filters",Ce)){y(at("edit_filters"),"error");return}const B=($=a.schema)==null?void 0:$.find(A=>A.name===C.column);if(B&&C.value!==void 0){const A=Ea(B.type,C.operator,C.value);if(!A.isValid){y(A.errorMessage||"Invalid filter value","error");return}}Qe();try{const A=a.filters??[];pe("filters","filter_added",A,[...A,C]),F(a.id,{filters:[...A,C]})}catch(A){const Z=St("processing","filters",A);et(Z)}},[a,Ce,F,Qe,et,pe]),zr=p.useCallback((C,B)=>{if(!a)return;if(!st("edit_filters",Ce)){y(at("edit_filters"),"error");return}const $=a.filters??[],A=[...$];pe("filters","filter_updated",$[C],B),A[C]=B,F(a.id,{filters:A})},[a,Ce,F,pe]),_t=p.useCallback(C=>{if(!a)return;if(!st("edit_filters",Ce)){y(at("edit_filters"),"error");return}const B=a.filters??[],$=B.filter((A,Z)=>Z!==C);pe("filters","filter_removed",B[C],null),F(a.id,{filters:$.length>0?$:void 0})},[a,Ce,F,pe]),Ue=p.useCallback(()=>{if(!a)return;if(!st("edit_filters",Ce)){y(at("edit_filters"),"error");return}const C=a.filters??[];pe("filters","filter_cleared",C,null),F(a.id,{filters:void 0})},[a,Ce,F,pe]),Ne=p.useCallback(C=>{if(!a)return;if(!st("edit_filters",Ce)){y(at("edit_filters"),"error");return}const B=a.filters??[];pe("filters","filter_cleared",B,C),F(a.id,{filters:C.length>0?C:void 0})},[a,Ce,F,pe]),rt=p.useCallback(C=>{var Z;if(!a)return;const B=(Z=a.views)==null?void 0:Z.find(X=>X.id===C);if(!B)return;const $=B.snapshot.columnOrder,A=Fr($,B.snapshot.grouping);F(a.id,{filters:B.snapshot.filters.length>0?[...B.snapshot.filters]:void 0,sortStack:B.snapshot.sortStack.length>0?[...B.snapshot.sortStack]:void 0,columnVisibility:{...B.snapshot.columnVisibility},columnOrder:A,columnWidths:{...B.snapshot.columnWidths},grouping:B.snapshot.grouping,activeViewId:C}),_e(new Set),x(!1)},[a,F]),ht=p.useCallback((C,B,$)=>{if(!(a!=null&&a.schema)||!ye)return;const A={id:`view-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,name:C,description:B||void 0,isDefault:$,isFavorite:!1,isDeleted:!1,createdAt:Date.now(),updatedAt:Date.now(),snapshot:{...ye}},Z=a.views??[],X=$?Z.map(be=>({...be,isDefault:!1})):Z;F(a.id,{views:[...X,A],activeViewId:A.id}),y(`"${C}" view created`,"success")},[a,ye,F]),Wt=p.useCallback(()=>{var B;if(!K||!ye||K.isDefault||!a)return;const C=(B=a.views)==null?void 0:B.map($=>$.id===K.id?{...$,snapshot:{...ye}}:$);F(a.id,{views:C}),y(`"${K.name}" view updated`,"success")},[K,ye,a,F]),Ir=p.useCallback(C=>{var A;if(!K||!ye||!a)return;const B=C??ye.columnWidths,$=(A=a.views)==null?void 0:A.map(Z=>Z.id===K.id?{...Z,snapshot:{...Z.snapshot,columnVisibility:ye.columnVisibility,columnOrder:ye.columnOrder,columnWidths:B},updatedAt:Date.now()}:Z);F(a.id,{views:$,columnWidths:B}),y(`Column configuration saved to "${K.name}"`,"success")},[K,ye,a,F]),Er=p.useCallback(C=>{var X,be;if(!ye||!a||!K)return;const B=C??ye.columnWidths,$={...K,snapshot:{...K.snapshot,columnVisibility:ye.columnVisibility,columnOrder:ye.columnOrder,columnWidths:B},updatedAt:Date.now()},A=(X=a.views)==null?void 0:X.map(Te=>Te.id===K.id?$:{...Te,snapshot:{...Te.snapshot,columnVisibility:ye.columnVisibility,columnOrder:ye.columnOrder,columnWidths:B},updatedAt:Date.now()});F(a.id,{views:A,columnWidths:B});const Z=(((be=a.views)==null?void 0:be.length)||0)-1;y(`Column configuration saved to current view and ${Z} other view${Z===1?"":"s"}`,"success")},[ye,a,K,F]),Br=p.useCallback(()=>{_(!0)},[]),Dr=p.useCallback(()=>{if(!K||!a)return;const C=K.snapshot.columnOrder,B=Fr(C,K.snapshot.grouping);F(a.id,{filters:K.snapshot.filters.length>0?[...K.snapshot.filters]:void 0,sortStack:K.snapshot.sortStack.length>0?[...K.snapshot.sortStack]:void 0,columnVisibility:{...K.snapshot.columnVisibility},columnOrder:B,columnWidths:{...K.snapshot.columnWidths},grouping:K.snapshot.grouping}),y("Changes reverted to last saved state","success")},[K,a,F]),Or=p.useCallback(C=>{if(!(a!=null&&a.views))return;const B=a.views.map(A=>({...A,isDefault:A.id===C}));F(a.id,{views:B});const $=a.views.find(A=>A.id===C);$&&y(`"${$.name}" set as default view`,"success")},[a,F]),Mr=p.useCallback(C=>{if(!(a!=null&&a.views))return;const B=a.views.map(A=>A.id===C?{...A,isFavorite:!A.isFavorite,updatedAt:Date.now()}:A);F(a.id,{views:B});const $=a.views.find(A=>A.id===C);$&&!$.isFavorite?y(`"${$.name}" added to favorites`,"success"):$&&y(`"${$.name}" removed from favorites`,"info")},[a,F]),sr=p.useCallback(C=>{if(!(a!=null&&a.views))return;const B=a.views.map(X=>X.id===C?{...X,isDeleted:!0,updatedAt:Date.now()}:X),$=a.activeViewId===C,A=B.find(X=>X.isDefault&&!X.isDeleted);F(a.id,{views:B,activeViewId:$&&A?A.id:a.activeViewId,filters:$&&A?A.snapshot.filters.length>0?A.snapshot.filters:void 0:a.filters,sortStack:$&&A?A.snapshot.sortStack.length>0?A.snapshot.sortStack:void 0:a.sortStack});const Z=a.views.find(X=>X.id===C);Z&&y(`"${Z.name}" moved to Recently Deleted`,"info")},[a,F]),ar=p.useCallback(C=>{if(!(a!=null&&a.views))return;const B=a.views.map(A=>A.id===C?{...A,isDeleted:!1,updatedAt:Date.now()}:A);F(a.id,{views:B});const $=a.views.find(A=>A.id===C);$&&y(`"${$.name}" restored`,"success")},[a,F]),Ar=p.useCallback(C=>{if(!(a!=null&&a.views))return;const B=a.views.find(Te=>Te.id===C),$=a.views.filter(Te=>!Te.isDeleted||Te.id===C);if((B==null?void 0:B.isDefault)&&$.filter(Te=>Te.isDefault).length===1){y("Cannot delete the last default view","error");return}const Z=a.views.filter(Te=>Te.id!==C),X=a.activeViewId===C,be=Z.find(Te=>Te.isDefault&&!Te.isDeleted);F(a.id,{views:Z,activeViewId:X&&be?be.id:a.activeViewId,filters:X&&be?be.snapshot.filters.length>0?be.snapshot.filters:void 0:a.filters,sortStack:X&&be?be.snapshot.sortStack.length>0?be.snapshot.sortStack:void 0:a.sortStack}),B&&y(`"${B.name}" permanently deleted`,"success")},[a,F]),$r=p.useCallback(C=>{G(C),q(!0),x(!1)},[]),Be=p.useCallback((C,B)=>{if(!L||!(a!=null&&a.views))return;const $=a.views.map(A=>A.id===L?{...A,name:C,description:B||void 0}:A);F(a.id,{views:$}),G(null)},[L,a,F]),gt=p.useCallback(C=>{Q(C),ue(!0),x(!1)},[]),lr=p.useCallback(()=>{if(!oe||!(a!=null&&a.views))return;const C=a.views.filter(A=>A.id!==oe),B=a.activeViewId===oe,$=C.find(A=>A.isDefault);F(a.id,{views:C,activeViewId:B&&$?$.id:a.activeViewId,filters:B&&$?$.snapshot.filters.length>0?$.snapshot.filters:void 0:a.filters,sortStack:B&&$?$.snapshot.sortStack.length>0?$.snapshot.sortStack:void 0:a.sortStack}),Q(null),ue(!1)},[oe,a,F]);p.useEffect(()=>{ke!=null&&ke.resetPage?ke.resetPage():zt(1)},[a==null?void 0:a.filters,kt,a==null?void 0:a.activeViewId]),p.useEffect(()=>{ke&&ke.currentPage!==Me&&zt(ke.currentPage)},[ke==null?void 0:ke.currentPage]);const cr=p.useCallback(C=>{ke!=null&&ke.goToPage&&ke.goToPage(C),zt(C)},[ke]),yt=p.useCallback(C=>{const B=(Me-1)*ut,$=Math.floor(B/C)+1;pt(C),zt($)},[Me,ut]),dr=p.useCallback((C,B)=>{if(!a)return;if(!st("edit_columns",Ce)){y(at("edit_columns"),"error");return}const A={...a.columnVisibility||(K==null?void 0:K.snapshot.columnVisibility)||{},[C]:B};F(a.id,{columnVisibility:A})},[a,K,Ce,F]),Pt=p.useCallback(C=>{if(a){if(!st("edit_columns",Ce)){y(at("edit_columns"),"error");return}F(a.id,{columnOrder:C})}},[a,Ce,F]),Nt=p.useCallback((C,B)=>{if(!a)return;if(!st("edit_columns",Ce)){y(at("edit_columns"),"error");return}const A={...a.columnWidths||(K==null?void 0:K.snapshot.columnWidths)||{},[C]:B};F(a.id,{columnWidths:A})},[a,K,Ce,F]),I=p.useCallback(C=>{if(!a)return;const $=(a.filters??[]).filter(A=>A.column!==C);F(a.id,{filters:$.length>0?$:void 0})},[a,F]),V=p.useCallback(()=>{if(!K||!(a!=null&&a.schema))return;const C={},B=[],$={};a.schema.forEach(A=>{C[A.name]=!0,B.push(A.name),$[A.name]=150}),F(a.id,{columnVisibility:C,columnOrder:B,columnWidths:$,filters:void 0,sortStack:void 0}),y("Reset to default layout - all filters and sorts cleared","success")},[K,a,F]),ae=p.useCallback(Ca(C=>{Tt(C)},300),[]),$e=p.useCallback(C=>{ae(C)},[ae]),ce=p.useCallback(C=>{if(!C.trim()||!a)return;const B=a.searchHistory||[],$=ea(B,C);F(a.id,{searchHistory:$})},[a,F]),Ft=p.useCallback(C=>{if(!a)return;const B=a.searchHistory||[],$=ta(B,C);F(a.id,{searchHistory:$})},[a,F]),Ji=p.useCallback(C=>{if(!a)return;const B=a.searchHistory||[],$=ra(B,C);F(a.id,{searchHistory:$})},[a,F]),Ki=p.useCallback(C=>{_e(B=>{const $=new Set(B);return $.has(C)?$.delete(C):$.add(C),$})},[]),Xi=p.useCallback((C,B)=>{_e($=>{const A=new Set($);for(const Z of B)C?A.add(Z):A.delete(Z);return A})},[]),Zi=p.useCallback((C,B,$)=>{_e(A=>{const Z=new Set(A),X=Math.min(C,B),be=Math.max(C,B);for(let Te=X;Te<=be;Te++)$[Te]!==void 0&&Z.add($[Te]);return Z})},[]),Qi=p.useCallback(()=>{_e(new Set)},[]),es=p.useCallback(C=>{_e(B=>{const $=new Set(B);return $.delete(C),$})},[]),ts=p.useCallback(C=>{if(!(a!=null&&a.uploadedData))return;const B=a.uploadedData.indexOf(C);if(B===-1)return;const $=a.favoriteRowIndices||[],Z=$.includes(B)?$.filter(X=>X!==B):[...$,B];F(a.id,{favoriteRowIndices:Z})},[a,F]),rs=p.useCallback((C,B)=>{if(!(a!=null&&a.uploadedData))return;const $=a.favoriteRowIndices||[],A=C.map(X=>a.uploadedData.indexOf(X)).filter(X=>X!==-1),Z=B?[...$,...A.filter(X=>!$.includes(X))]:$.filter(X=>!A.includes(X));F(a.id,{favoriteRowIndices:Z})},[a,F]),os=p.useCallback(()=>{if(!a)return;const C=a.favoriteRowIndices||[],B=!a.showFavoritesOnly;if(B&&C.length===0){y("No rows marked as favorite","warning");return}F(a.id,{showFavoritesOnly:B}),_e(new Set),y(B?`Showing ${C.length} favorite row${C.length===1?"":"s"}`:"Showing all data","info")},[a,F]),ns=p.useCallback(C=>{if(a){if(!st("edit_columns",Ce)){y(at("edit_columns"),"error");return}if(C&&a.schema){const{validGrouping:B,invalidColumns:$}=gi(C,a.schema);$.length>0&&y(`Removed invalid grouping columns: ${$.join(", ")}`,"warning"),Qe();try{const A=a.grouping;B===null?pe("grouping","group_cleared",A,null):A?pe("grouping","group_reordered",A,B):pe("grouping","group_level_added",null,B);const Z=(K==null?void 0:K.snapshot.columnOrder)||a.columnOrder||[],X=Fr(Z,B);F(a.id,{grouping:B,columnOrder:X}),JSON.stringify(X)!==JSON.stringify(a.columnOrder)&&pe("columns","column_reordered",a.columnOrder,X),Ae(!1)}catch(A){const Z=St("processing","grouping",A);et(Z)}}else{const B=a.grouping;pe("grouping","group_cleared",B,null);const $=(K==null?void 0:K.snapshot.columnOrder)||a.columnOrder||[];F(a.id,{grouping:C,columnOrder:[...$]}),JSON.stringify($)!==JSON.stringify(a.columnOrder)&&pe("columns","column_reordered",a.columnOrder,$),Ae(!1)}}},[a,K,Ce,F,Qe,et,pe]),is=p.useCallback(C=>{if(!a)return;const B=a.grouping;if(!B)return;const $=Ys(B,C);F(a.id,{grouping:$})},[a,F]),ss=p.useCallback(()=>{mt(!0)},[]),ur=p.useCallback(C=>{a!=null&&a.schema&&(ne(!0),setTimeout(()=>{try{let B;C.scope==="visible"?B=ft:B=a.uploadedData||[];let $;C.columnScope==="all"?($={},a.schema.forEach(Te=>{$[Te.name]=!0})):$=a.columnVisibility||(K==null?void 0:K.snapshot.columnVisibility)||{};const A=a.columnOrder||(K==null?void 0:K.snapshot.columnOrder),Z=so(B,a.schema,a.filters??[],a.sortStack??[],K,$,A),X=a.name;let be;switch(C.format){case"csv":ao(Z,X,C),be="export_csv";break;case"excel":lo(Z,X,C),be="export_excel";break;case"json":co(Z,X,C),be="export_json";break}pe("export",be,null,{format:C.format,scope:C.scope,columnScope:C.columnScope,rowCount:B.length,viewName:(K==null?void 0:K.name)||"Default View"}),y(`Export completed successfully (${C.format.toUpperCase()})`,"success")}catch(B){const $=Da(B,{onRetry:()=>ur(C)});y(`Export failed: ${$.message}`,{action:{label:"Retry",onClick:()=>ur(C)}});const A=gn(a.id,bt,$,a.auditHistory||[]);F(a.id,{auditHistory:A}),Ht.error("urm:report-engine","Export failed",B)}finally{ne(!1)}},500))},[a,K,ft,F,pe]),as=p.useCallback(C=>{if(a!=null&&a.schema){if(nt&&K&&!K.isDefault){se(C.format),te(!0),mt(!1);return}ur(C),mt(!1)}},[a,K,nt,ur]),Jr=p.useCallback(C=>{ur({format:C,scope:"visible",columnScope:"visible"})},[ur]),ls=p.useCallback(()=>{ie&&Jr(ie),te(!1),se(null)},[ie,Jr]),cs=p.useCallback(()=>{Wt(),ie&&Jr(ie),te(!1),se(null)},[Wt,ie,Jr]),ds=p.useCallback(()=>{te(!1),se(null)},[]),us=p.useCallback(C=>{!(a!=null&&a.schema)||qe.size===0||(ne(!0),setTimeout(()=>{try{const B=Array.from(qe),$=so(B,a.schema,a.filters??[],a.sortStack??[],K),A=`${a.name.toLowerCase().replace(/\s+/g,"_")}_selected_export`;switch(C){case"csv":ao($,A);break;case"excel":lo($,A);break;case"json":co($,A);break}y(`Exported ${B.length} selected rows`,"info")}catch(B){y("Export failed. Please try again.","error"),Ht.error("urm:report-engine","Bulk export failed",B)}finally{ne(!1)}},500))},[a,K,qe,$t]),ps=p.useCallback((C,B)=>{if(a)try{const $=fa(a),A=ha(C,B,bt,$),Z=ga(a.presets,A);F(a.id,{presets:Z}),pe("presets","preset_created",null,{presetId:A.id,name:A.name}),Ke(!1),y(`Preset "${C}" saved successfully`,"success")}catch($){y($ instanceof Error?$.message:"Failed to create preset","error")}},[a,F,pe]),xs=p.useCallback(()=>{Mt(null),y("Exited preset view","info")},[]),ms=p.useCallback(()=>{We(!0)},[]),fs=p.useCallback((C,B)=>{if(!a)return;const $=ya(a.presets,C);F(a.id,{presets:$}),pe("presets","preset_deleted",{presetId:C,name:B},null),xt===C&&Mt(null),y(`Preset "${B}" deleted`,"success")},[a,xt,F,pe]);p.useEffect(()=>{if(!d||u.length===0)return;const C=u.find(B=>B.id===d);C&&C.id!==f&&b(C.id)},[d,u,f]),p.useEffect(()=>{if(!a)return;const C=ba();if(C&&a.presets&&a.schemaLocked&&a.schema){const B=hn(a.presets,C);if(B){const{sanitizedConfig:$,warnings:A}=Ba(B.config,a.schema);A.length>0&&A.forEach(X=>y(X,"warning"));const Z=va($);F(a.id,Z),Mt(C),pe("presets","preset_applied",null,{presetId:B.id,name:B.name}),y(`Loaded preset: ${B.name}`,"info")}else y("Preset not found","info")}},[a==null?void 0:a.schemaLocked]);const hs=xt?hn(a==null?void 0:a.presets,xt):void 0;p.useEffect(()=>{a!=null&&a.views&&a.views.length>0&&a.activeViewId&&Xs(a.id,{views:a.views,activeViewId:a.activeViewId})},[a==null?void 0:a.views,a==null?void 0:a.activeViewId,a==null?void 0:a.id]),p.useEffect(()=>{if(a!=null&&a.schemaLocked&&a.schema&&(!a.views||a.views.length===0)){const C=Zs(a.id);if(C&&C.views.length>0){const B=C.views.find($=>$.id===C.activeViewId);if(B)F(a.id,{views:C.views,activeViewId:C.activeViewId,filters:B.snapshot.filters.length>0?B.snapshot.filters:void 0,sortStack:B.snapshot.sortStack.length>0?B.snapshot.sortStack:void 0});else{const $=C.views.find(A=>A.isDefault)||Eo(a.schema);F(a.id,{views:C.views,activeViewId:$.id,filters:$.snapshot.filters.length>0?$.snapshot.filters:void 0,sortStack:$.snapshot.sortStack.length>0?$.snapshot.sortStack:void 0})}}}},[a==null?void 0:a.schemaLocked,a==null?void 0:a.schema,a==null?void 0:a.id]);const gs=p.useCallback(C=>{M(C),R(!0)},[]),ys=p.useCallback(()=>{R(!1),M(void 0)},[]),bs=(sn=a==null?void 0:a.views)==null?void 0:sn.find(C=>C.id===L),vs=(an=a==null?void 0:a.views)==null?void 0:an.find(C=>C.id===oe);return{reports:u,activeReport:a,activeReportId:f,setActiveReportId:b,isModalOpen:h,setIsModalOpen:g,createReport:fe,updateReport:F,uploadState:k,handleFileUpload:tt,handleUploadError:wr,handleRetry:it,handleConfirm:Re,paginatedData:tr,processedData:ft,displayData:$t,tableMetrics:rr,isGrouped:Cr,tableEngine:ot,activeView:K,isDirty:nt,currentTableState:ye,viewChanges:or,filters:a==null?void 0:a.filters,showFilterPanel:O,setShowFilterPanel:R,filterFocusColumn:re,handleAddFilter:ir,handleUpdateFilter:zr,handleRemoveFilter:_t,handleClearAllFilters:Ue,handleReplaceFilters:Ne,handleOpenFilterForColumn:gs,handleCloseFilterPanel:ys,handleClearFiltersForColumn:I,sortStack:a==null?void 0:a.sortStack,showSortPanel:U,setShowSortPanel:J,handleSort:nr,handleUpdateSortStack:kr,handleSortAscending:Rt,handleSortDescending:Tr,views:a==null?void 0:a.views,showManageViews:ee,setShowManageViews:x,showCreateViewModal:N,setShowCreateViewModal:_,showEditViewModal:H,setShowEditViewModal:q,showDeleteConfirmation:de,setShowDeleteConfirmation:ue,editingView:bs,deletingView:vs,editingViewId:L,deletingViewId:oe,handleSelectView:rt,handleCreateView:ht,handleUpdateCurrentView:Wt,handleSaveColumnConfigToCurrentView:Ir,handleSaveColumnConfigToAllViews:Er,handleSaveAsNewView:Br,handleRevertChanges:Dr,handleToggleDefault:Or,handleToggleFavorite:Mr,handleSoftDelete:sr,handleRestoreView:ar,handlePermanentDelete:Ar,handleEditView:$r,handleSaveEditView:Be,handleDeleteView:gt,handleConfirmDelete:lr,showManageColumns:je,setShowManageColumns:Y,columnVisibility:a==null?void 0:a.columnVisibility,columnOrder:a==null?void 0:a.columnOrder,columnWidths:a==null?void 0:a.columnWidths,handleUpdateColumnVisibility:dr,handleUpdateColumnOrder:Pt,handleUpdateColumnWidth:Nt,handleResetColumnLayout:V,showGroupPanel:Oe,setShowGroupPanel:Ae,grouping:a==null?void 0:a.grouping,groupingState:dt,handleGroup:ns,handleToggleGroupCollapse:is,searchQuery:kt,searchHistory:oa((a==null?void 0:a.searchHistory)||[]),handleSearchChange:$e,handleAddToSearchHistory:ce,handleToggleSearchFavourite:Ft,handleDeleteSearchHistory:Ji,selectedRowIds:qe,handleToggleRowSelection:Ki,handleToggleAllRows:Xi,handleRangeSelection:Zi,handleClearSelection:Qi,handleUpdateSelectionAfterDelete:es,favoriteRowIndices:(a==null?void 0:a.favoriteRowIndices)||[],resolvedFavoritesSet:jr,showFavoritesOnly:(a==null?void 0:a.showFavoritesOnly)||!1,handleToggleRowFavorite:ts,handleBulkSetFavorites:rs,handleToggleFavoritesFilter:os,currentPage:Me,pageSize:ut,paginationEngine:ke,handlePageChange:cr,handlePageSizeChange:yt,isExporting:le,showExportModal:Jt,setShowExportModal:mt,showDirtyExportWarning:P,handleExport:ss,handleExportWithConfig:as,handleExportSelected:us,handleExportAnyway:ls,handleSaveAndExport:cs,handleCancelExport:ds,showAuditHistory:Je,setShowAuditHistory:It,auditHistory:a==null?void 0:a.auditHistory,showCreatePreset:qt,setShowCreatePreset:Ke,showManagePresets:Xe,setShowManagePresets:We,activePreset:hs,activePresetId:xt,handleOpenManagePresets:ms,handleCreatePreset:ps,handleClearActivePreset:xs,handleDeletePresetById:fs,userRole:Ce,isViewerRole:At,currentUserId:bt,featureLimitWarning:Xt,setFeatureLimitWarning:Zt,datasetMeta:Sr,reportError:Qt,setReportError:er,handleError:et,schema:a==null?void 0:a.schema,hasSchemaConflicts:a!=null&&a.schema?Ws(a.schema):!1,snack:j,handleSnackClose:T,showSnack:y}}const Fe={sort:{maxLevels:5},filter:{maxConditions:10,allowedOperators:["equals","contains","startsWith","endsWith","gt","lt","gte","lte","isTrue","isFalse","NULL","NOT_NULL"]},columns:{maxVisible:20,minColumnWidth:60,maxColumnWidth:800},grouping:{maxLevels:3,allowNested:!0,allowCollapse:!0},export:{allowedFormats:["csv","excel","json"]},views:{maxViews:10,isAdmin:!1},dates:{displayFormat:null},display:{showDevPanel:!1}},yi="urm_dev_config";function Ga(){try{const t=localStorage.getItem(yi);if(!t)return Fe;const o=JSON.parse(t),n={sort:{...Fe.sort,...o.sort},filter:{...Fe.filter,...o.filter},columns:{...Fe.columns,...o.columns},grouping:{...Fe.grouping,...o.grouping},export:{...Fe.export,...o.export},views:{...Fe.views,...o.views},dates:{...Fe.dates,...o.dates},display:{...Fe.display,...o.display}};return n.sort.maxLevels=Math.min(5,Math.max(1,n.sort.maxLevels)),n}catch{return Fe}}function qa(t){try{localStorage.setItem(yi,JSON.stringify(t))}catch{}}function Ja(t,o,n){if(!n||!o)return t;const i={sort:{...t.sort,...o.sort},filter:{...t.filter,...o.filter},columns:{...t.columns,...o.columns},grouping:{...t.grouping,...o.grouping},export:{...t.export,...o.export},views:{...t.views,...o.views},dates:{...t.dates,...o.dates},display:{...t.display,...o.display}};return i.sort.maxLevels=Math.min(5,Math.max(1,i.sort.maxLevels)),i}const bi=p.createContext(Fe);function yr(){return p.useContext(bi)}const vi=p.createContext(void 0);function Jo(t){const{children:o,initialData:n,data:i,reportName:s,dataSource:c,mode:d="builder",autoLoad:l=!0,config:u,devConfig:m,showDevPanel:f=!1,sharedReportId:b}=t,g=Ya({mode:d,autoLoad:l,initialData:i||n,dataSource:c,reportName:s,sharedReportId:b,config:u}),[z,v]=p.useState(()=>Ga()),j=(()=>{const a=Ja(z,m,!!m);return{...a,display:{...a.display,showDevPanel:f||a.display.showDevPanel}}})(),S=p.useCallback(T=>{v(T),qa(T)},[]),y={...g,activeDevConfig:j,handleDevConfigChange:S};return e.jsx(bi.Provider,{value:j,children:e.jsx(vi.Provider,{value:y,children:o})})}function mo(){const t=p.useContext(vi);if(t===void 0)throw new Error("useReportContext must be used within a ReportProvider. Wrap your component tree with <ReportProvider>...</ReportProvider>");return t}function Ka({onCreateReport:t,reports:o=[],activeReportId:n,onReportClick:i}){const s=o.find(c=>c.id===n);return e.jsx(r.Box,{component:"header",sx:{position:"sticky",top:0,zIndex:50,borderBottom:"1px solid",borderColor:"divider",bgcolor:"background.paper"},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,height:64},children:[e.jsxs(r.Breadcrumbs,{separator:e.jsx(w.ChevronRight,{sx:{fontSize:16,color:"text.secondary"}}),sx:{display:"flex",alignItems:"center"},children:[e.jsx(r.Typography,{variant:"h6",component:"h1",sx:{fontWeight:500,fontSize:"1.375rem",color:"text.primary",letterSpacing:"-0.01em",cursor:o.length>0&&s?"pointer":"default","&:hover":o.length>0&&s?{color:"primary.main"}:{}},onClick:()=>{o.length>0},children:"Reports"}),s&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx(r.Typography,{sx:{fontWeight:500,fontSize:"1.125rem",color:"primary.main",cursor:"pointer","&:hover":{textDecoration:"underline"}},onClick:()=>i==null?void 0:i(s.id),children:s.name}),e.jsx(r.Tooltip,{title:s.description||"No description",arrow:!0,placement:"bottom",children:e.jsx(w.InfoOutlined,{sx:{fontSize:18,color:"text.secondary",opacity:.7,cursor:"help","&:hover":{opacity:1}}})})]})]}),e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",gap:1.5},children:e.jsx(r.Button,{variant:"contained",startIcon:e.jsx(w.Add,{sx:{fontSize:18}}),onClick:t,sx:{borderRadius:"20px",px:3,textTransform:"none",fontWeight:500,fontSize:"0.875rem",py:.75},children:"New Report"})})]})})}function Ut(t,...o){const n=new URL(`https://mui.com/production-error/?code=${t}`);return o.forEach(i=>n.searchParams.append("args[]",i)),`Minified MUI error #${t}; visit ${n} for the full message.`}const Xa="$$material";function Za(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Qr={exports:{}},eo={exports:{}},xe={};/** @license React v16.13.1
|
|
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 bn;function Qa(){if(bn)return xe;bn=1;var t=typeof Symbol=="function"&&Symbol.for,o=t?Symbol.for("react.element"):60103,n=t?Symbol.for("react.portal"):60106,i=t?Symbol.for("react.fragment"):60107,s=t?Symbol.for("react.strict_mode"):60108,c=t?Symbol.for("react.profiler"):60114,d=t?Symbol.for("react.provider"):60109,l=t?Symbol.for("react.context"):60110,u=t?Symbol.for("react.async_mode"):60111,m=t?Symbol.for("react.concurrent_mode"):60111,f=t?Symbol.for("react.forward_ref"):60112,b=t?Symbol.for("react.suspense"):60113,h=t?Symbol.for("react.suspense_list"):60120,g=t?Symbol.for("react.memo"):60115,z=t?Symbol.for("react.lazy"):60116,v=t?Symbol.for("react.block"):60121,j=t?Symbol.for("react.fundamental"):60117,S=t?Symbol.for("react.responder"):60118,y=t?Symbol.for("react.scope"):60119;function T(k){if(typeof k=="object"&&k!==null){var D=k.$$typeof;switch(D){case o:switch(k=k.type,k){case u:case m:case i:case c:case s:case b:return k;default:switch(k=k&&k.$$typeof,k){case l:case f:case z:case g:case d:return k;default:return D}}case n:return D}}}function a(k){return T(k)===m}return xe.AsyncMode=u,xe.ConcurrentMode=m,xe.ContextConsumer=l,xe.ContextProvider=d,xe.Element=o,xe.ForwardRef=f,xe.Fragment=i,xe.Lazy=z,xe.Memo=g,xe.Portal=n,xe.Profiler=c,xe.StrictMode=s,xe.Suspense=b,xe.isAsyncMode=function(k){return a(k)||T(k)===u},xe.isConcurrentMode=a,xe.isContextConsumer=function(k){return T(k)===l},xe.isContextProvider=function(k){return T(k)===d},xe.isElement=function(k){return typeof k=="object"&&k!==null&&k.$$typeof===o},xe.isForwardRef=function(k){return T(k)===f},xe.isFragment=function(k){return T(k)===i},xe.isLazy=function(k){return T(k)===z},xe.isMemo=function(k){return T(k)===g},xe.isPortal=function(k){return T(k)===n},xe.isProfiler=function(k){return T(k)===c},xe.isStrictMode=function(k){return T(k)===s},xe.isSuspense=function(k){return T(k)===b},xe.isValidElementType=function(k){return typeof k=="string"||typeof k=="function"||k===i||k===m||k===c||k===s||k===b||k===h||typeof k=="object"&&k!==null&&(k.$$typeof===z||k.$$typeof===g||k.$$typeof===d||k.$$typeof===l||k.$$typeof===f||k.$$typeof===j||k.$$typeof===S||k.$$typeof===y||k.$$typeof===v)},xe.typeOf=T,xe}var me={};/** @license React v16.13.1
|
|
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 vn;function el(){return vn||(vn=1,process.env.NODE_ENV!=="production"&&(function(){var t=typeof Symbol=="function"&&Symbol.for,o=t?Symbol.for("react.element"):60103,n=t?Symbol.for("react.portal"):60106,i=t?Symbol.for("react.fragment"):60107,s=t?Symbol.for("react.strict_mode"):60108,c=t?Symbol.for("react.profiler"):60114,d=t?Symbol.for("react.provider"):60109,l=t?Symbol.for("react.context"):60110,u=t?Symbol.for("react.async_mode"):60111,m=t?Symbol.for("react.concurrent_mode"):60111,f=t?Symbol.for("react.forward_ref"):60112,b=t?Symbol.for("react.suspense"):60113,h=t?Symbol.for("react.suspense_list"):60120,g=t?Symbol.for("react.memo"):60115,z=t?Symbol.for("react.lazy"):60116,v=t?Symbol.for("react.block"):60121,j=t?Symbol.for("react.fundamental"):60117,S=t?Symbol.for("react.responder"):60118,y=t?Symbol.for("react.scope"):60119;function T(Y){return typeof Y=="string"||typeof Y=="function"||Y===i||Y===m||Y===c||Y===s||Y===b||Y===h||typeof Y=="object"&&Y!==null&&(Y.$$typeof===z||Y.$$typeof===g||Y.$$typeof===d||Y.$$typeof===l||Y.$$typeof===f||Y.$$typeof===j||Y.$$typeof===S||Y.$$typeof===y||Y.$$typeof===v)}function a(Y){if(typeof Y=="object"&&Y!==null){var Oe=Y.$$typeof;switch(Oe){case o:var Ae=Y.type;switch(Ae){case u:case m:case i:case c:case s:case b:return Ae;default:var dt=Ae&&Ae.$$typeof;switch(dt){case l:case f:case z:case g:case d:return dt;default:return Oe}}case n:return Oe}}}var k=u,D=m,O=l,R=d,U=o,J=f,ee=i,x=z,N=g,_=n,H=c,q=s,de=b,ue=!1;function re(Y){return ue||(ue=!0,console.warn("The ReactIs.isAsyncMode() alias has been deprecated, and will be removed in React 17+. Update your code to use ReactIs.isConcurrentMode() instead. It has the exact same API.")),M(Y)||a(Y)===u}function M(Y){return a(Y)===m}function L(Y){return a(Y)===l}function G(Y){return a(Y)===d}function oe(Y){return typeof Y=="object"&&Y!==null&&Y.$$typeof===o}function Q(Y){return a(Y)===f}function le(Y){return a(Y)===i}function ne(Y){return a(Y)===z}function P(Y){return a(Y)===g}function te(Y){return a(Y)===n}function ie(Y){return a(Y)===c}function se(Y){return a(Y)===s}function je(Y){return a(Y)===b}me.AsyncMode=k,me.ConcurrentMode=D,me.ContextConsumer=O,me.ContextProvider=R,me.Element=U,me.ForwardRef=J,me.Fragment=ee,me.Lazy=x,me.Memo=N,me.Portal=_,me.Profiler=H,me.StrictMode=q,me.Suspense=de,me.isAsyncMode=re,me.isConcurrentMode=M,me.isContextConsumer=L,me.isContextProvider=G,me.isElement=oe,me.isForwardRef=Q,me.isFragment=le,me.isLazy=ne,me.isMemo=P,me.isPortal=te,me.isProfiler=ie,me.isStrictMode=se,me.isSuspense=je,me.isValidElementType=T,me.typeOf=a})()),me}var Sn;function Si(){return Sn||(Sn=1,process.env.NODE_ENV==="production"?eo.exports=Qa():eo.exports=el()),eo.exports}/*
|
|
18
18
|
object-assign
|
|
19
19
|
(c) Sindre Sorhus
|
|
20
20
|
@license MIT
|
|
21
|
-
*/var
|
|
22
|
-
Valid keys: `+JSON.stringify(Object.keys(
|
|
21
|
+
*/var Do,jn;function tl(){if(jn)return Do;jn=1;var t=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;function i(c){if(c==null)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(c)}function s(){try{if(!Object.assign)return!1;var c=new String("abc");if(c[5]="de",Object.getOwnPropertyNames(c)[0]==="5")return!1;for(var d={},l=0;l<10;l++)d["_"+String.fromCharCode(l)]=l;var u=Object.getOwnPropertyNames(d).map(function(f){return d[f]});if(u.join("")!=="0123456789")return!1;var m={};return"abcdefghijklmnopqrst".split("").forEach(function(f){m[f]=f}),Object.keys(Object.assign({},m)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}return Do=s()?Object.assign:function(c,d){for(var l,u=i(c),m,f=1;f<arguments.length;f++){l=Object(arguments[f]);for(var b in l)o.call(l,b)&&(u[b]=l[b]);if(t){m=t(l);for(var h=0;h<m.length;h++)n.call(l,m[h])&&(u[m[h]]=l[m[h]])}}return u},Do}var Oo,Cn;function Ko(){if(Cn)return Oo;Cn=1;var t="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return Oo=t,Oo}var Mo,wn;function ji(){return wn||(wn=1,Mo=Function.call.bind(Object.prototype.hasOwnProperty)),Mo}var Ao,kn;function rl(){if(kn)return Ao;kn=1;var t=function(){};if(process.env.NODE_ENV!=="production"){var o=Ko(),n={},i=ji();t=function(c){var d="Warning: "+c;typeof console<"u"&&console.error(d);try{throw new Error(d)}catch{}}}function s(c,d,l,u,m){if(process.env.NODE_ENV!=="production"){for(var f in c)if(i(c,f)){var b;try{if(typeof c[f]!="function"){var h=Error((u||"React class")+": "+l+" type `"+f+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof c[f]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw h.name="Invariant Violation",h}b=c[f](d,f,u,l,null,o)}catch(z){b=z}if(b&&!(b instanceof Error)&&t((u||"React class")+": type specification of "+l+" `"+f+"` is invalid; the type checker function must return `null` or an `Error` but returned a "+typeof b+". You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument)."),b instanceof Error&&!(b.message in n)){n[b.message]=!0;var g=m?m():"";t("Failed "+l+" type: "+b.message+(g??""))}}}}return s.resetWarningCache=function(){process.env.NODE_ENV!=="production"&&(n={})},Ao=s,Ao}var $o,Tn;function ol(){if(Tn)return $o;Tn=1;var t=Si(),o=tl(),n=Ko(),i=ji(),s=rl(),c=function(){};process.env.NODE_ENV!=="production"&&(c=function(l){var u="Warning: "+l;typeof console<"u"&&console.error(u);try{throw new Error(u)}catch{}});function d(){return null}return $o=function(l,u){var m=typeof Symbol=="function"&&Symbol.iterator,f="@@iterator";function b(M){var L=M&&(m&&M[m]||M[f]);if(typeof L=="function")return L}var h="<<anonymous>>",g={array:S("array"),bigint:S("bigint"),bool:S("boolean"),func:S("function"),number:S("number"),object:S("object"),string:S("string"),symbol:S("symbol"),any:y(),arrayOf:T,element:a(),elementType:k(),instanceOf:D,node:J(),objectOf:R,oneOf:O,oneOfType:U,shape:x,exact:N};function z(M,L){return M===L?M!==0||1/M===1/L:M!==M&&L!==L}function v(M,L){this.message=M,this.data=L&&typeof L=="object"?L:{},this.stack=""}v.prototype=Error.prototype;function j(M){if(process.env.NODE_ENV!=="production")var L={},G=0;function oe(le,ne,P,te,ie,se,je){if(te=te||h,se=se||P,je!==n){if(u){var Y=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use `PropTypes.checkPropTypes()` to call them. Read more at http://fb.me/use-check-prop-types");throw Y.name="Invariant Violation",Y}else if(process.env.NODE_ENV!=="production"&&typeof console<"u"){var Oe=te+":"+P;!L[Oe]&&G<3&&(c("You are manually calling a React.PropTypes validation function for the `"+se+"` prop on `"+te+"`. This is deprecated and will throw in the standalone `prop-types` package. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details."),L[Oe]=!0,G++)}}return ne[P]==null?le?ne[P]===null?new v("The "+ie+" `"+se+"` is marked as required "+("in `"+te+"`, but its value is `null`.")):new v("The "+ie+" `"+se+"` is marked as required in "+("`"+te+"`, but its value is `undefined`.")):null:M(ne,P,te,ie,se)}var Q=oe.bind(null,!1);return Q.isRequired=oe.bind(null,!0),Q}function S(M){function L(G,oe,Q,le,ne,P){var te=G[oe],ie=q(te);if(ie!==M){var se=de(te);return new v("Invalid "+le+" `"+ne+"` of type "+("`"+se+"` supplied to `"+Q+"`, expected ")+("`"+M+"`."),{expectedType:M})}return null}return j(L)}function y(){return j(d)}function T(M){function L(G,oe,Q,le,ne){if(typeof M!="function")return new v("Property `"+ne+"` of component `"+Q+"` has invalid PropType notation inside arrayOf.");var P=G[oe];if(!Array.isArray(P)){var te=q(P);return new v("Invalid "+le+" `"+ne+"` of type "+("`"+te+"` supplied to `"+Q+"`, expected an array."))}for(var ie=0;ie<P.length;ie++){var se=M(P,ie,Q,le,ne+"["+ie+"]",n);if(se instanceof Error)return se}return null}return j(L)}function a(){function M(L,G,oe,Q,le){var ne=L[G];if(!l(ne)){var P=q(ne);return new v("Invalid "+Q+" `"+le+"` of type "+("`"+P+"` supplied to `"+oe+"`, expected a single ReactElement."))}return null}return j(M)}function k(){function M(L,G,oe,Q,le){var ne=L[G];if(!t.isValidElementType(ne)){var P=q(ne);return new v("Invalid "+Q+" `"+le+"` of type "+("`"+P+"` supplied to `"+oe+"`, expected a single ReactElement type."))}return null}return j(M)}function D(M){function L(G,oe,Q,le,ne){if(!(G[oe]instanceof M)){var P=M.name||h,te=re(G[oe]);return new v("Invalid "+le+" `"+ne+"` of type "+("`"+te+"` supplied to `"+Q+"`, expected ")+("instance of `"+P+"`."))}return null}return j(L)}function O(M){if(!Array.isArray(M))return process.env.NODE_ENV!=="production"&&(arguments.length>1?c("Invalid arguments supplied to oneOf, expected an array, got "+arguments.length+" arguments. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z])."):c("Invalid argument supplied to oneOf, expected an array.")),d;function L(G,oe,Q,le,ne){for(var P=G[oe],te=0;te<M.length;te++)if(z(P,M[te]))return null;var ie=JSON.stringify(M,function(je,Y){var Oe=de(Y);return Oe==="symbol"?String(Y):Y});return new v("Invalid "+le+" `"+ne+"` of value `"+String(P)+"` "+("supplied to `"+Q+"`, expected one of "+ie+"."))}return j(L)}function R(M){function L(G,oe,Q,le,ne){if(typeof M!="function")return new v("Property `"+ne+"` of component `"+Q+"` has invalid PropType notation inside objectOf.");var P=G[oe],te=q(P);if(te!=="object")return new v("Invalid "+le+" `"+ne+"` of type "+("`"+te+"` supplied to `"+Q+"`, expected an object."));for(var ie in P)if(i(P,ie)){var se=M(P,ie,Q,le,ne+"."+ie,n);if(se instanceof Error)return se}return null}return j(L)}function U(M){if(!Array.isArray(M))return process.env.NODE_ENV!=="production"&&c("Invalid argument supplied to oneOfType, expected an instance of array."),d;for(var L=0;L<M.length;L++){var G=M[L];if(typeof G!="function")return c("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+ue(G)+" at index "+L+"."),d}function oe(Q,le,ne,P,te){for(var ie=[],se=0;se<M.length;se++){var je=M[se],Y=je(Q,le,ne,P,te,n);if(Y==null)return null;Y.data&&i(Y.data,"expectedType")&&ie.push(Y.data.expectedType)}var Oe=ie.length>0?", expected one of type ["+ie.join(", ")+"]":"";return new v("Invalid "+P+" `"+te+"` supplied to "+("`"+ne+"`"+Oe+"."))}return j(oe)}function J(){function M(L,G,oe,Q,le){return _(L[G])?null:new v("Invalid "+Q+" `"+le+"` supplied to "+("`"+oe+"`, expected a ReactNode."))}return j(M)}function ee(M,L,G,oe,Q){return new v((M||"React class")+": "+L+" type `"+G+"."+oe+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+Q+"`.")}function x(M){function L(G,oe,Q,le,ne){var P=G[oe],te=q(P);if(te!=="object")return new v("Invalid "+le+" `"+ne+"` of type `"+te+"` "+("supplied to `"+Q+"`, expected `object`."));for(var ie in M){var se=M[ie];if(typeof se!="function")return ee(Q,le,ne,ie,de(se));var je=se(P,ie,Q,le,ne+"."+ie,n);if(je)return je}return null}return j(L)}function N(M){function L(G,oe,Q,le,ne){var P=G[oe],te=q(P);if(te!=="object")return new v("Invalid "+le+" `"+ne+"` of type `"+te+"` "+("supplied to `"+Q+"`, expected `object`."));var ie=o({},G[oe],M);for(var se in ie){var je=M[se];if(i(M,se)&&typeof je!="function")return ee(Q,le,ne,se,de(je));if(!je)return new v("Invalid "+le+" `"+ne+"` key `"+se+"` supplied to `"+Q+"`.\nBad object: "+JSON.stringify(G[oe],null," ")+`
|
|
22
|
+
Valid keys: `+JSON.stringify(Object.keys(M),null," "));var Y=je(P,se,Q,le,ne+"."+se,n);if(Y)return Y}return null}return j(L)}function _(M){switch(typeof M){case"number":case"string":case"undefined":return!0;case"boolean":return!M;case"object":if(Array.isArray(M))return M.every(_);if(M===null||l(M))return!0;var L=b(M);if(L){var G=L.call(M),oe;if(L!==M.entries){for(;!(oe=G.next()).done;)if(!_(oe.value))return!1}else for(;!(oe=G.next()).done;){var Q=oe.value;if(Q&&!_(Q[1]))return!1}}else return!1;return!0;default:return!1}}function H(M,L){return M==="symbol"?!0:L?L["@@toStringTag"]==="Symbol"||typeof Symbol=="function"&&L instanceof Symbol:!1}function q(M){var L=typeof M;return Array.isArray(M)?"array":M instanceof RegExp?"object":H(L,M)?"symbol":L}function de(M){if(typeof M>"u"||M===null)return""+M;var L=q(M);if(L==="object"){if(M instanceof Date)return"date";if(M instanceof RegExp)return"regexp"}return L}function ue(M){var L=de(M);switch(L){case"array":case"object":return"an "+L;case"boolean":case"date":case"regexp":return"a "+L;default:return L}}function re(M){return!M.constructor||!M.constructor.name?h:M.constructor.name}return g.checkPropTypes=s,g.resetWarningCache=s.resetWarningCache,g.PropTypes=g,g},$o}var Ro,zn;function nl(){if(zn)return Ro;zn=1;var t=Ko();function o(){}function n(){}return n.resetWarningCache=o,Ro=function(){function i(d,l,u,m,f,b){if(b!==t){var h=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw h.name="Invariant Violation",h}}i.isRequired=i;function s(){return i}var c={array:i,bigint:i,bool:i,func:i,number:i,object:i,string:i,symbol:i,any:i,arrayOf:s,element:i,elementType:i,instanceOf:s,node:i,objectOf:s,oneOf:s,oneOfType:s,shape:s,exact:s,checkPropTypes:n,resetWarningCache:o};return c.PropTypes=c,c},Ro}var In;function il(){if(In)return Qr.exports;if(In=1,process.env.NODE_ENV!=="production"){var t=Si(),o=!0;Qr.exports=ol()(t.isElement,o)}else Qr.exports=nl()();return Qr.exports}var sl=il();const _r=Za(sl);var to={exports:{}},ve={};/**
|
|
23
23
|
* @license React
|
|
24
24
|
* react-is.production.js
|
|
25
25
|
*
|
|
@@ -27,7 +27,7 @@ Valid keys: `+JSON.stringify(Object.keys(O),null," "));var U=ke(W,ne,X,ae,Z+"."
|
|
|
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 En;function al(){if(En)return ve;En=1;var t=Symbol.for("react.transitional.element"),o=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),c=Symbol.for("react.consumer"),d=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),m=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),b=Symbol.for("react.lazy"),h=Symbol.for("react.view_transition"),g=Symbol.for("react.client.reference");function z(v){if(typeof v=="object"&&v!==null){var j=v.$$typeof;switch(j){case t:switch(v=v.type,v){case n:case s:case i:case u:case m:case h:return v;default:switch(v=v&&v.$$typeof,v){case d:case l:case b:case f:return v;case c:return v;default:return j}}case o:return j}}}return ve.ContextConsumer=c,ve.ContextProvider=d,ve.Element=t,ve.ForwardRef=l,ve.Fragment=n,ve.Lazy=b,ve.Memo=f,ve.Portal=o,ve.Profiler=s,ve.StrictMode=i,ve.Suspense=u,ve.SuspenseList=m,ve.isContextConsumer=function(v){return z(v)===c},ve.isContextProvider=function(v){return z(v)===d},ve.isElement=function(v){return typeof v=="object"&&v!==null&&v.$$typeof===t},ve.isForwardRef=function(v){return z(v)===l},ve.isFragment=function(v){return z(v)===n},ve.isLazy=function(v){return z(v)===b},ve.isMemo=function(v){return z(v)===f},ve.isPortal=function(v){return z(v)===o},ve.isProfiler=function(v){return z(v)===s},ve.isStrictMode=function(v){return z(v)===i},ve.isSuspense=function(v){return z(v)===u},ve.isSuspenseList=function(v){return z(v)===m},ve.isValidElementType=function(v){return typeof v=="string"||typeof v=="function"||v===n||v===s||v===i||v===u||v===m||typeof v=="object"&&v!==null&&(v.$$typeof===b||v.$$typeof===f||v.$$typeof===d||v.$$typeof===c||v.$$typeof===l||v.$$typeof===g||v.getModuleId!==void 0)},ve.typeOf=z,ve}var Se={};/**
|
|
31
31
|
* @license React
|
|
32
32
|
* react-is.development.js
|
|
33
33
|
*
|
|
@@ -35,15 +35,15 @@ Valid keys: `+JSON.stringify(Object.keys(O),null," "));var U=ke(W,ne,X,ae,Z+"."
|
|
|
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,
|
|
38
|
+
*/var Bn;function ll(){return Bn||(Bn=1,process.env.NODE_ENV!=="production"&&(function(){function t(v){if(typeof v=="object"&&v!==null){var j=v.$$typeof;switch(j){case o:switch(v=v.type,v){case i:case c:case s:case m:case f:case g:return v;default:switch(v=v&&v.$$typeof,v){case l:case u:case h:case b:return v;case d:return v;default:return j}}case n:return j}}}var o=Symbol.for("react.transitional.element"),n=Symbol.for("react.portal"),i=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),d=Symbol.for("react.consumer"),l=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),m=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),b=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),g=Symbol.for("react.view_transition"),z=Symbol.for("react.client.reference");Se.ContextConsumer=d,Se.ContextProvider=l,Se.Element=o,Se.ForwardRef=u,Se.Fragment=i,Se.Lazy=h,Se.Memo=b,Se.Portal=n,Se.Profiler=c,Se.StrictMode=s,Se.Suspense=m,Se.SuspenseList=f,Se.isContextConsumer=function(v){return t(v)===d},Se.isContextProvider=function(v){return t(v)===l},Se.isElement=function(v){return typeof v=="object"&&v!==null&&v.$$typeof===o},Se.isForwardRef=function(v){return t(v)===u},Se.isFragment=function(v){return t(v)===i},Se.isLazy=function(v){return t(v)===h},Se.isMemo=function(v){return t(v)===b},Se.isPortal=function(v){return t(v)===n},Se.isProfiler=function(v){return t(v)===c},Se.isStrictMode=function(v){return t(v)===s},Se.isSuspense=function(v){return t(v)===m},Se.isSuspenseList=function(v){return t(v)===f},Se.isValidElementType=function(v){return typeof v=="string"||typeof v=="function"||v===i||v===c||v===s||v===m||v===f||typeof v=="object"&&v!==null&&(v.$$typeof===h||v.$$typeof===b||v.$$typeof===l||v.$$typeof===d||v.$$typeof===u||v.$$typeof===z||v.getModuleId!==void 0)},Se.typeOf=t})()),Se}var Dn;function cl(){return Dn||(Dn=1,process.env.NODE_ENV==="production"?to.exports=al():to.exports=ll()),to.exports}var Ci=cl();function Bt(t){if(typeof t!="object"||t===null)return!1;const o=Object.getPrototypeOf(t);return(o===null||o===Object.prototype||Object.getPrototypeOf(o)===null)&&!(Symbol.toStringTag in t)&&!(Symbol.iterator in t)}function wi(t){if(po.isValidElement(t)||Ci.isValidElementType(t)||!Bt(t))return t;const o={};return Object.keys(t).forEach(n=>{o[n]=wi(t[n])}),o}function He(t,o,n={clone:!0}){const i=n.clone?{...t}:t;return Bt(t)&&Bt(o)&&Object.keys(o).forEach(s=>{po.isValidElement(o[s])||Ci.isValidElementType(o[s])?i[s]=o[s]:Bt(o[s])&&Object.prototype.hasOwnProperty.call(t,s)&&Bt(t[s])?i[s]=He(t[s],o[s],n):n.clone?i[s]=Bt(o[s])?wi(o[s]):o[s]:i[s]=o[s]}),i}const dl=t=>{const o=Object.keys(t).map(n=>({key:n,val:t[n]}))||[];return o.sort((n,i)=>n.val-i.val),o.reduce((n,i)=>({...n,[i.key]:i.val}),{})};function ul(t){const{values:o={xs:0,sm:600,md:900,lg:1200,xl:1536},unit:n="px",step:i=5,...s}=t,c=dl(o),d=Object.keys(c);function l(h){return`@media (min-width:${typeof o[h]=="number"?o[h]:h}${n})`}function u(h){return`@media (max-width:${(typeof o[h]=="number"?o[h]:h)-i/100}${n})`}function m(h,g){const z=d.indexOf(g);return`@media (min-width:${typeof o[h]=="number"?o[h]:h}${n}) and (max-width:${(z!==-1&&typeof o[d[z]]=="number"?o[d[z]]:g)-i/100}${n})`}function f(h){return d.indexOf(h)+1<d.length?m(h,d[d.indexOf(h)+1]):l(h)}function b(h){const g=d.indexOf(h);return g===0?l(d[1]):g===d.length-1?u(d[g]):m(h,d[d.indexOf(h)+1]).replace("@media","@media not all and")}return{keys:d,values:c,up:l,down:u,between:m,only:f,not:b,unit:n,...s}}function On(t,o){if(!t.containerQueries)return o;const n=Object.keys(o).filter(i=>i.startsWith("@container")).sort((i,s)=>{var d,l;const c=/min-width:\s*([0-9.]+)/;return+(((d=i.match(c))==null?void 0:d[1])||0)-+(((l=s.match(c))==null?void 0:l[1])||0)});return n.length?n.reduce((i,s)=>{const c=o[s];return delete i[s],i[s]=c,i},{...o}):o}function pl(t,o){return o==="@"||o.startsWith("@")&&(t.some(n=>o.startsWith(`@${n}`))||!!o.match(/^@\d/))}function xl(t,o){const n=o.match(/^@([^/]+)?\/?(.+)?$/);if(!n){if(process.env.NODE_ENV!=="production")throw new Error(`MUI: The provided shorthand ${`(${o})`} is invalid. The format should be \`@<breakpoint | number>\` or \`@<breakpoint | number>/<container>\`.
|
|
39
|
+
For example, \`@sm\` or \`@600\` or \`@40rem/sidebar\`.`);return null}const[,i,s]=n,c=Number.isNaN(+i)?i||0:+i;return t.containerQueries(s).up(c)}function ml(t){const o=(c,d)=>c.replace("@media",d?`@container ${d}`:"@container");function n(c,d){c.up=(...l)=>o(t.breakpoints.up(...l),d),c.down=(...l)=>o(t.breakpoints.down(...l),d),c.between=(...l)=>o(t.breakpoints.between(...l),d),c.only=(...l)=>o(t.breakpoints.only(...l),d),c.not=(...l)=>{const u=o(t.breakpoints.not(...l),d);return u.includes("not all and")?u.replace("not all and ","").replace("min-width:","width<").replace("max-width:","width>").replace("and","or"):u}}const i={},s=c=>(n(i,c),i);return n(s),{...t,containerQueries:s}}const fl={borderRadius:4},Ot=process.env.NODE_ENV!=="production"?_r.oneOfType([_r.number,_r.string,_r.object,_r.array]):{};function Ur(t,o){return o?He(t,o,{clone:!1}):t}const fo={xs:0,sm:600,md:900,lg:1200,xl:1536},Mn={keys:["xs","sm","md","lg","xl"],up:t=>`@media (min-width:${fo[t]}px)`},hl={containerQueries:t=>({up:o=>{let n=typeof o=="number"?o:fo[o]||o;return typeof n=="number"&&(n=`${n}px`),t?`@container ${t} (min-width:${n})`:`@container (min-width:${n})`}})};function Ct(t,o,n){const i=t.theme||{};if(Array.isArray(o)){const c=i.breakpoints||Mn;return o.reduce((d,l,u)=>(d[c.up(c.keys[u])]=n(o[u]),d),{})}if(typeof o=="object"){const c=i.breakpoints||Mn;return Object.keys(o).reduce((d,l)=>{if(pl(c.keys,l)){const u=xl(i.containerQueries?i:hl,l);u&&(d[u]=n(o[l],l))}else if(Object.keys(c.values||fo).includes(l)){const u=c.up(l);d[u]=n(o[l],l)}else{const u=l;d[u]=o[u]}return d},{})}return n(o)}function gl(t={}){var n;return((n=t.keys)==null?void 0:n.reduce((i,s)=>{const c=t.up(s);return i[c]={},i},{}))||{}}function An(t,o){return t.reduce((n,i)=>{const s=n[i];return(!s||Object.keys(s).length===0)&&delete n[i],n},o)}function ki(t){if(typeof t!="string")throw new Error(process.env.NODE_ENV!=="production"?"MUI: `capitalize(string)` expects a string argument.":Ut(7));return t.charAt(0).toUpperCase()+t.slice(1)}function ho(t,o,n=!0){if(!o||typeof o!="string")return null;if(t&&t.vars&&n){const i=`vars.${o}`.split(".").reduce((s,c)=>s&&s[c]?s[c]:null,t);if(i!=null)return i}return o.split(".").reduce((i,s)=>i&&i[s]!=null?i[s]:null,t)}function uo(t,o,n,i=n){let s;return typeof t=="function"?s=t(n):Array.isArray(t)?s=t[n]||i:s=ho(t,n)||i,o&&(s=o(s,i,t)),s}function Ee(t){const{prop:o,cssProperty:n=t.prop,themeKey:i,transform:s}=t,c=d=>{if(d[o]==null)return null;const l=d[o],u=d.theme,m=ho(u,i)||{};return Ct(d,l,b=>{let h=uo(m,s,b);return b===h&&typeof b=="string"&&(h=uo(m,s,`${o}${b==="default"?"":ki(b)}`,b)),n===!1?h:{[n]:h}})};return c.propTypes=process.env.NODE_ENV!=="production"?{[o]:Ot}:{},c.filterProps=[o],c}function yl(t){const o={};return n=>(o[n]===void 0&&(o[n]=t(n)),o[n])}const bl={m:"margin",p:"padding"},vl={t:"Top",r:"Right",b:"Bottom",l:"Left",x:["Left","Right"],y:["Top","Bottom"]},$n={marginX:"mx",marginY:"my",paddingX:"px",paddingY:"py"},Sl=yl(t=>{if(t.length>2)if($n[t])t=$n[t];else return[t];const[o,n]=t.split(""),i=bl[o],s=vl[n]||"";return Array.isArray(s)?s.map(c=>i+c):[i+s]}),go=["m","mt","mr","mb","ml","mx","my","margin","marginTop","marginRight","marginBottom","marginLeft","marginX","marginY","marginInline","marginInlineStart","marginInlineEnd","marginBlock","marginBlockStart","marginBlockEnd"],yo=["p","pt","pr","pb","pl","px","py","padding","paddingTop","paddingRight","paddingBottom","paddingLeft","paddingX","paddingY","paddingInline","paddingInlineStart","paddingInlineEnd","paddingBlock","paddingBlockStart","paddingBlockEnd"],jl=[...go,...yo];function Gr(t,o,n,i){const s=ho(t,o,!0)??n;return typeof s=="number"||typeof s=="string"?c=>typeof c=="string"?c:(process.env.NODE_ENV!=="production"&&typeof c!="number"&&console.error(`MUI: Expected ${i} argument to be a number or a string, got ${c}.`),typeof s=="string"?s.startsWith("var(")&&c===0?0:s.startsWith("var(")&&c===1?s:`calc(${c} * ${s})`:s*c):Array.isArray(s)?c=>{if(typeof c=="string")return c;const d=Math.abs(c);process.env.NODE_ENV!=="production"&&(Number.isInteger(d)?d>s.length-1&&console.error([`MUI: The value provided (${d}) overflows.`,`The supported values are: ${JSON.stringify(s)}.`,`${d} > ${s.length-1}, you need to add the missing values.`].join(`
|
|
40
40
|
`)):console.error([`MUI: The \`theme.${o}\` array type cannot be combined with non integer values.You should either use an integer value that can be used as index, or define the \`theme.${o}\` as a number.`].join(`
|
|
41
|
-
`)));const
|
|
42
|
-
`)),()=>{})}function Lo(t){return _r(t,"spacing",8,"spacing")}function Pr(t,o){return typeof o=="string"||o==null?o:t(o)}function Va(t,o){return n=>t.reduce((i,a)=>(i[a]=Pr(o,n),i),{})}function Ha(t,o,n,i){if(!o.includes(n))return null;const a=Fa(n),l=Va(a,i),c=t[n];return Ct(t,c,l)}function ci(t,o){const n=Lo(t.theme);return Object.keys(t).map(i=>Ha(t,o,i,n)).reduce(Mr,{})}function Ie(t){return ci(t,lo)}Ie.propTypes=process.env.NODE_ENV!=="production"?lo.reduce((t,o)=>(t[o]=Ot,t),{}):{};Ie.filterProps=lo;function Ee(t){return ci(t,co)}Ee.propTypes=process.env.NODE_ENV!=="production"?co.reduce((t,o)=>(t[o]=Ot,t),{}):{};Ee.filterProps=co;process.env.NODE_ENV!=="production"&&La.reduce((t,o)=>(t[o]=Ot,t),{});function di(t=8,o=Lo({spacing:t})){if(t.mui)return t;const n=(...i)=>(process.env.NODE_ENV!=="production"&&(i.length<=4||console.error(`MUI: Too many arguments provided, expected between 0 and 4, got ${i.length}`)),(i.length===0?[1]:i).map(l=>{const c=o(l);return typeof c=="number"?`${c}px`:c}).join(" "));return n.mui=!0,n}function uo(...t){const o=t.reduce((i,a)=>(a.filterProps.forEach(l=>{i[l]=a}),i),{}),n=i=>Object.keys(i).reduce((a,l)=>o[l]?Mr(a,o[l](i)):a,{});return n.propTypes=process.env.NODE_ENV!=="production"?t.reduce((i,a)=>Object.assign(i,a.propTypes),{}):{},n.filterProps=t.reduce((i,a)=>i.concat(a.filterProps),[]),n}function qe(t){return typeof t!="number"?t:`${t}px solid`}function Je(t,o){return De({prop:t,themeKey:"borders",transform:o})}const Ua=Je("border",qe),Ga=Je("borderTop",qe),Ya=Je("borderRight",qe),qa=Je("borderBottom",qe),Ja=Je("borderLeft",qe),Ka=Je("borderColor"),Xa=Je("borderTopColor"),Qa=Je("borderRightColor"),Za=Je("borderBottomColor"),el=Je("borderLeftColor"),tl=Je("outline",qe),rl=Je("outlineColor"),po=t=>{if(t.borderRadius!==void 0&&t.borderRadius!==null){const o=_r(t.theme,"shape.borderRadius",4,"borderRadius"),n=i=>({borderRadius:Pr(o,i)});return Ct(t,t.borderRadius,n)}return null};po.propTypes=process.env.NODE_ENV!=="production"?{borderRadius:Ot}:{};po.filterProps=["borderRadius"];uo(Ua,Ga,Ya,qa,Ja,Ka,Xa,Qa,Za,el,po,tl,rl);const xo=t=>{if(t.gap!==void 0&&t.gap!==null){const o=_r(t.theme,"spacing",8,"gap"),n=i=>({gap:Pr(o,i)});return Ct(t,t.gap,n)}return null};xo.propTypes=process.env.NODE_ENV!=="production"?{gap:Ot}:{};xo.filterProps=["gap"];const fo=t=>{if(t.columnGap!==void 0&&t.columnGap!==null){const o=_r(t.theme,"spacing",8,"columnGap"),n=i=>({columnGap:Pr(o,i)});return Ct(t,t.columnGap,n)}return null};fo.propTypes=process.env.NODE_ENV!=="production"?{columnGap:Ot}:{};fo.filterProps=["columnGap"];const ho=t=>{if(t.rowGap!==void 0&&t.rowGap!==null){const o=_r(t.theme,"spacing",8,"rowGap"),n=i=>({rowGap:Pr(o,i)});return Ct(t,t.rowGap,n)}return null};ho.propTypes=process.env.NODE_ENV!=="production"?{rowGap:Ot}:{};ho.filterProps=["rowGap"];const ol=De({prop:"gridColumn"}),nl=De({prop:"gridRow"}),il=De({prop:"gridAutoFlow"}),sl=De({prop:"gridAutoColumns"}),al=De({prop:"gridAutoRows"}),ll=De({prop:"gridTemplateColumns"}),cl=De({prop:"gridTemplateRows"}),dl=De({prop:"gridTemplateAreas"}),ul=De({prop:"gridArea"});uo(xo,fo,ho,ol,nl,il,sl,al,ll,cl,dl,ul);function cr(t,o){return o==="grey"?o:t}const pl=De({prop:"color",themeKey:"palette",transform:cr}),xl=De({prop:"bgcolor",cssProperty:"backgroundColor",themeKey:"palette",transform:cr}),fl=De({prop:"backgroundColor",themeKey:"palette",transform:cr});uo(pl,xl,fl);function He(t){return t<=1&&t!==0?`${t*100}%`:t}const hl=De({prop:"width",transform:He}),Vo=t=>{if(t.maxWidth!==void 0&&t.maxWidth!==null){const o=n=>{var a,l,c,d,u;const i=((c=(l=(a=t.theme)==null?void 0:a.breakpoints)==null?void 0:l.values)==null?void 0:c[n])||so[n];return i?((u=(d=t.theme)==null?void 0:d.breakpoints)==null?void 0:u.unit)!=="px"?{maxWidth:`${i}${t.theme.breakpoints.unit}`}:{maxWidth:i}:{maxWidth:He(n)}};return Ct(t,t.maxWidth,o)}return null};Vo.filterProps=["maxWidth"];const ml=De({prop:"minWidth",transform:He}),gl=De({prop:"height",transform:He}),yl=De({prop:"maxHeight",transform:He}),bl=De({prop:"minHeight",transform:He});De({prop:"size",cssProperty:"width",transform:He});De({prop:"size",cssProperty:"height",transform:He});const vl=De({prop:"boxSizing"});uo(hl,Vo,ml,gl,yl,bl,vl);const mo={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:po},color:{themeKey:"palette",transform:cr},bgcolor:{themeKey:"palette",cssProperty:"backgroundColor",transform:cr},backgroundColor:{themeKey:"palette",transform:cr},p:{style:Ee},pt:{style:Ee},pr:{style:Ee},pb:{style:Ee},pl:{style:Ee},px:{style:Ee},py:{style:Ee},padding:{style:Ee},paddingTop:{style:Ee},paddingRight:{style:Ee},paddingBottom:{style:Ee},paddingLeft:{style:Ee},paddingX:{style:Ee},paddingY:{style:Ee},paddingInline:{style:Ee},paddingInlineStart:{style:Ee},paddingInlineEnd:{style:Ee},paddingBlock:{style:Ee},paddingBlockStart:{style:Ee},paddingBlockEnd:{style:Ee},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:xo},rowGap:{style:ho},columnGap:{style:fo},gridColumn:{},gridRow:{},gridAutoFlow:{},gridAutoColumns:{},gridAutoRows:{},gridTemplateColumns:{},gridTemplateRows:{},gridTemplateAreas:{},gridArea:{},position:{},zIndex:{themeKey:"zIndex"},top:{},right:{},bottom:{},left:{},boxShadow:{themeKey:"shadows"},width:{transform:He},maxWidth:{style:Vo},minWidth:{transform:He},height:{transform:He},maxHeight:{transform:He},minHeight:{transform:He},boxSizing:{},font:{themeKey:"font"},fontFamily:{themeKey:"typography"},fontSize:{themeKey:"typography"},fontStyle:{themeKey:"typography"},fontWeight:{themeKey:"typography"},letterSpacing:{},textTransform:{},lineHeight:{},textAlign:{},typography:{cssProperty:!1,themeKey:"typography"}};function Sl(...t){const o=t.reduce((i,a)=>i.concat(Object.keys(a)),[]),n=new Set(o);return t.every(i=>n.size===Object.keys(i).length)}function Cl(t,o){return typeof t=="function"?t(o):t}function jl(){function t(n,i,a,l){const c={[n]:i,theme:a},d=l[n];if(!d)return{[n]:i};const{cssProperty:u=n,themeKey:f,transform:h,style:m}=d;if(i==null)return null;if(f==="typography"&&i==="inherit")return{[n]:i};const v=ao(a,f)||{};return m?m(c):Ct(c,i,z=>{let y=ro(v,h,z);return z===y&&typeof z=="string"&&(y=ro(v,h,`${n}${z==="default"?"":li(z)}`,z)),u===!1?y:{[u]:y}})}function o(n){const{sx:i,theme:a={},nested:l}=n||{};if(!i)return null;const c=a.unstable_sxConfig??mo;function d(u){let f=u;if(typeof u=="function")f=u(a);else if(typeof u!="object")return u;if(!f)return null;const h=_a(a.breakpoints),m=Object.keys(h);let v=h;return Object.keys(f).forEach(w=>{const z=Cl(f[w],a);if(z!=null)if(typeof z=="object")if(c[w])v=Mr(v,t(w,z,a,c));else{const y=Ct({theme:a},z,j=>({[w]:j}));Sl(y,z)?v[w]=o({sx:z,theme:a,nested:!0}):v=Mr(v,y)}else v=Mr(v,t(w,z,a,c))}),!l&&a.modularCssLayers?{"@layer sx":Sn(a,jn(m,v))}:Sn(a,jn(m,v))}return Array.isArray(i)?i.map(d):d(i)}return o}const go=jl();go.filterProps=["sx"];function wl(t,o){var i;const n=this;if(n.vars){if(!((i=n.colorSchemes)!=null&&i[t])||typeof n.getColorSchemeSelector!="function")return{};let a=n.getColorSchemeSelector(t);return a==="&"?o:((a.includes("data-")||a.includes("."))&&(a=`*:where(${a.replace(/\s*&$/,"")}) &`),{[a]:o})}return n.palette.mode===t?o:{}}function ui(t={},...o){const{breakpoints:n={},palette:i={},spacing:a,shape:l={},...c}=t,d=Ba(n),u=di(a);let f=Ue({breakpoints:d,direction:"ltr",components:{},palette:{mode:"light",...i},spacing:u,shape:{...Wa,...l}},c);return f=Ma(f),f.applyStyles=wl,f=o.reduce((h,m)=>Ue(h,m),f),f.unstable_sxConfig={...mo,...c==null?void 0:c.unstable_sxConfig},f.unstable_sx=function(m){return go({sx:m,theme:this})},f}function kl(t){return Object.keys(t).length===0}function Tl(t=null){const o=oo.useContext(ns.ThemeContext);return!o||kl(o)?t:o}const zl=ui();function Il(t=zl){return Tl(t)}const kn=t=>t,El=()=>{let t=kn;return{configure(o){t=o},generate(o){return t(o)},reset(){t=kn}}},Dl=El(),Bl={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 Ol(t,o,n="Mui"){const i=Bl[o];return i?`${n}-${i}`:`${Dl.generate(t)}-${o}`}function Al(t,o=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER){return Math.max(o,Math.min(t,n))}function Ho(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}].`),Al(t,o,n)}function Ml(t){t=t.slice(1);const o=new RegExp(`.{1,${t.length>=6?2:1}}`,"g");let n=t.match(o);return n&&n[0].length===1&&(n=n.map(i=>i+i)),process.env.NODE_ENV!=="production"&&t.length!==t.trim().length&&console.error(`MUI: The color: "${t}" is invalid. Make sure the color input doesn't contain leading/trailing space.`),n?`rgb${n.length===4?"a":""}(${n.map((i,a)=>a<3?parseInt(i,16):Math.round(parseInt(i,16)/255*1e3)/1e3).join(", ")})`:""}function Bt(t){if(t.type)return t;if(t.charAt(0)==="#")return Bt(Ml(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 \`${
|
|
41
|
+
`)));const l=s[d];return c>=0?l:typeof l=="number"?-l:typeof l=="string"&&l.startsWith("var(")?`calc(-1 * ${l})`:`-${l}`}:typeof s=="function"?s:(process.env.NODE_ENV!=="production"&&console.error([`MUI: The \`theme.${o}\` value (${s}) is invalid.`,"It should be a number, an array or a function."].join(`
|
|
42
|
+
`)),()=>{})}function Xo(t){return Gr(t,"spacing",8,"spacing")}function qr(t,o){return typeof o=="string"||o==null?o:t(o)}function Cl(t,o){return n=>t.reduce((i,s)=>(i[s]=qr(o,n),i),{})}function wl(t,o,n,i){if(!o.includes(n))return null;const s=Sl(n),c=Cl(s,i),d=t[n];return Ct(t,d,c)}function Ti(t,o){const n=Xo(t.theme);return Object.keys(t).map(i=>wl(t,o,i,n)).reduce(Ur,{})}function ze(t){return Ti(t,go)}ze.propTypes=process.env.NODE_ENV!=="production"?go.reduce((t,o)=>(t[o]=Ot,t),{}):{};ze.filterProps=go;function Ie(t){return Ti(t,yo)}Ie.propTypes=process.env.NODE_ENV!=="production"?yo.reduce((t,o)=>(t[o]=Ot,t),{}):{};Ie.filterProps=yo;process.env.NODE_ENV!=="production"&&jl.reduce((t,o)=>(t[o]=Ot,t),{});function zi(t=8,o=Xo({spacing:t})){if(t.mui)return t;const n=(...i)=>(process.env.NODE_ENV!=="production"&&(i.length<=4||console.error(`MUI: Too many arguments provided, expected between 0 and 4, got ${i.length}`)),(i.length===0?[1]:i).map(c=>{const d=o(c);return typeof d=="number"?`${d}px`:d}).join(" "));return n.mui=!0,n}function bo(...t){const o=t.reduce((i,s)=>(s.filterProps.forEach(c=>{i[c]=s}),i),{}),n=i=>Object.keys(i).reduce((s,c)=>o[c]?Ur(s,o[c](i)):s,{});return n.propTypes=process.env.NODE_ENV!=="production"?t.reduce((i,s)=>Object.assign(i,s.propTypes),{}):{},n.filterProps=t.reduce((i,s)=>i.concat(s.filterProps),[]),n}function Ye(t){return typeof t!="number"?t:`${t}px solid`}function Ge(t,o){return Ee({prop:t,themeKey:"borders",transform:o})}const kl=Ge("border",Ye),Tl=Ge("borderTop",Ye),zl=Ge("borderRight",Ye),Il=Ge("borderBottom",Ye),El=Ge("borderLeft",Ye),Bl=Ge("borderColor"),Dl=Ge("borderTopColor"),Ol=Ge("borderRightColor"),Ml=Ge("borderBottomColor"),Al=Ge("borderLeftColor"),$l=Ge("outline",Ye),Rl=Ge("outlineColor"),vo=t=>{if(t.borderRadius!==void 0&&t.borderRadius!==null){const o=Gr(t.theme,"shape.borderRadius",4,"borderRadius"),n=i=>({borderRadius:qr(o,i)});return Ct(t,t.borderRadius,n)}return null};vo.propTypes=process.env.NODE_ENV!=="production"?{borderRadius:Ot}:{};vo.filterProps=["borderRadius"];bo(kl,Tl,zl,Il,El,Bl,Dl,Ol,Ml,Al,vo,$l,Rl);const So=t=>{if(t.gap!==void 0&&t.gap!==null){const o=Gr(t.theme,"spacing",8,"gap"),n=i=>({gap:qr(o,i)});return Ct(t,t.gap,n)}return null};So.propTypes=process.env.NODE_ENV!=="production"?{gap:Ot}:{};So.filterProps=["gap"];const jo=t=>{if(t.columnGap!==void 0&&t.columnGap!==null){const o=Gr(t.theme,"spacing",8,"columnGap"),n=i=>({columnGap:qr(o,i)});return Ct(t,t.columnGap,n)}return null};jo.propTypes=process.env.NODE_ENV!=="production"?{columnGap:Ot}:{};jo.filterProps=["columnGap"];const Co=t=>{if(t.rowGap!==void 0&&t.rowGap!==null){const o=Gr(t.theme,"spacing",8,"rowGap"),n=i=>({rowGap:qr(o,i)});return Ct(t,t.rowGap,n)}return null};Co.propTypes=process.env.NODE_ENV!=="production"?{rowGap:Ot}:{};Co.filterProps=["rowGap"];const _l=Ee({prop:"gridColumn"}),Wl=Ee({prop:"gridRow"}),Pl=Ee({prop:"gridAutoFlow"}),Nl=Ee({prop:"gridAutoColumns"}),Fl=Ee({prop:"gridAutoRows"}),Ll=Ee({prop:"gridTemplateColumns"}),Vl=Ee({prop:"gridTemplateRows"}),Hl=Ee({prop:"gridTemplateAreas"}),Ul=Ee({prop:"gridArea"});bo(So,jo,Co,_l,Wl,Pl,Nl,Fl,Ll,Vl,Hl,Ul);function gr(t,o){return o==="grey"?o:t}const Yl=Ee({prop:"color",themeKey:"palette",transform:gr}),Gl=Ee({prop:"bgcolor",cssProperty:"backgroundColor",themeKey:"palette",transform:gr}),ql=Ee({prop:"backgroundColor",themeKey:"palette",transform:gr});bo(Yl,Gl,ql);function Le(t){return t<=1&&t!==0?`${t*100}%`:t}const Jl=Ee({prop:"width",transform:Le}),Zo=t=>{if(t.maxWidth!==void 0&&t.maxWidth!==null){const o=n=>{var s,c,d,l,u;const i=((d=(c=(s=t.theme)==null?void 0:s.breakpoints)==null?void 0:c.values)==null?void 0:d[n])||fo[n];return i?((u=(l=t.theme)==null?void 0:l.breakpoints)==null?void 0:u.unit)!=="px"?{maxWidth:`${i}${t.theme.breakpoints.unit}`}:{maxWidth:i}:{maxWidth:Le(n)}};return Ct(t,t.maxWidth,o)}return null};Zo.filterProps=["maxWidth"];const Kl=Ee({prop:"minWidth",transform:Le}),Xl=Ee({prop:"height",transform:Le}),Zl=Ee({prop:"maxHeight",transform:Le}),Ql=Ee({prop:"minHeight",transform:Le});Ee({prop:"size",cssProperty:"width",transform:Le});Ee({prop:"size",cssProperty:"height",transform:Le});const ec=Ee({prop:"boxSizing"});bo(Jl,Zo,Kl,Xl,Zl,Ql,ec);const wo={border:{themeKey:"borders",transform:Ye},borderTop:{themeKey:"borders",transform:Ye},borderRight:{themeKey:"borders",transform:Ye},borderBottom:{themeKey:"borders",transform:Ye},borderLeft:{themeKey:"borders",transform:Ye},borderColor:{themeKey:"palette"},borderTopColor:{themeKey:"palette"},borderRightColor:{themeKey:"palette"},borderBottomColor:{themeKey:"palette"},borderLeftColor:{themeKey:"palette"},outline:{themeKey:"borders",transform:Ye},outlineColor:{themeKey:"palette"},borderRadius:{themeKey:"shape.borderRadius",style:vo},color:{themeKey:"palette",transform:gr},bgcolor:{themeKey:"palette",cssProperty:"backgroundColor",transform:gr},backgroundColor:{themeKey:"palette",transform:gr},p:{style:Ie},pt:{style:Ie},pr:{style:Ie},pb:{style:Ie},pl:{style:Ie},px:{style:Ie},py:{style:Ie},padding:{style:Ie},paddingTop:{style:Ie},paddingRight:{style:Ie},paddingBottom:{style:Ie},paddingLeft:{style:Ie},paddingX:{style:Ie},paddingY:{style:Ie},paddingInline:{style:Ie},paddingInlineStart:{style:Ie},paddingInlineEnd:{style:Ie},paddingBlock:{style:Ie},paddingBlockStart:{style:Ie},paddingBlockEnd:{style:Ie},m:{style:ze},mt:{style:ze},mr:{style:ze},mb:{style:ze},ml:{style:ze},mx:{style:ze},my:{style:ze},margin:{style:ze},marginTop:{style:ze},marginRight:{style:ze},marginBottom:{style:ze},marginLeft:{style:ze},marginX:{style:ze},marginY:{style:ze},marginInline:{style:ze},marginInlineStart:{style:ze},marginInlineEnd:{style:ze},marginBlock:{style:ze},marginBlockStart:{style:ze},marginBlockEnd:{style:ze},displayPrint:{cssProperty:!1,transform:t=>({"@media print":{display:t}})},display:{},overflow:{},textOverflow:{},visibility:{},whiteSpace:{},flexBasis:{},flexDirection:{},flexWrap:{},justifyContent:{},alignItems:{},alignContent:{},order:{},flex:{},flexGrow:{},flexShrink:{},alignSelf:{},justifyItems:{},justifySelf:{},gap:{style:So},rowGap:{style:Co},columnGap:{style:jo},gridColumn:{},gridRow:{},gridAutoFlow:{},gridAutoColumns:{},gridAutoRows:{},gridTemplateColumns:{},gridTemplateRows:{},gridTemplateAreas:{},gridArea:{},position:{},zIndex:{themeKey:"zIndex"},top:{},right:{},bottom:{},left:{},boxShadow:{themeKey:"shadows"},width:{transform:Le},maxWidth:{style:Zo},minWidth:{transform:Le},height:{transform:Le},maxHeight:{transform:Le},minHeight:{transform:Le},boxSizing:{},font:{themeKey:"font"},fontFamily:{themeKey:"typography"},fontSize:{themeKey:"typography"},fontStyle:{themeKey:"typography"},fontWeight:{themeKey:"typography"},letterSpacing:{},textTransform:{},lineHeight:{},textAlign:{},typography:{cssProperty:!1,themeKey:"typography"}};function tc(...t){const o=t.reduce((i,s)=>i.concat(Object.keys(s)),[]),n=new Set(o);return t.every(i=>n.size===Object.keys(i).length)}function rc(t,o){return typeof t=="function"?t(o):t}function oc(){function t(n,i,s,c){const d={[n]:i,theme:s},l=c[n];if(!l)return{[n]:i};const{cssProperty:u=n,themeKey:m,transform:f,style:b}=l;if(i==null)return null;if(m==="typography"&&i==="inherit")return{[n]:i};const h=ho(s,m)||{};return b?b(d):Ct(d,i,z=>{let v=uo(h,f,z);return z===v&&typeof z=="string"&&(v=uo(h,f,`${n}${z==="default"?"":ki(z)}`,z)),u===!1?v:{[u]:v}})}function o(n){const{sx:i,theme:s={},nested:c}=n||{};if(!i)return null;const d=s.unstable_sxConfig??wo;function l(u){let m=u;if(typeof u=="function")m=u(s);else if(typeof u!="object")return u;if(!m)return null;const f=gl(s.breakpoints),b=Object.keys(f);let h=f;return Object.keys(m).forEach(g=>{const z=rc(m[g],s);if(z!=null)if(typeof z=="object")if(d[g])h=Ur(h,t(g,z,s,d));else{const v=Ct({theme:s},z,j=>({[g]:j}));tc(v,z)?h[g]=o({sx:z,theme:s,nested:!0}):h=Ur(h,v)}else h=Ur(h,t(g,z,s,d))}),!c&&s.modularCssLayers?{"@layer sx":On(s,An(b,h))}:On(s,An(b,h))}return Array.isArray(i)?i.map(l):l(i)}return o}const ko=oc();ko.filterProps=["sx"];function nc(t,o){var i;const n=this;if(n.vars){if(!((i=n.colorSchemes)!=null&&i[t])||typeof n.getColorSchemeSelector!="function")return{};let s=n.getColorSchemeSelector(t);return s==="&"?o:((s.includes("data-")||s.includes("."))&&(s=`*:where(${s.replace(/\s*&$/,"")}) &`),{[s]:o})}return n.palette.mode===t?o:{}}function Ii(t={},...o){const{breakpoints:n={},palette:i={},spacing:s,shape:c={},...d}=t,l=ul(n),u=zi(s);let m=He({breakpoints:l,direction:"ltr",components:{},palette:{mode:"light",...i},spacing:u,shape:{...fl,...c}},d);return m=ml(m),m.applyStyles=nc,m=o.reduce((f,b)=>He(f,b),m),m.unstable_sxConfig={...wo,...d==null?void 0:d.unstable_sxConfig},m.unstable_sx=function(b){return ko({sx:b,theme:this})},m}function ic(t){return Object.keys(t).length===0}function sc(t=null){const o=po.useContext(js.ThemeContext);return!o||ic(o)?t:o}const ac=Ii();function lc(t=ac){return sc(t)}const Rn=t=>t,cc=()=>{let t=Rn;return{configure(o){t=o},generate(o){return t(o)},reset(){t=Rn}}},dc=cc(),uc={active:"active",checked:"checked",completed:"completed",disabled:"disabled",error:"error",expanded:"expanded",focused:"focused",focusVisible:"focusVisible",open:"open",readOnly:"readOnly",required:"required",selected:"selected"};function pc(t,o,n="Mui"){const i=uc[o];return i?`${n}-${i}`:`${dc.generate(t)}-${o}`}function xc(t,o=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER){return Math.max(o,Math.min(t,n))}function Qo(t,o=0,n=1){return process.env.NODE_ENV!=="production"&&(t<o||t>n)&&console.error(`MUI: The value provided ${t} is out of range [${o}, ${n}].`),xc(t,o,n)}function mc(t){t=t.slice(1);const o=new RegExp(`.{1,${t.length>=6?2:1}}`,"g");let n=t.match(o);return n&&n[0].length===1&&(n=n.map(i=>i+i)),process.env.NODE_ENV!=="production"&&t.length!==t.trim().length&&console.error(`MUI: The color: "${t}" is invalid. Make sure the color input doesn't contain leading/trailing space.`),n?`rgb${n.length===4?"a":""}(${n.map((i,s)=>s<3?parseInt(i,16):Math.round(parseInt(i,16)/255*1e3)/1e3).join(", ")})`:""}function Dt(t){if(t.type)return t;if(t.charAt(0)==="#")return Dt(mc(t));const o=t.indexOf("("),n=t.substring(0,o);if(!["rgb","rgba","hsl","hsla","color"].includes(n))throw new Error(process.env.NODE_ENV!=="production"?`MUI: Unsupported \`${t}\` color.
|
|
43
|
+
The following formats are supported: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color().`:Ut(9,t));let i=t.substring(o+1,t.length-1),s;if(n==="color"){if(i=i.split(" "),s=i.shift(),i.length===4&&i[3].charAt(0)==="/"&&(i[3]=i[3].slice(1)),!["srgb","display-p3","a98-rgb","prophoto-rgb","rec-2020"].includes(s))throw new Error(process.env.NODE_ENV!=="production"?`MUI: unsupported \`${s}\` color space.
|
|
44
|
+
The following color spaces are supported: srgb, display-p3, a98-rgb, prophoto-rgb, rec-2020.`:Ut(10,s))}else i=i.split(",");return i=i.map(c=>parseFloat(c)),{type:n,values:i,colorSpace:s}}const fc=t=>{const o=Dt(t);return o.values.slice(0,3).map((n,i)=>o.type.includes("hsl")&&i!==0?`${n}%`:n).join(" ")},Lr=(t,o)=>{try{return fc(t)}catch{return o&&process.env.NODE_ENV!=="production"&&console.warn(o),t}};function To(t){const{type:o,colorSpace:n}=t;let{values:i}=t;return o.includes("rgb")?i=i.map((s,c)=>c<3?parseInt(s,10):s):o.includes("hsl")&&(i[1]=`${i[1]}%`,i[2]=`${i[2]}%`),o.includes("color")?i=`${n} ${i.join(" ")}`:i=`${i.join(", ")}`,`${o}(${i})`}function Ei(t){t=Dt(t);const{values:o}=t,n=o[0],i=o[1]/100,s=o[2]/100,c=i*Math.min(s,1-s),d=(m,f=(m+n/30)%12)=>s-c*Math.max(Math.min(f-3,9-f,1),-1);let l="rgb";const u=[Math.round(d(0)*255),Math.round(d(8)*255),Math.round(d(4)*255)];return t.type==="hsla"&&(l+="a",u.push(o[3])),To({type:l,values:u})}function Fo(t){t=Dt(t);let o=t.type==="hsl"||t.type==="hsla"?Dt(Ei(t)).values:t.values;return o=o.map(n=>(t.type!=="color"&&(n/=255),n<=.03928?n/12.92:((n+.055)/1.055)**2.4)),Number((.2126*o[0]+.7152*o[1]+.0722*o[2]).toFixed(3))}function _n(t,o){const n=Fo(t),i=Fo(o);return(Math.max(n,i)+.05)/(Math.min(n,i)+.05)}function E(t,o){return t=Dt(t),o=Qo(o),(t.type==="rgb"||t.type==="hsl")&&(t.type+="a"),t.type==="color"?t.values[3]=`/${o}`:t.values[3]=o,To(t)}function Lt(t,o,n){try{return E(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function zo(t,o){if(t=Dt(t),o=Qo(o),t.type.includes("hsl"))t.values[2]*=1-o;else if(t.type.includes("rgb")||t.type.includes("color"))for(let n=0;n<3;n+=1)t.values[n]*=1-o;return To(t)}function he(t,o,n){try{return zo(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function Io(t,o){if(t=Dt(t),o=Qo(o),t.type.includes("hsl"))t.values[2]+=(100-t.values[2])*o;else if(t.type.includes("rgb"))for(let n=0;n<3;n+=1)t.values[n]+=(255-t.values[n])*o;else if(t.type.includes("color"))for(let n=0;n<3;n+=1)t.values[n]+=(1-t.values[n])*o;return To(t)}function ge(t,o,n){try{return Io(t,o)}catch{return n&&process.env.NODE_ENV!=="production"&&console.warn(n),t}}function hc(t,o=.15){return Fo(t)>.5?zo(t,o):Io(t,o)}function ro(t,o,n){try{return hc(t,o)}catch{return t}}function gc(t=""){function o(...i){if(!i.length)return"";const s=i[0];return typeof s=="string"&&!s.match(/(#|\(|\)|(-?(\d*\.)?\d+)(px|em|%|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))|^(-?(\d*\.)?\d+)$|(\d+ \d+ \d+)/)?`, var(--${t?`${t}-`:""}${s}${o(...i.slice(1))})`:`, ${s}`}return(i,...s)=>`var(--${t?`${t}-`:""}${i}${o(...s)})`}const Wn=(t,o,n,i=[])=>{let s=t;o.forEach((c,d)=>{d===o.length-1?Array.isArray(s)?s[Number(c)]=n:s&&typeof s=="object"&&(s[c]=n):s&&typeof s=="object"&&(s[c]||(s[c]=i.includes(c)?[]:{}),s=s[c])})},yc=(t,o,n)=>{function i(s,c=[],d=[]){Object.entries(s).forEach(([l,u])=>{(!n||n&&!n([...c,l]))&&u!=null&&(typeof u=="object"&&Object.keys(u).length>0?i(u,[...c,l],Array.isArray(u)?[...d,l]:d):o([...c,l],u,d))})}i(t)},bc=(t,o)=>typeof o=="number"?["lineHeight","fontWeight","opacity","zIndex"].some(i=>t.includes(i))||t[t.length-1].toLowerCase().includes("opacity")?o:`${o}px`:o;function _o(t,o){const{prefix:n,shouldSkipGeneratingVar:i}=o||{},s={},c={},d={};return yc(t,(l,u,m)=>{if((typeof u=="string"||typeof u=="number")&&(!i||!i(l,u))){const f=`--${n?`${n}-`:""}${l.join("-")}`,b=bc(l,u);Object.assign(s,{[f]:b}),Wn(c,l,`var(${f})`,m),Wn(d,l,`var(${f}, ${b})`,m)}},l=>l[0]==="vars"),{css:s,vars:c,varsWithDefaults:d}}function vc(t,o={}){const{getSelector:n=S,disableCssColorScheme:i,colorSchemeSelector:s,enableContrastVars:c}=o,{colorSchemes:d={},components:l,defaultColorScheme:u="light",...m}=t,{vars:f,css:b,varsWithDefaults:h}=_o(m,o);let g=h;const z={},{[u]:v,...j}=d;if(Object.entries(j||{}).forEach(([a,k])=>{const{vars:D,css:O,varsWithDefaults:R}=_o(k,o);g=He(g,R),z[a]={css:O,vars:D}}),v){const{css:a,vars:k,varsWithDefaults:D}=_o(v,o);g=He(g,D),z[u]={css:a,vars:k}}function S(a,k){var O,R;let D=s;if(s==="class"&&(D=".%s"),s==="data"&&(D="[data-%s]"),s!=null&&s.startsWith("data-")&&!s.includes("%s")&&(D=`[${s}="%s"]`),a){if(D==="media")return t.defaultColorScheme===a?":root":{[`@media (prefers-color-scheme: ${((R=(O=d[a])==null?void 0:O.palette)==null?void 0:R.mode)||a})`]:{":root":k}};if(D)return t.defaultColorScheme===a?`:root, ${D.replace("%s",String(a))}`:D.replace("%s",String(a))}return":root"}return{vars:g,generateThemeVars:()=>{let a={...f};return Object.entries(z).forEach(([,{vars:k}])=>{a=He(a,k)}),a},generateStyleSheets:()=>{var U,J;const a=[],k=t.defaultColorScheme||"light";function D(ee,x){Object.keys(x).length&&a.push(typeof ee=="string"?{[ee]:{...x}}:ee)}D(n(void 0,{...b}),b);const{[k]:O,...R}=z;if(O){const{css:ee}=O,x=(J=(U=d[k])==null?void 0:U.palette)==null?void 0:J.mode,N=!i&&x?{colorScheme:x,...ee}:{...ee};D(n(k,{...N}),N)}return Object.entries(R).forEach(([ee,{css:x}])=>{var H,q;const N=(q=(H=d[ee])==null?void 0:H.palette)==null?void 0:q.mode,_=!i&&N?{colorScheme:N,...x}:{...x};D(n(ee,{..._}),_)}),c&&a.push({":root":{"--__l-threshold":"0.7","--__l":"clamp(0, (l / var(--__l-threshold) - 1) * -infinity, 1)","--__a":"clamp(0.87, (l / var(--__l-threshold) - 1) * -infinity, 1)"}}),a}}}function Sc(t){return function(n){return t==="media"?(process.env.NODE_ENV!=="production"&&n!=="light"&&n!=="dark"&&console.error(`MUI: @media (prefers-color-scheme) supports only 'light' or 'dark', but receive '${n}'.`),`@media (prefers-color-scheme: ${n})`):t?t.startsWith("data-")&&!t.includes("%s")?`[${t}="${n}"] &`:t==="class"?`.${n} &`:t==="data"?`[data-${n}] &`:`${t.replace("%s",n)} &`:"&"}}const Yr={black:"#000",white:"#fff"},jc={50:"#fafafa",100:"#f5f5f5",200:"#eeeeee",300:"#e0e0e0",400:"#bdbdbd",500:"#9e9e9e",600:"#757575",700:"#616161",800:"#424242",900:"#212121",A100:"#f5f5f5",A200:"#eeeeee",A400:"#bdbdbd",A700:"#616161"},pr={50:"#f3e5f5",200:"#ce93d8",300:"#ba68c8",400:"#ab47bc",500:"#9c27b0",700:"#7b1fa2"},xr={300:"#e57373",400:"#ef5350",500:"#f44336",700:"#d32f2f",800:"#c62828"},Wr={300:"#ffb74d",400:"#ffa726",500:"#ff9800",700:"#f57c00",900:"#e65100"},mr={50:"#e3f2fd",200:"#90caf9",400:"#42a5f5",700:"#1976d2",800:"#1565c0"},fr={300:"#4fc3f7",400:"#29b6f6",500:"#03a9f4",700:"#0288d1",900:"#01579b"},hr={300:"#81c784",400:"#66bb6a",500:"#4caf50",700:"#388e3c",800:"#2e7d32",900:"#1b5e20"};function Bi(){return{text:{primary:"rgba(0, 0, 0, 0.87)",secondary:"rgba(0, 0, 0, 0.6)",disabled:"rgba(0, 0, 0, 0.38)"},divider:"rgba(0, 0, 0, 0.12)",background:{paper:Yr.white,default:Yr.white},action:{active:"rgba(0, 0, 0, 0.54)",hover:"rgba(0, 0, 0, 0.04)",hoverOpacity:.04,selected:"rgba(0, 0, 0, 0.08)",selectedOpacity:.08,disabled:"rgba(0, 0, 0, 0.26)",disabledBackground:"rgba(0, 0, 0, 0.12)",disabledOpacity:.38,focus:"rgba(0, 0, 0, 0.12)",focusOpacity:.12,activatedOpacity:.12}}}const Di=Bi();function Oi(){return{text:{primary:Yr.white,secondary:"rgba(255, 255, 255, 0.7)",disabled:"rgba(255, 255, 255, 0.5)",icon:"rgba(255, 255, 255, 0.5)"},divider:"rgba(255, 255, 255, 0.12)",background:{paper:"#121212",default:"#121212"},action:{active:Yr.white,hover:"rgba(255, 255, 255, 0.08)",hoverOpacity:.08,selected:"rgba(255, 255, 255, 0.16)",selectedOpacity:.16,disabled:"rgba(255, 255, 255, 0.3)",disabledBackground:"rgba(255, 255, 255, 0.12)",disabledOpacity:.38,focus:"rgba(255, 255, 255, 0.12)",focusOpacity:.12,activatedOpacity:.24}}}const Lo=Oi();function Pn(t,o,n,i){const s=i.light||i,c=i.dark||i*1.5;t[o]||(t.hasOwnProperty(n)?t[o]=t[n]:o==="light"?t.light=Io(t.main,s):o==="dark"&&(t.dark=zo(t.main,c)))}function Nn(t,o,n,i,s){const c=s.light||s,d=s.dark||s*1.5;o[n]||(o.hasOwnProperty(i)?o[n]=o[i]:n==="light"?o.light=`color-mix(in ${t}, ${o.main}, #fff ${(c*100).toFixed(0)}%)`:n==="dark"&&(o.dark=`color-mix(in ${t}, ${o.main}, #000 ${(d*100).toFixed(0)}%)`))}function Cc(t="light"){return t==="dark"?{main:mr[200],light:mr[50],dark:mr[400]}:{main:mr[700],light:mr[400],dark:mr[800]}}function wc(t="light"){return t==="dark"?{main:pr[200],light:pr[50],dark:pr[400]}:{main:pr[500],light:pr[300],dark:pr[700]}}function kc(t="light"){return t==="dark"?{main:xr[500],light:xr[300],dark:xr[700]}:{main:xr[700],light:xr[400],dark:xr[800]}}function Tc(t="light"){return t==="dark"?{main:fr[400],light:fr[300],dark:fr[700]}:{main:fr[700],light:fr[500],dark:fr[900]}}function zc(t="light"){return t==="dark"?{main:hr[400],light:hr[300],dark:hr[700]}:{main:hr[800],light:hr[500],dark:hr[900]}}function Ic(t="light"){return t==="dark"?{main:Wr[400],light:Wr[300],dark:Wr[700]}:{main:"#ed6c02",light:Wr[500],dark:Wr[900]}}function Ec(t){return`oklch(from ${t} var(--__l) 0 h / var(--__a))`}function en(t){const{mode:o="light",contrastThreshold:n=3,tonalOffset:i=.2,colorSpace:s,...c}=t,d=t.primary||Cc(o),l=t.secondary||wc(o),u=t.error||kc(o),m=t.info||Tc(o),f=t.success||zc(o),b=t.warning||Ic(o);function h(j){if(s)return Ec(j);const S=_n(j,Lo.text.primary)>=n?Lo.text.primary:Di.text.primary;if(process.env.NODE_ENV!=="production"){const y=_n(j,S);y<3&&console.error([`MUI: The contrast ratio of ${y}:1 for ${S} on ${j}`,"falls below the WCAG recommended absolute minimum contrast ratio of 3:1.","https://www.w3.org/TR/2008/REC-WCAG20-20081211/#visual-audio-contrast-contrast"].join(`
|
|
45
|
+
`))}return S}const g=({color:j,name:S,mainShade:y=500,lightShade:T=300,darkShade:a=700})=>{if(j={...j},!j.main&&j[y]&&(j.main=j[y]),!j.hasOwnProperty("main"))throw new Error(process.env.NODE_ENV!=="production"?`MUI: The color${S?` (${S})`:""} provided to augmentColor(color) is invalid.
|
|
46
|
+
The color object needs to have a \`main\` property or a \`${y}\` property.`:Ut(11,S?` (${S})`:"",y));if(typeof j.main!="string")throw new Error(process.env.NODE_ENV!=="production"?`MUI: The color${S?` (${S})`:""} provided to augmentColor(color) is invalid.
|
|
47
47
|
\`color.main\` should be a string, but \`${JSON.stringify(j.main)}\` was provided instead.
|
|
48
48
|
|
|
49
49
|
Did you intend to use one of the following approaches?
|
|
@@ -56,17 +56,17 @@ const theme1 = createTheme({ palette: {
|
|
|
56
56
|
|
|
57
57
|
const theme2 = createTheme({ palette: {
|
|
58
58
|
primary: { main: green[500] },
|
|
59
|
-
} });`:
|
|
60
|
-
`)),Object.keys(
|
|
59
|
+
} });`:Ut(12,S?` (${S})`:"",JSON.stringify(j.main)));return s?(Nn(s,j,"light",T,i),Nn(s,j,"dark",a,i)):(Pn(j,"light",T,i),Pn(j,"dark",a,i)),j.contrastText||(j.contrastText=h(j.main)),j};let z;return o==="light"?z=Bi():o==="dark"&&(z=Oi()),process.env.NODE_ENV!=="production"&&(z||console.error(`MUI: The palette mode \`${o}\` is not supported.`)),He({common:{...Yr},mode:o,primary:g({color:d,name:"primary"}),secondary:g({color:l,name:"secondary",mainShade:"A400",lightShade:"A200",darkShade:"A700"}),error:g({color:u,name:"error"}),warning:g({color:b,name:"warning"}),info:g({color:m,name:"info"}),success:g({color:f,name:"success"}),grey:jc,contrastThreshold:n,getContrastText:h,augmentColor:g,tonalOffset:i,...z},c)}function Bc(t){const o={};return Object.entries(t).forEach(i=>{const[s,c]=i;typeof c=="object"&&(o[s]=`${c.fontStyle?`${c.fontStyle} `:""}${c.fontVariant?`${c.fontVariant} `:""}${c.fontWeight?`${c.fontWeight} `:""}${c.fontStretch?`${c.fontStretch} `:""}${c.fontSize||""}${c.lineHeight?`/${c.lineHeight} `:""}${c.fontFamily||""}`)}),o}function Dc(t,o){return{toolbar:{minHeight:56,[t.up("xs")]:{"@media (orientation: landscape)":{minHeight:48}},[t.up("sm")]:{minHeight:64}},...o}}function Oc(t){return Math.round(t*1e5)/1e5}const Fn={textTransform:"uppercase"},Ln='"Roboto", "Helvetica", "Arial", sans-serif';function Mc(t,o){const{fontFamily:n=Ln,fontSize:i=14,fontWeightLight:s=300,fontWeightRegular:c=400,fontWeightMedium:d=500,fontWeightBold:l=700,htmlFontSize:u=16,allVariants:m,pxToRem:f,...b}=typeof o=="function"?o(t):o;process.env.NODE_ENV!=="production"&&(typeof i!="number"&&console.error("MUI: `fontSize` is required to be a number."),typeof u!="number"&&console.error("MUI: `htmlFontSize` is required to be a number."));const h=i/14,g=f||(j=>`${j/u*h}rem`),z=(j,S,y,T,a)=>({fontFamily:n,fontWeight:j,fontSize:g(S),lineHeight:y,...n===Ln?{letterSpacing:`${Oc(T/S)}em`}:{},...a,...m}),v={h1:z(s,96,1.167,-1.5),h2:z(s,60,1.2,-.5),h3:z(c,48,1.167,0),h4:z(c,34,1.235,.25),h5:z(c,24,1.334,0),h6:z(d,20,1.6,.15),subtitle1:z(c,16,1.75,.15),subtitle2:z(d,14,1.57,.1),body1:z(c,16,1.5,.15),body2:z(c,14,1.43,.15),button:z(d,14,1.75,.4,Fn),caption:z(c,12,1.66,.4),overline:z(c,12,2.66,1,Fn),inherit:{fontFamily:"inherit",fontWeight:"inherit",fontSize:"inherit",lineHeight:"inherit",letterSpacing:"inherit"}};return He({htmlFontSize:u,pxToRem:g,fontFamily:n,fontSize:i,fontWeightLight:s,fontWeightRegular:c,fontWeightMedium:d,fontWeightBold:l,...v},b,{clone:!1})}const Ac=.2,$c=.14,Rc=.12;function we(...t){return[`${t[0]}px ${t[1]}px ${t[2]}px ${t[3]}px rgba(0,0,0,${Ac})`,`${t[4]}px ${t[5]}px ${t[6]}px ${t[7]}px rgba(0,0,0,${$c})`,`${t[8]}px ${t[9]}px ${t[10]}px ${t[11]}px rgba(0,0,0,${Rc})`].join(",")}const _c=["none",we(0,2,1,-1,0,1,1,0,0,1,3,0),we(0,3,1,-2,0,2,2,0,0,1,5,0),we(0,3,3,-2,0,3,4,0,0,1,8,0),we(0,2,4,-1,0,4,5,0,0,1,10,0),we(0,3,5,-1,0,5,8,0,0,1,14,0),we(0,3,5,-1,0,6,10,0,0,1,18,0),we(0,4,5,-2,0,7,10,1,0,2,16,1),we(0,5,5,-3,0,8,10,1,0,3,14,2),we(0,5,6,-3,0,9,12,1,0,3,16,2),we(0,6,6,-3,0,10,14,1,0,4,18,3),we(0,6,7,-4,0,11,15,1,0,4,20,3),we(0,7,8,-4,0,12,17,2,0,5,22,4),we(0,7,8,-4,0,13,19,2,0,5,24,4),we(0,7,9,-4,0,14,21,2,0,5,26,4),we(0,8,9,-5,0,15,22,2,0,6,28,5),we(0,8,10,-5,0,16,24,2,0,6,30,5),we(0,8,11,-5,0,17,26,2,0,6,32,5),we(0,9,11,-5,0,18,28,2,0,7,34,6),we(0,9,12,-6,0,19,29,2,0,7,36,6),we(0,10,13,-6,0,20,31,3,0,8,38,7),we(0,10,13,-6,0,21,33,3,0,8,40,7),we(0,10,14,-6,0,22,35,3,0,8,42,7),we(0,11,14,-7,0,23,36,3,0,9,44,8),we(0,11,15,-7,0,24,38,3,0,9,46,8)],Wc={easeInOut:"cubic-bezier(0.4, 0, 0.2, 1)",easeOut:"cubic-bezier(0.0, 0, 0.2, 1)",easeIn:"cubic-bezier(0.4, 0, 1, 1)",sharp:"cubic-bezier(0.4, 0, 0.6, 1)"},Pc={shortest:150,shorter:200,short:250,standard:300,complex:375,enteringScreen:225,leavingScreen:195};function Vn(t){return`${Math.round(t)}ms`}function Nc(t){if(!t)return 0;const o=t/36;return Math.min(Math.round((4+15*o**.25+o/5)*10),3e3)}function Fc(t){const o={...Wc,...t.easing},n={...Pc,...t.duration};return{getAutoHeightDuration:Nc,create:(s=["all"],c={})=>{const{duration:d=n.standard,easing:l=o.easeInOut,delay:u=0,...m}=c;if(process.env.NODE_ENV!=="production"){const f=h=>typeof h=="string",b=h=>!Number.isNaN(parseFloat(h));!f(s)&&!Array.isArray(s)&&console.error('MUI: Argument "props" must be a string or Array.'),!b(d)&&!f(d)&&console.error(`MUI: Argument "duration" must be a number or a string but found ${d}.`),f(l)||console.error('MUI: Argument "easing" must be a string.'),!b(u)&&!f(u)&&console.error('MUI: Argument "delay" must be a number or a string.'),typeof c!="object"&&console.error(["MUI: Secong argument of transition.create must be an object.","Arguments should be either `create('prop1', options)` or `create(['prop1', 'prop2'], options)`"].join(`
|
|
60
|
+
`)),Object.keys(m).length!==0&&console.error(`MUI: Unrecognized argument(s) [${Object.keys(m).join(",")}].`)}return(Array.isArray(s)?s:[s]).map(f=>`${f} ${typeof d=="string"?d:Vn(d)} ${l} ${typeof u=="string"?u:Vn(u)}`).join(",")},...t,easing:o,duration:n}}const Lc={mobileStepper:1e3,fab:1050,speedDial:1050,appBar:1100,drawer:1200,modal:1300,snackbar:1400,tooltip:1500};function Vc(t){return Bt(t)||typeof t>"u"||typeof t=="string"||typeof t=="boolean"||typeof t=="number"||Array.isArray(t)}function Mi(t={}){const o={...t};function n(i){const s=Object.entries(i);for(let c=0;c<s.length;c++){const[d,l]=s[c];!Vc(l)||d.startsWith("unstable_")?delete i[d]:Bt(l)&&(i[d]={...l},n(i[d]))}}return n(o),`import { unstable_createBreakpoints as createBreakpoints, createTransitions } from '@mui/material/styles';
|
|
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 bc(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{}},vc=(t="mui")=>_l(t);function Bo(t,o,n,i,a){if(!n)return;n=n===!0?{}:n;const l=a==="dark"?"dark":"light";if(!i){o[a]=fc({...n,palette:{mode:l,...n==null?void 0:n.palette},colorSpace:t});return}const{palette:c,...d}=Mo({...i,palette:{mode:l,...n==null?void 0:n.palette},colorSpace:t});return o[a]={...n,palette:c,opacity:{...gi(l),...n==null?void 0:n.opacity},overlays:(n==null?void 0:n.overlays)||yi(l)},d}function Sc(t={},...o){const{colorSchemes:n={light:!0},defaultColorScheme:i,disableCssColorScheme:a=!1,cssVarPrefix:l="mui",nativeColor:c=!1,shouldSkipGeneratingVar:d=hc,colorSchemeSelector:u=n.light&&n.dark?"media":void 0,rootSelector:f=":root",...h}=t,m=Object.keys(n)[0],v=i||(n.light&&m!=="light"?"light":m),w=vc(l),{[v]:z,light:y,dark:j,...b}=n,g={...b};let S=z;if((v==="dark"&&!("dark"in n)||v==="light"&&!("light"in n))&&(S=!0),!S)throw new Error(process.env.NODE_ENV!=="production"?`MUI: The \`colorSchemes.${v}\` option is either missing or invalid.`:Ht(21,v));let s;c&&(s="oklch");const I=Bo(s,g,S,h,v);y&&!g.light&&Bo(s,g,y,void 0,"light"),j&&!g.dark&&Bo(s,g,j,void 0,"dark");let A={defaultColorScheme:v,...I,cssVarPrefix:l,colorSchemeSelector:u,rootSelector:f,getCssVar:w,colorSchemes:g,font:{...Kl(I.typography),...I.font},spacing:bc(h.spacing)};Object.keys(A.colorSchemes).forEach(se=>{const x=A.colorSchemes[se].palette,V=J=>{const oe=J.split("-"),ue=oe[1],pe=oe[2];return w(J,x[ue][pe])};x.mode==="light"&&(M(x.common,"background","#fff"),M(x.common,"onBackground","#000")),x.mode==="dark"&&(M(x.common,"background","#000"),M(x.common,"onBackground","#fff"));function $(J,oe,ue){if(s){let pe;return J===Ft&&(pe=`transparent ${((1-ue)*100).toFixed(0)}%`),J===he&&(pe=`#000 ${(ue*100).toFixed(0)}%`),J===me&&(pe=`#fff ${(ue*100).toFixed(0)}%`),`color-mix(in ${s}, ${oe}, ${pe})`}return J(oe,ue)}if(yc(x,["Alert","AppBar","Avatar","Button","Chip","FilledInput","LinearProgress","Skeleton","Slider","SnackbarContent","SpeedDialAction","StepConnector","StepContent","Switch","TableCell","Tooltip"]),x.mode==="light"){M(x.Alert,"errorColor",$(he,x.error.light,.6)),M(x.Alert,"infoColor",$(he,x.info.light,.6)),M(x.Alert,"successColor",$(he,x.success.light,.6)),M(x.Alert,"warningColor",$(he,x.warning.light,.6)),M(x.Alert,"errorFilledBg",V("palette-error-main")),M(x.Alert,"infoFilledBg",V("palette-info-main")),M(x.Alert,"successFilledBg",V("palette-success-main")),M(x.Alert,"warningFilledBg",V("palette-warning-main")),M(x.Alert,"errorFilledColor",lt(()=>x.getContrastText(x.error.main))),M(x.Alert,"infoFilledColor",lt(()=>x.getContrastText(x.info.main))),M(x.Alert,"successFilledColor",lt(()=>x.getContrastText(x.success.main))),M(x.Alert,"warningFilledColor",lt(()=>x.getContrastText(x.warning.main))),M(x.Alert,"errorStandardBg",$(me,x.error.light,.9)),M(x.Alert,"infoStandardBg",$(me,x.info.light,.9)),M(x.Alert,"successStandardBg",$(me,x.success.light,.9)),M(x.Alert,"warningStandardBg",$(me,x.warning.light,.9)),M(x.Alert,"errorIconColor",V("palette-error-main")),M(x.Alert,"infoIconColor",V("palette-info-main")),M(x.Alert,"successIconColor",V("palette-success-main")),M(x.Alert,"warningIconColor",V("palette-warning-main")),M(x.AppBar,"defaultBg",V("palette-grey-100")),M(x.Avatar,"defaultBg",V("palette-grey-400")),M(x.Button,"inheritContainedBg",V("palette-grey-300")),M(x.Button,"inheritContainedHoverBg",V("palette-grey-A100")),M(x.Chip,"defaultBorder",V("palette-grey-400")),M(x.Chip,"defaultAvatarColor",V("palette-grey-700")),M(x.Chip,"defaultIconColor",V("palette-grey-700")),M(x.FilledInput,"bg","rgba(0, 0, 0, 0.06)"),M(x.FilledInput,"hoverBg","rgba(0, 0, 0, 0.09)"),M(x.FilledInput,"disabledBg","rgba(0, 0, 0, 0.12)"),M(x.LinearProgress,"primaryBg",$(me,x.primary.main,.62)),M(x.LinearProgress,"secondaryBg",$(me,x.secondary.main,.62)),M(x.LinearProgress,"errorBg",$(me,x.error.main,.62)),M(x.LinearProgress,"infoBg",$(me,x.info.main,.62)),M(x.LinearProgress,"successBg",$(me,x.success.main,.62)),M(x.LinearProgress,"warningBg",$(me,x.warning.main,.62)),M(x.Skeleton,"bg",s?$(Ft,x.text.primary,.11):`rgba(${V("palette-text-primaryChannel")} / 0.11)`),M(x.Slider,"primaryTrack",$(me,x.primary.main,.62)),M(x.Slider,"secondaryTrack",$(me,x.secondary.main,.62)),M(x.Slider,"errorTrack",$(me,x.error.main,.62)),M(x.Slider,"infoTrack",$(me,x.info.main,.62)),M(x.Slider,"successTrack",$(me,x.success.main,.62)),M(x.Slider,"warningTrack",$(me,x.warning.main,.62));const J=s?$(he,x.background.default,.6825):Jr(x.background.default,.8);M(x.SnackbarContent,"bg",J),M(x.SnackbarContent,"color",lt(()=>s?Ao.text.primary:x.getContrastText(J))),M(x.SpeedDialAction,"fabHoverBg",Jr(x.background.paper,.15)),M(x.StepConnector,"border",V("palette-grey-400")),M(x.StepContent,"border",V("palette-grey-400")),M(x.Switch,"defaultColor",V("palette-common-white")),M(x.Switch,"defaultDisabledColor",V("palette-grey-100")),M(x.Switch,"primaryDisabledColor",$(me,x.primary.main,.62)),M(x.Switch,"secondaryDisabledColor",$(me,x.secondary.main,.62)),M(x.Switch,"errorDisabledColor",$(me,x.error.main,.62)),M(x.Switch,"infoDisabledColor",$(me,x.info.main,.62)),M(x.Switch,"successDisabledColor",$(me,x.success.main,.62)),M(x.Switch,"warningDisabledColor",$(me,x.warning.main,.62)),M(x.TableCell,"border",$(me,$(Ft,x.divider,1),.88)),M(x.Tooltip,"bg",$(Ft,x.grey[700],.92))}if(x.mode==="dark"){M(x.Alert,"errorColor",$(me,x.error.light,.6)),M(x.Alert,"infoColor",$(me,x.info.light,.6)),M(x.Alert,"successColor",$(me,x.success.light,.6)),M(x.Alert,"warningColor",$(me,x.warning.light,.6)),M(x.Alert,"errorFilledBg",V("palette-error-dark")),M(x.Alert,"infoFilledBg",V("palette-info-dark")),M(x.Alert,"successFilledBg",V("palette-success-dark")),M(x.Alert,"warningFilledBg",V("palette-warning-dark")),M(x.Alert,"errorFilledColor",lt(()=>x.getContrastText(x.error.dark))),M(x.Alert,"infoFilledColor",lt(()=>x.getContrastText(x.info.dark))),M(x.Alert,"successFilledColor",lt(()=>x.getContrastText(x.success.dark))),M(x.Alert,"warningFilledColor",lt(()=>x.getContrastText(x.warning.dark))),M(x.Alert,"errorStandardBg",$(he,x.error.light,.9)),M(x.Alert,"infoStandardBg",$(he,x.info.light,.9)),M(x.Alert,"successStandardBg",$(he,x.success.light,.9)),M(x.Alert,"warningStandardBg",$(he,x.warning.light,.9)),M(x.Alert,"errorIconColor",V("palette-error-main")),M(x.Alert,"infoIconColor",V("palette-info-main")),M(x.Alert,"successIconColor",V("palette-success-main")),M(x.Alert,"warningIconColor",V("palette-warning-main")),M(x.AppBar,"defaultBg",V("palette-grey-900")),M(x.AppBar,"darkBg",V("palette-background-paper")),M(x.AppBar,"darkColor",V("palette-text-primary")),M(x.Avatar,"defaultBg",V("palette-grey-600")),M(x.Button,"inheritContainedBg",V("palette-grey-800")),M(x.Button,"inheritContainedHoverBg",V("palette-grey-700")),M(x.Chip,"defaultBorder",V("palette-grey-700")),M(x.Chip,"defaultAvatarColor",V("palette-grey-300")),M(x.Chip,"defaultIconColor",V("palette-grey-300")),M(x.FilledInput,"bg","rgba(255, 255, 255, 0.09)"),M(x.FilledInput,"hoverBg","rgba(255, 255, 255, 0.13)"),M(x.FilledInput,"disabledBg","rgba(255, 255, 255, 0.12)"),M(x.LinearProgress,"primaryBg",$(he,x.primary.main,.5)),M(x.LinearProgress,"secondaryBg",$(he,x.secondary.main,.5)),M(x.LinearProgress,"errorBg",$(he,x.error.main,.5)),M(x.LinearProgress,"infoBg",$(he,x.info.main,.5)),M(x.LinearProgress,"successBg",$(he,x.success.main,.5)),M(x.LinearProgress,"warningBg",$(he,x.warning.main,.5)),M(x.Skeleton,"bg",s?$(Ft,x.text.primary,.13):`rgba(${V("palette-text-primaryChannel")} / 0.13)`),M(x.Slider,"primaryTrack",$(he,x.primary.main,.5)),M(x.Slider,"secondaryTrack",$(he,x.secondary.main,.5)),M(x.Slider,"errorTrack",$(he,x.error.main,.5)),M(x.Slider,"infoTrack",$(he,x.info.main,.5)),M(x.Slider,"successTrack",$(he,x.success.main,.5)),M(x.Slider,"warningTrack",$(he,x.warning.main,.5));const J=s?$(me,x.background.default,.985):Jr(x.background.default,.98);M(x.SnackbarContent,"bg",J),M(x.SnackbarContent,"color",lt(()=>s?fi.text.primary:x.getContrastText(J))),M(x.SpeedDialAction,"fabHoverBg",Jr(x.background.paper,.15)),M(x.StepConnector,"border",V("palette-grey-600")),M(x.StepContent,"border",V("palette-grey-600")),M(x.Switch,"defaultColor",V("palette-grey-300")),M(x.Switch,"defaultDisabledColor",V("palette-grey-600")),M(x.Switch,"primaryDisabledColor",$(he,x.primary.main,.55)),M(x.Switch,"secondaryDisabledColor",$(he,x.secondary.main,.55)),M(x.Switch,"errorDisabledColor",$(he,x.error.main,.55)),M(x.Switch,"infoDisabledColor",$(he,x.info.main,.55)),M(x.Switch,"successDisabledColor",$(he,x.success.main,.55)),M(x.Switch,"warningDisabledColor",$(he,x.warning.main,.55)),M(x.TableCell,"border",$(he,$(Ft,x.divider,1),.68)),M(x.Tooltip,"bg",$(Ft,x.grey[700],.92))}bt(x.background,"default"),bt(x.background,"paper"),bt(x.common,"background"),bt(x.common,"onBackground"),bt(x,"divider"),Object.keys(x).forEach(J=>{const oe=x[J];J!=="tonalOffset"&&oe&&typeof oe=="object"&&(oe.main&&M(x[J],"mainChannel",Or(Ar(oe.main))),oe.light&&M(x[J],"lightChannel",Or(Ar(oe.light))),oe.dark&&M(x[J],"darkChannel",Or(Ar(oe.dark))),oe.contrastText&&M(x[J],"contrastTextChannel",Or(Ar(oe.contrastText))),J==="text"&&(bt(x[J],"primary"),bt(x[J],"secondary")),J==="action"&&(oe.active&&bt(x[J],"active"),oe.selected&&bt(x[J],"selected")))})}),A=o.reduce((se,x)=>Ue(se,x),A);const H={prefix:l,disableCssColorScheme:a,shouldSkipGeneratingVar:d,getSelector:gc(A),enableContrastVars:c},{vars:N,generateThemeVars:K,generateStyleSheets:te}=Nl(A,H);return A.vars=N,Object.entries(A.colorSchemes[A.defaultColorScheme]).forEach(([se,x])=>{A[se]=x}),A.generateThemeVars=K,A.generateStyleSheets=te,A.generateSpacing=function(){return di(h.spacing,Lo(this))},A.getColorSchemeSelector=Fl(u),A.spacing=A.generateSpacing(),A.shouldSkipGeneratingVar=d,A.unstable_sxConfig={...mo,...h==null?void 0:h.unstable_sxConfig},A.unstable_sx=function(x){return go({sx:x,theme:this})},A.toRuntimeSource=mi,A}function Mn(t,o,n){t.colorSchemes&&n&&(t.colorSchemes[o]={...n!==!0&&n,palette:Uo({...n===!0?{}:n.palette,mode:o})})}function Cc(t={},...o){const{palette:n,cssVariables:i=!1,colorSchemes:a=n?void 0:{light:!0},defaultColorScheme:l=n==null?void 0:n.mode,...c}=t,d=l||"light",u=a==null?void 0:a[d],f={...a,...n?{[d]:{...typeof u!="boolean"&&u,palette:n}}:void 0};if(i===!1){if(!("colorSchemes"in t))return Mo(t,...o);let h=n;"palette"in t||f[d]&&(f[d]!==!0?h=f[d].palette:d==="dark"&&(h={mode:"dark"}));const m=Mo({...t,palette:h},...o);return m.defaultColorScheme=d,m.colorSchemes=f,m.palette.mode==="light"&&(m.colorSchemes.light={...f.light!==!0&&f.light,palette:m.palette},Mn(m,"dark",f.dark)),m.palette.mode==="dark"&&(m.colorSchemes.dark={...f.dark!==!0&&f.dark,palette:m.palette},Mn(m,"light",f.light)),m}return!n&&!("light"in f)&&d==="light"&&(f.light=!0),Sc({...c,colorSchemes:f,defaultColorScheme:d,...typeof i!="boolean"&&i},...o)}const jc=Cc();function wc(){const t=Il(jc);return process.env.NODE_ENV!=="production"&&oo.useDebugValue(t),t[ga]||t}async function kc(t,o,n){try{new URL(t)}catch{throw new Error("Please enter a valid URL")}const i={"Content-Type":"application/json"};o&&(i.Authorization=`Bearer ${o}`);const a=new AbortController,l=setTimeout(()=>a.abort(),3e4);let c;try{c=await fetch(t,{headers:i,signal:a.signal})}catch(f){throw clearTimeout(l),(f==null?void 0:f.name)==="AbortError"?new Error("Request timed out after 30 seconds"):new Error("Failed to fetch — check the URL and your network connection")}finally{clearTimeout(l)}if(c.status===401)throw new Error("Authentication failed (401) — check your API key");if(!c.ok)throw new Error(`API error ${c.status}: ${c.statusText}`);let d;try{d=await c.json()}catch{throw new Error("Response is not valid JSON")}let u;if(Array.isArray(d))u=d;else if(n&&d[n]&&Array.isArray(d[n]))u=d[n];else{const h=["data","results","items","records"].find(m=>d[m]&&Array.isArray(d[m]));if(h)u=d[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 Tc({isOpen:t,onClose:o,onCreate:n,preloadedData:i,preloadedDataLabel:a}){const[l,c]=p.useState(""),[d,u]=p.useState(!1),[f,h]=p.useState(""),[m,v]=p.useState(null),[w,z]=p.useState(null),[y,j]=p.useState(!1),[b,g]=p.useState(""),S=p.useRef(null),[s,I]=p.useState("json"),[A,H]=p.useState(""),[N,K]=p.useState(""),[te,se]=p.useState(""),[x,V]=p.useState("idle"),[$,J]=p.useState(""),[oe,ue]=p.useState(null),[pe,_]=p.useState(0),O=async W=>{if(g(""),!W.name.endsWith(".json")){g("Only .json files are allowed");return}const ee=10*1024*1024;if(W.size>ee){g("File size exceeds 10MB limit");return}try{const ie=await W.text();let ne;try{ne=JSON.parse(ie)}catch{g("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(ne)){g("JSON must be an array of objects");return}if(ne.length===0){g("No data rows found in JSON file");return}v(W),z(ne)}catch{g("Network error — please try again")}},L=W=>{W.preventDefault();const ee=W.dataTransfer.files[0];ee&&O(ee)},re=async()=>{if(A.trim()){V("loading"),J("");try{const W=await kc(A.trim(),N.trim()||void 0,te.trim()||void 0);ue(W.data),_(W.data.length),V("ready")}catch(W){J((W==null?void 0:W.message)||"Connection failed"),V("error")}}},Q=()=>{if(!l.trim()){u(!0);return}const W=s==="api"?oe:i||w;W&&(n(l.trim(),f.trim(),W),X())},X=()=>{c(""),u(!1),h(""),v(null),z(null),g(""),I("json"),H(""),K(""),se(""),V("idle"),J(""),ue(null),_(0),o()},ae=i||w,Z=d&&!l.trim();return l.trim(),e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:X,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:X,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:l,onChange:W=>{c(W.target.value),d&&W.target.value.trim()&&u(!1)},placeholder:"Enter report name",autoFocus:!0,error:Z,helperText:Z?"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:f,onChange:W=>h(W.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:s==="json"?0:1,onChange:(W,ee)=>{I(ee===0?"json":"api"),V("idle"),J("")},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}})]}),s==="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:W=>R(W.palette.success.main,.04),display:"flex",alignItems:"center",gap:2},children:[e.jsx(r.Box,{sx:{width:36,height:36,borderRadius:"50%",bgcolor:W=>R(W.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:a||`${i.length.toLocaleString()} records loaded`}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary"},children:"Data source is connected — ready to create"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:1.25},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Data source"}),e.jsx(r.IconButton,{size:"small",onClick:()=>j(!0),sx:{p:.25,color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:e.jsx(k.Info,{sx:{fontSize:16}})})]}),e.jsxs(r.Box,{onDrop:L,onDragOver:W=>W.preventDefault(),onPaste:W=>W.preventDefault(),onClick:()=>{var W;return(W=S.current)==null?void 0:W.click()},sx:{position:"relative",border:"1.5px",borderStyle:w?"solid":"dashed",borderColor:w?"success.main":b?"error.main":"primary.main",borderRadius:2,p:3,textAlign:"center",cursor:"pointer",bgcolor:w?W=>R(W.palette.success.main,.04):b?W=>R(W.palette.error.main,.04):W=>R(W.palette.primary.main,.04),transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:w?W=>R(W.palette.success.main,.08):b?W=>R(W.palette.error.main,.08):W=>R(W.palette.primary.main,.08),borderColor:w?"success.dark":b?"error.dark":"primary.dark"}},children:[e.jsx(r.Box,{component:"input",ref:S,type:"file",accept:".json",sx:{display:"none"},onChange:W=>{var ee;return((ee=W.target.files)==null?void 0:ee[0])&&O(W.target.files[0])}}),w?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:W=>R(W.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:m==null?void 0:m.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:W=>R(W.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"}),b&&e.jsx(r.Box,{sx:{mt:1.25,p:.75,borderRadius:1,bgcolor:W=>R(W.palette.error.main,.08),border:1,borderColor:W=>R(W.palette.error.main,.2)},children:e.jsx(r.Typography,{variant:"caption",sx:{color:"error.main",fontSize:"0.6875rem",fontWeight:500},children:b})})]})]})]})}),s==="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:W=>{H(W.target.value),V("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:N,onChange:W=>K(W.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:te,onChange:W=>se(W.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:re,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:W=>R(W.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:W=>R(W.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:W=>R(W.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:$})]})]})]})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:2,gap:1,borderTop:"1px solid",borderColor:"divider"},children:[e.jsx(r.Button,{onClick:X,variant:"text",sx:{textTransform:"none",color:"primary.main",fontWeight:500,fontSize:"0.875rem",borderRadius:"4px",px:2,py:.625,minWidth:64,"&:hover":{bgcolor:W=>R(W.palette.primary.main,.04)}},children:"Cancel"}),e.jsx(r.Button,{onClick:Q,disabled:s==="json"&&!ae||s==="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:()=>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(k.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{sx:{px:3,py:2},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Required format"}),e.jsx(r.Typography,{variant:"body2",sx:{color:"text.secondary",fontSize:"0.8125rem",lineHeight:1.5},children:"Your JSON file must be an array of objects. Each object represents a row, and all should have the same field names."})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Example structure"}),e.jsx(r.Box,{component:"pre",sx:{bgcolor:"action.hover",border:1,borderColor:"divider",p:2,borderRadius:1,overflow:"auto",maxHeight:200,fontSize:"0.75rem",fontFamily:"monospace",lineHeight:1.5,color:"text.primary"},children:`[
|
|
67
|
+
export default theme;`}function Hn(t){return typeof t=="number"?`${(t*100).toFixed(0)}%`:`calc((${t}) * 100%)`}const Hc=t=>{if(!Number.isNaN(+t))return+t;const o=t.match(/\d*\.?\d+/g);if(!o)return 0;let n=0;for(let i=0;i<o.length;i+=1)n+=+o[i];return n};function Uc(t){Object.assign(t,{alpha(o,n){const i=this||t;return i.colorSpace?`oklch(from ${o} l c h / ${typeof n=="string"?`calc(${n})`:n})`:i.vars?`rgba(${o.replace(/var\(--([^,\s)]+)(?:,[^)]+)?\)+/g,"var(--$1Channel)")} / ${typeof n=="string"?`calc(${n})`:n})`:E(o,Hc(n))},lighten(o,n){const i=this||t;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${o}, #fff ${Hn(n)})`:Io(o,n)},darken(o,n){const i=this||t;return i.colorSpace?`color-mix(in ${i.colorSpace}, ${o}, #000 ${Hn(n)})`:zo(o,n)}})}function Vo(t={},...o){const{breakpoints:n,mixins:i={},spacing:s,palette:c={},transitions:d={},typography:l={},shape:u,colorSpace:m,...f}=t;if(t.vars&&t.generateThemeVars===void 0)throw new Error(process.env.NODE_ENV!=="production"?"MUI: `vars` is a private field used for CSS variables support.\nPlease use another name or follow the [docs](https://mui.com/material-ui/customization/css-theme-variables/usage/) to enable the feature.":Ut(20));const b=en({...c,colorSpace:m}),h=Ii(t);let g=He(h,{mixins:Dc(h.breakpoints,i),palette:b,shadows:_c.slice(),typography:Mc(b,l),transitions:Fc(d),zIndex:{...Lc}});if(g=He(g,f),g=o.reduce((z,v)=>He(z,v),g),process.env.NODE_ENV!=="production"){const z=["active","checked","completed","disabled","error","expanded","focused","focusVisible","required","selected"],v=(j,S)=>{let y;for(y in j){const T=j[y];if(z.includes(y)&&Object.keys(T).length>0){if(process.env.NODE_ENV!=="production"){const a=pc("",y);console.error([`MUI: The \`${S}\` component increases the CSS specificity of the \`${y}\` internal state.`,"You can not override it like this: ",JSON.stringify(j,null,2),"",`Instead, you need to use the '&.${a}' syntax:`,JSON.stringify({root:{[`&.${a}`]:T}},null,2),"","https://mui.com/r/state-classes-guide"].join(`
|
|
68
|
+
`))}j[y]={}}}};Object.keys(g.components).forEach(j=>{const S=g.components[j].styleOverrides;S&&j.startsWith("Mui")&&v(S,j)})}return g.unstable_sxConfig={...wo,...f==null?void 0:f.unstable_sxConfig},g.unstable_sx=function(v){return ko({sx:v,theme:this})},g.toRuntimeSource=Mi,Uc(g),g}function Yc(t){let o;return t<1?o=5.11916*t**2:o=4.5*Math.log(t+1)+2,Math.round(o*10)/1e3}const Gc=[...Array(25)].map((t,o)=>{if(o===0)return"none";const n=Yc(o);return`linear-gradient(rgba(255 255 255 / ${n}), rgba(255 255 255 / ${n}))`});function Ai(t){return{inputPlaceholder:t==="dark"?.5:.42,inputUnderline:t==="dark"?.7:.42,switchTrackDisabled:t==="dark"?.2:.12,switchTrack:t==="dark"?.3:.38}}function $i(t){return t==="dark"?Gc:[]}function qc(t){const{palette:o={mode:"light"},opacity:n,overlays:i,colorSpace:s,...c}=t,d=en({...o,colorSpace:s});return{palette:d,opacity:{...Ai(d.mode),...n},overlays:i||$i(d.mode),...c}}function Jc(t){var o;return!!t[0].match(/(cssVarPrefix|colorSchemeSelector|modularCssLayers|rootSelector|typography|mixins|breakpoints|direction|transitions)/)||!!t[0].match(/sxConfig$/)||t[0]==="palette"&&!!((o=t[1])!=null&&o.match(/(mode|contrastThreshold|tonalOffset)/))}const Kc=t=>[...[...Array(25)].map((o,n)=>`--${t?`${t}-`:""}overlays-${n}`),`--${t?`${t}-`:""}palette-AppBar-darkBg`,`--${t?`${t}-`:""}palette-AppBar-darkColor`],Xc=t=>(o,n)=>{const i=t.rootSelector||":root",s=t.colorSchemeSelector;let c=s;if(s==="class"&&(c=".%s"),s==="data"&&(c="[data-%s]"),s!=null&&s.startsWith("data-")&&!s.includes("%s")&&(c=`[${s}="%s"]`),t.defaultColorScheme===o){if(o==="dark"){const d={};return Kc(t.cssVarPrefix).forEach(l=>{d[l]=n[l],delete n[l]}),c==="media"?{[i]:n,"@media (prefers-color-scheme: dark)":{[i]:d}}:c?{[c.replace("%s",o)]:d,[`${i}, ${c.replace("%s",o)}`]:n}:{[i]:{...n,...d}}}if(c&&c!=="media")return`${i}, ${c.replace("%s",String(o))}`}else if(o){if(c==="media")return{[`@media (prefers-color-scheme: ${String(o)})`]:{[i]:n}};if(c)return c.replace("%s",String(o))}return i};function Zc(t,o){o.forEach(n=>{t[n]||(t[n]={})})}function W(t,o,n){!t[o]&&n&&(t[o]=n)}function Vr(t){return typeof t!="string"||!t.startsWith("hsl")?t:Ei(t)}function vt(t,o){`${o}Channel`in t||(t[`${o}Channel`]=Lr(Vr(t[o]),`MUI: Can't create \`palette.${o}Channel\` because \`palette.${o}\` is not one of these formats: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color().
|
|
69
|
+
To suppress this warning, you need to explicitly provide the \`palette.${o}Channel\` as a string (in rgb format, for example "12 12 12") or undefined if you want to remove the channel token.`))}function Qc(t){return typeof t=="number"?`${t}px`:typeof t=="string"||typeof t=="function"||Array.isArray(t)?t:"8px"}const lt=t=>{try{return t()}catch{}},ed=(t="mui")=>gc(t);function Wo(t,o,n,i,s){if(!n)return;n=n===!0?{}:n;const c=s==="dark"?"dark":"light";if(!i){o[s]=qc({...n,palette:{mode:c,...n==null?void 0:n.palette},colorSpace:t});return}const{palette:d,...l}=Vo({...i,palette:{mode:c,...n==null?void 0:n.palette},colorSpace:t});return o[s]={...n,palette:d,opacity:{...Ai(c),...n==null?void 0:n.opacity},overlays:(n==null?void 0:n.overlays)||$i(c)},l}function td(t={},...o){const{colorSchemes:n={light:!0},defaultColorScheme:i,disableCssColorScheme:s=!1,cssVarPrefix:c="mui",nativeColor:d=!1,shouldSkipGeneratingVar:l=Jc,colorSchemeSelector:u=n.light&&n.dark?"media":void 0,rootSelector:m=":root",...f}=t,b=Object.keys(n)[0],h=i||(n.light&&b!=="light"?"light":b),g=ed(c),{[h]:z,light:v,dark:j,...S}=n,y={...S};let T=z;if((h==="dark"&&!("dark"in n)||h==="light"&&!("light"in n))&&(T=!0),!T)throw new Error(process.env.NODE_ENV!=="production"?`MUI: The \`colorSchemes.${h}\` option is either missing or invalid.`:Ut(21,h));let a;d&&(a="oklch");const k=Wo(a,y,T,f,h);v&&!y.light&&Wo(a,y,v,void 0,"light"),j&&!y.dark&&Wo(a,y,j,void 0,"dark");let D={defaultColorScheme:h,...k,cssVarPrefix:c,colorSchemeSelector:u,rootSelector:m,getCssVar:g,colorSchemes:y,font:{...Bc(k.typography),...k.font},spacing:Qc(f.spacing)};Object.keys(D.colorSchemes).forEach(ee=>{const x=D.colorSchemes[ee].palette,N=H=>{const q=H.split("-"),de=q[1],ue=q[2];return g(H,x[de][ue])};x.mode==="light"&&(W(x.common,"background","#fff"),W(x.common,"onBackground","#000")),x.mode==="dark"&&(W(x.common,"background","#000"),W(x.common,"onBackground","#fff"));function _(H,q,de){if(a){let ue;return H===Lt&&(ue=`transparent ${((1-de)*100).toFixed(0)}%`),H===he&&(ue=`#000 ${(de*100).toFixed(0)}%`),H===ge&&(ue=`#fff ${(de*100).toFixed(0)}%`),`color-mix(in ${a}, ${q}, ${ue})`}return H(q,de)}if(Zc(x,["Alert","AppBar","Avatar","Button","Chip","FilledInput","LinearProgress","Skeleton","Slider","SnackbarContent","SpeedDialAction","StepConnector","StepContent","Switch","TableCell","Tooltip"]),x.mode==="light"){W(x.Alert,"errorColor",_(he,x.error.light,.6)),W(x.Alert,"infoColor",_(he,x.info.light,.6)),W(x.Alert,"successColor",_(he,x.success.light,.6)),W(x.Alert,"warningColor",_(he,x.warning.light,.6)),W(x.Alert,"errorFilledBg",N("palette-error-main")),W(x.Alert,"infoFilledBg",N("palette-info-main")),W(x.Alert,"successFilledBg",N("palette-success-main")),W(x.Alert,"warningFilledBg",N("palette-warning-main")),W(x.Alert,"errorFilledColor",lt(()=>x.getContrastText(x.error.main))),W(x.Alert,"infoFilledColor",lt(()=>x.getContrastText(x.info.main))),W(x.Alert,"successFilledColor",lt(()=>x.getContrastText(x.success.main))),W(x.Alert,"warningFilledColor",lt(()=>x.getContrastText(x.warning.main))),W(x.Alert,"errorStandardBg",_(ge,x.error.light,.9)),W(x.Alert,"infoStandardBg",_(ge,x.info.light,.9)),W(x.Alert,"successStandardBg",_(ge,x.success.light,.9)),W(x.Alert,"warningStandardBg",_(ge,x.warning.light,.9)),W(x.Alert,"errorIconColor",N("palette-error-main")),W(x.Alert,"infoIconColor",N("palette-info-main")),W(x.Alert,"successIconColor",N("palette-success-main")),W(x.Alert,"warningIconColor",N("palette-warning-main")),W(x.AppBar,"defaultBg",N("palette-grey-100")),W(x.Avatar,"defaultBg",N("palette-grey-400")),W(x.Button,"inheritContainedBg",N("palette-grey-300")),W(x.Button,"inheritContainedHoverBg",N("palette-grey-A100")),W(x.Chip,"defaultBorder",N("palette-grey-400")),W(x.Chip,"defaultAvatarColor",N("palette-grey-700")),W(x.Chip,"defaultIconColor",N("palette-grey-700")),W(x.FilledInput,"bg","rgba(0, 0, 0, 0.06)"),W(x.FilledInput,"hoverBg","rgba(0, 0, 0, 0.09)"),W(x.FilledInput,"disabledBg","rgba(0, 0, 0, 0.12)"),W(x.LinearProgress,"primaryBg",_(ge,x.primary.main,.62)),W(x.LinearProgress,"secondaryBg",_(ge,x.secondary.main,.62)),W(x.LinearProgress,"errorBg",_(ge,x.error.main,.62)),W(x.LinearProgress,"infoBg",_(ge,x.info.main,.62)),W(x.LinearProgress,"successBg",_(ge,x.success.main,.62)),W(x.LinearProgress,"warningBg",_(ge,x.warning.main,.62)),W(x.Skeleton,"bg",a?_(Lt,x.text.primary,.11):`rgba(${N("palette-text-primaryChannel")} / 0.11)`),W(x.Slider,"primaryTrack",_(ge,x.primary.main,.62)),W(x.Slider,"secondaryTrack",_(ge,x.secondary.main,.62)),W(x.Slider,"errorTrack",_(ge,x.error.main,.62)),W(x.Slider,"infoTrack",_(ge,x.info.main,.62)),W(x.Slider,"successTrack",_(ge,x.success.main,.62)),W(x.Slider,"warningTrack",_(ge,x.warning.main,.62));const H=a?_(he,x.background.default,.6825):ro(x.background.default,.8);W(x.SnackbarContent,"bg",H),W(x.SnackbarContent,"color",lt(()=>a?Lo.text.primary:x.getContrastText(H))),W(x.SpeedDialAction,"fabHoverBg",ro(x.background.paper,.15)),W(x.StepConnector,"border",N("palette-grey-400")),W(x.StepContent,"border",N("palette-grey-400")),W(x.Switch,"defaultColor",N("palette-common-white")),W(x.Switch,"defaultDisabledColor",N("palette-grey-100")),W(x.Switch,"primaryDisabledColor",_(ge,x.primary.main,.62)),W(x.Switch,"secondaryDisabledColor",_(ge,x.secondary.main,.62)),W(x.Switch,"errorDisabledColor",_(ge,x.error.main,.62)),W(x.Switch,"infoDisabledColor",_(ge,x.info.main,.62)),W(x.Switch,"successDisabledColor",_(ge,x.success.main,.62)),W(x.Switch,"warningDisabledColor",_(ge,x.warning.main,.62)),W(x.TableCell,"border",_(ge,_(Lt,x.divider,1),.88)),W(x.Tooltip,"bg",_(Lt,x.grey[700],.92))}if(x.mode==="dark"){W(x.Alert,"errorColor",_(ge,x.error.light,.6)),W(x.Alert,"infoColor",_(ge,x.info.light,.6)),W(x.Alert,"successColor",_(ge,x.success.light,.6)),W(x.Alert,"warningColor",_(ge,x.warning.light,.6)),W(x.Alert,"errorFilledBg",N("palette-error-dark")),W(x.Alert,"infoFilledBg",N("palette-info-dark")),W(x.Alert,"successFilledBg",N("palette-success-dark")),W(x.Alert,"warningFilledBg",N("palette-warning-dark")),W(x.Alert,"errorFilledColor",lt(()=>x.getContrastText(x.error.dark))),W(x.Alert,"infoFilledColor",lt(()=>x.getContrastText(x.info.dark))),W(x.Alert,"successFilledColor",lt(()=>x.getContrastText(x.success.dark))),W(x.Alert,"warningFilledColor",lt(()=>x.getContrastText(x.warning.dark))),W(x.Alert,"errorStandardBg",_(he,x.error.light,.9)),W(x.Alert,"infoStandardBg",_(he,x.info.light,.9)),W(x.Alert,"successStandardBg",_(he,x.success.light,.9)),W(x.Alert,"warningStandardBg",_(he,x.warning.light,.9)),W(x.Alert,"errorIconColor",N("palette-error-main")),W(x.Alert,"infoIconColor",N("palette-info-main")),W(x.Alert,"successIconColor",N("palette-success-main")),W(x.Alert,"warningIconColor",N("palette-warning-main")),W(x.AppBar,"defaultBg",N("palette-grey-900")),W(x.AppBar,"darkBg",N("palette-background-paper")),W(x.AppBar,"darkColor",N("palette-text-primary")),W(x.Avatar,"defaultBg",N("palette-grey-600")),W(x.Button,"inheritContainedBg",N("palette-grey-800")),W(x.Button,"inheritContainedHoverBg",N("palette-grey-700")),W(x.Chip,"defaultBorder",N("palette-grey-700")),W(x.Chip,"defaultAvatarColor",N("palette-grey-300")),W(x.Chip,"defaultIconColor",N("palette-grey-300")),W(x.FilledInput,"bg","rgba(255, 255, 255, 0.09)"),W(x.FilledInput,"hoverBg","rgba(255, 255, 255, 0.13)"),W(x.FilledInput,"disabledBg","rgba(255, 255, 255, 0.12)"),W(x.LinearProgress,"primaryBg",_(he,x.primary.main,.5)),W(x.LinearProgress,"secondaryBg",_(he,x.secondary.main,.5)),W(x.LinearProgress,"errorBg",_(he,x.error.main,.5)),W(x.LinearProgress,"infoBg",_(he,x.info.main,.5)),W(x.LinearProgress,"successBg",_(he,x.success.main,.5)),W(x.LinearProgress,"warningBg",_(he,x.warning.main,.5)),W(x.Skeleton,"bg",a?_(Lt,x.text.primary,.13):`rgba(${N("palette-text-primaryChannel")} / 0.13)`),W(x.Slider,"primaryTrack",_(he,x.primary.main,.5)),W(x.Slider,"secondaryTrack",_(he,x.secondary.main,.5)),W(x.Slider,"errorTrack",_(he,x.error.main,.5)),W(x.Slider,"infoTrack",_(he,x.info.main,.5)),W(x.Slider,"successTrack",_(he,x.success.main,.5)),W(x.Slider,"warningTrack",_(he,x.warning.main,.5));const H=a?_(ge,x.background.default,.985):ro(x.background.default,.98);W(x.SnackbarContent,"bg",H),W(x.SnackbarContent,"color",lt(()=>a?Di.text.primary:x.getContrastText(H))),W(x.SpeedDialAction,"fabHoverBg",ro(x.background.paper,.15)),W(x.StepConnector,"border",N("palette-grey-600")),W(x.StepContent,"border",N("palette-grey-600")),W(x.Switch,"defaultColor",N("palette-grey-300")),W(x.Switch,"defaultDisabledColor",N("palette-grey-600")),W(x.Switch,"primaryDisabledColor",_(he,x.primary.main,.55)),W(x.Switch,"secondaryDisabledColor",_(he,x.secondary.main,.55)),W(x.Switch,"errorDisabledColor",_(he,x.error.main,.55)),W(x.Switch,"infoDisabledColor",_(he,x.info.main,.55)),W(x.Switch,"successDisabledColor",_(he,x.success.main,.55)),W(x.Switch,"warningDisabledColor",_(he,x.warning.main,.55)),W(x.TableCell,"border",_(he,_(Lt,x.divider,1),.68)),W(x.Tooltip,"bg",_(Lt,x.grey[700],.92))}vt(x.background,"default"),vt(x.background,"paper"),vt(x.common,"background"),vt(x.common,"onBackground"),vt(x,"divider"),Object.keys(x).forEach(H=>{const q=x[H];H!=="tonalOffset"&&q&&typeof q=="object"&&(q.main&&W(x[H],"mainChannel",Lr(Vr(q.main))),q.light&&W(x[H],"lightChannel",Lr(Vr(q.light))),q.dark&&W(x[H],"darkChannel",Lr(Vr(q.dark))),q.contrastText&&W(x[H],"contrastTextChannel",Lr(Vr(q.contrastText))),H==="text"&&(vt(x[H],"primary"),vt(x[H],"secondary")),H==="action"&&(q.active&&vt(x[H],"active"),q.selected&&vt(x[H],"selected")))})}),D=o.reduce((ee,x)=>He(ee,x),D);const O={prefix:c,disableCssColorScheme:s,shouldSkipGeneratingVar:l,getSelector:Xc(D),enableContrastVars:d},{vars:R,generateThemeVars:U,generateStyleSheets:J}=vc(D,O);return D.vars=R,Object.entries(D.colorSchemes[D.defaultColorScheme]).forEach(([ee,x])=>{D[ee]=x}),D.generateThemeVars=U,D.generateStyleSheets=J,D.generateSpacing=function(){return zi(f.spacing,Xo(this))},D.getColorSchemeSelector=Sc(u),D.spacing=D.generateSpacing(),D.shouldSkipGeneratingVar=l,D.unstable_sxConfig={...wo,...f==null?void 0:f.unstable_sxConfig},D.unstable_sx=function(x){return ko({sx:x,theme:this})},D.toRuntimeSource=Mi,D}function Un(t,o,n){t.colorSchemes&&n&&(t.colorSchemes[o]={...n!==!0&&n,palette:en({...n===!0?{}:n.palette,mode:o})})}function rd(t={},...o){const{palette:n,cssVariables:i=!1,colorSchemes:s=n?void 0:{light:!0},defaultColorScheme:c=n==null?void 0:n.mode,...d}=t,l=c||"light",u=s==null?void 0:s[l],m={...s,...n?{[l]:{...typeof u!="boolean"&&u,palette:n}}:void 0};if(i===!1){if(!("colorSchemes"in t))return Vo(t,...o);let f=n;"palette"in t||m[l]&&(m[l]!==!0?f=m[l].palette:l==="dark"&&(f={mode:"dark"}));const b=Vo({...t,palette:f},...o);return b.defaultColorScheme=l,b.colorSchemes=m,b.palette.mode==="light"&&(b.colorSchemes.light={...m.light!==!0&&m.light,palette:b.palette},Un(b,"dark",m.dark)),b.palette.mode==="dark"&&(b.colorSchemes.dark={...m.dark!==!0&&m.dark,palette:b.palette},Un(b,"light",m.light)),b}return!n&&!("light"in m)&&l==="light"&&(m.light=!0),td({...d,colorSchemes:m,defaultColorScheme:l,...typeof i!="boolean"&&i},...o)}const od=rd();function wt(){const t=lc(od);return process.env.NODE_ENV!=="production"&&po.useDebugValue(t),t[Xa]||t}async function nd(t,o,n){try{new URL(t)}catch{throw new Error("Please enter a valid URL")}const i={"Content-Type":"application/json"};o&&(i.Authorization=`Bearer ${o}`);const s=new AbortController,c=setTimeout(()=>s.abort(),3e4);let d;try{d=await fetch(t,{headers:i,signal:s.signal})}catch(m){throw clearTimeout(c),(m==null?void 0:m.name)==="AbortError"?new Error("Request timed out after 30 seconds"):new Error("Failed to fetch — check the URL and your network connection")}finally{clearTimeout(c)}if(d.status===401)throw new Error("Authentication failed (401) — check your API key");if(!d.ok)throw new Error(`API error ${d.status}: ${d.statusText}`);let l;try{l=await d.json()}catch{throw new Error("Response is not valid JSON")}let u;if(Array.isArray(l))u=l;else if(n&&l[n]&&Array.isArray(l[n]))u=l[n];else{const f=["data","results","items","records"].find(b=>l[b]&&Array.isArray(l[b]));if(f)u=l[f];else throw new Error("API response must be a JSON array, or specify the data path key.")}return{data:u,source:t,fetchedAt:new Date().toISOString()}}function id({isOpen:t,onClose:o,onCreate:n,preloadedData:i,preloadedDataLabel:s}){const[c,d]=p.useState(""),[l,u]=p.useState(!1),[m,f]=p.useState(""),[b,h]=p.useState(null),[g,z]=p.useState(null),[v,j]=p.useState(!1),[S,y]=p.useState(""),T=p.useRef(null),[a,k]=p.useState("json"),[D,O]=p.useState(""),[R,U]=p.useState(""),[J,ee]=p.useState(""),[x,N]=p.useState("idle"),[_,H]=p.useState(""),[q,de]=p.useState(null),[ue,re]=p.useState(0),M=async P=>{if(y(""),!P.name.endsWith(".json")){y("Only .json files are allowed");return}const te=10*1024*1024;if(P.size>te){y("File size exceeds 10MB limit");return}try{const ie=await P.text();let se;try{se=JSON.parse(ie)}catch{y("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(se)){y("JSON must be an array of objects");return}if(se.length===0){y("No data rows found in JSON file");return}h(P),z(se)}catch{y("Network error — please try again")}},L=P=>{P.preventDefault();const te=P.dataTransfer.files[0];te&&M(te)},G=async()=>{if(D.trim()){N("loading"),H("");try{const P=await nd(D.trim(),R.trim()||void 0,J.trim()||void 0);de(P.data),re(P.data.length),N("ready")}catch(P){H((P==null?void 0:P.message)||"Connection failed"),N("error")}}},oe=()=>{if(!c.trim()){u(!0);return}const P=a==="api"?q:i||g;P&&(n(c.trim(),m.trim(),P),Q())},Q=()=>{d(""),u(!1),f(""),h(null),z(null),y(""),k("json"),O(""),U(""),ee(""),N("idle"),H(""),de(null),re(0),o()},le=i||g,ne=l&&!c.trim();return c.trim(),e.jsxs(e.Fragment,{children:[e.jsxs(r.Dialog,{open:t,onClose:Q,maxWidth:"xs",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",width:480,maxHeight:"min(720px, calc(100vh - 120px))",my:"auto",display:"flex",flexDirection:"column",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2.5,fontWeight:500,fontSize:"1.125rem",color:"text.primary",letterSpacing:"-0.01em",borderBottom:"1px solid",borderColor:"divider"},children:["Create new report",e.jsx(r.IconButton,{onClick:Q,size:"small",sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:"action.hover",color:"text.primary"}},children:e.jsx(w.Close,{sx:{fontSize:18}})})]}),e.jsx(r.DialogContent,{sx:{px:3,pt:2,pb:2,overflowY:"auto"},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2,pt:2},children:[e.jsx(r.TextField,{label:"Report name",required:!0,fullWidth:!0,value:c,onChange:P=>{d(P.target.value),l&&P.target.value.trim()&&u(!1)},placeholder:"Enter report name",autoFocus:!0,error:ne,helperText:ne?"Report name is required":void 0,inputProps:{maxLength:255},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsx(r.TextField,{label:"Description (optional)",fullWidth:!0,multiline:!0,rows:2,value:m,onChange:P=>f(P.target.value),placeholder:"Add details about this report",inputProps:{maxLength:500},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsxs(r.Tabs,{value:a==="json"?0:1,onChange:(P,te)=>{k(te===0?"json":"api"),N("idle"),H("")},variant:"fullWidth",sx:{borderBottom:1,borderColor:"divider",minHeight:40},children:[e.jsx(r.Tab,{label:"Upload JSON",icon:e.jsx(w.Description,{fontSize:"small"}),iconPosition:"start",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,minHeight:40,py:.5}}),e.jsx(r.Tab,{label:"Connect API",icon:e.jsx(w.Api,{fontSize:"small"}),iconPosition:"start",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,minHeight:40,py:.5}})]}),a==="json"&&e.jsx(r.Box,{children:i?e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2.5,bgcolor:P=>E(P.palette.success.main,.04),display:"flex",alignItems:"center",gap:2},children:[e.jsx(r.Box,{sx:{width:36,height:36,borderRadius:"50%",bgcolor:P=>E(P.palette.success.main,.12),display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(w.CheckCircle,{sx:{fontSize:20,color:"success.main"}})}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.dark",fontSize:"0.875rem"},children:s||`${i.length.toLocaleString()} records loaded`}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary"},children:"Data source is connected — ready to create"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:1.25},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Data source"}),e.jsx(r.IconButton,{size:"small",onClick:()=>j(!0),sx:{p:.25,color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:e.jsx(w.Info,{sx:{fontSize:16}})})]}),e.jsxs(r.Box,{onDrop:L,onDragOver:P=>P.preventDefault(),onPaste:P=>P.preventDefault(),onClick:()=>{var P;return(P=T.current)==null?void 0:P.click()},sx:{position:"relative",border:"1.5px",borderStyle:g?"solid":"dashed",borderColor:g?"success.main":S?"error.main":"primary.main",borderRadius:2,p:3,textAlign:"center",cursor:"pointer",bgcolor:g?P=>E(P.palette.success.main,.04):S?P=>E(P.palette.error.main,.04):P=>E(P.palette.primary.main,.04),transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:g?P=>E(P.palette.success.main,.08):S?P=>E(P.palette.error.main,.08):P=>E(P.palette.primary.main,.08),borderColor:g?"success.dark":S?"error.dark":"primary.dark"}},children:[e.jsx(r.Box,{component:"input",ref:T,type:"file",accept:".json",sx:{display:"none"},onChange:P=>{var te;return((te=P.target.files)==null?void 0:te[0])&&M(P.target.files[0])}}),g?e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",gap:.75,animation:"fadeIn 0.2s ease-in","@keyframes fadeIn":{from:{opacity:0,transform:"scale(0.98)"},to:{opacity:1,transform:"scale(1)"}}},children:[e.jsx(r.Box,{sx:{width:40,height:40,borderRadius:"50%",bgcolor:P=>E(P.palette.success.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mb:.5},children:e.jsx(w.CheckCircle,{sx:{fontSize:24,color:"success.main"}})}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.main",fontSize:"0.875rem"},children:b==null?void 0:b.name}),e.jsx(r.Typography,{variant:"caption",sx:{color:"success.dark",fontSize:"0.75rem"},children:"Ready to create"})]}):e.jsxs(r.Box,{children:[e.jsx(r.Box,{sx:{width:48,height:48,borderRadius:"50%",bgcolor:P=>E(P.palette.primary.main,.1),display:"flex",alignItems:"center",justifyContent:"center",mx:"auto",mb:1.5},children:e.jsx(w.CloudUpload,{sx:{fontSize:28,color:"primary.main"}})}),e.jsx(r.Typography,{variant:"body2",sx:{color:"text.primary",fontSize:"0.875rem",fontWeight:500,mb:.25},children:"Upload JSON file"}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",display:"block"},children:"Click to browse or drag and drop"}),S&&e.jsx(r.Box,{sx:{mt:1.25,p:.75,borderRadius:1,bgcolor:P=>E(P.palette.error.main,.08),border:1,borderColor:P=>E(P.palette.error.main,.2)},children:e.jsx(r.Typography,{variant:"caption",sx:{color:"error.main",fontSize:"0.6875rem",fontWeight:500},children:S})})]})]})]})}),a==="api"&&e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2},children:[e.jsx(r.TextField,{label:"API Endpoint URL",required:!0,fullWidth:!0,size:"small",value:D,onChange:P=>{O(P.target.value),N("idle")},placeholder:"http://localhost:8000/api/reports/sales-pipeline/data/flat",sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsx(r.TextField,{label:"API Key (optional)",fullWidth:!0,size:"small",value:R,onChange:P=>U(P.target.value),placeholder:"Leave blank if no auth required",InputProps:{startAdornment:e.jsx(r.InputAdornment,{position:"start",children:e.jsx(w.Lock,{sx:{fontSize:16,color:"text.secondary"}})})},sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}}}}),e.jsx(r.TextField,{label:"Response data path (optional)",fullWidth:!0,size:"small",value:J,onChange:P=>ee(P.target.value),placeholder:"data (leave blank if API returns a plain array)",helperText:'If your API returns { "data": [...] }, enter: data',sx:{"& .MuiInputBase-root":{fontSize:"0.875rem",borderRadius:1,color:"text.primary"},"& .MuiInputLabel-root":{fontSize:"0.875rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiOutlinedInput-root":{"& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"text.secondary"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:2}},"& .MuiFormHelperText-root":{fontSize:"0.75rem",mx:0}}}),e.jsx(r.Button,{variant:"outlined",fullWidth:!0,disabled:!D.trim()||x==="loading",onClick:G,startIcon:x==="loading"?e.jsx(r.CircularProgress,{size:16,color:"inherit"}):e.jsx(w.Api,{}),sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",borderRadius:1,py:.875,borderColor:"primary.main",color:"primary.main","&:hover":{bgcolor:P=>E(P.palette.primary.main,.04),borderColor:"primary.dark"},"&:disabled":{borderColor:"action.disabledBackground",color:"action.disabled"}},children:x==="loading"?"Connecting...":"Test Connection & Load Data"}),x==="ready"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"success.main",borderRadius:2,p:2,bgcolor:P=>E(P.palette.success.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(w.CheckCircle,{sx:{fontSize:20,color:"success.main",flexShrink:0,mt:.1}}),e.jsxs(r.Box,{children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"success.dark",fontSize:"0.875rem"},children:[ue.toLocaleString()," records loaded — ready to create"]}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",wordBreak:"break-all",display:"block",mt:.25},children:D})]})]}),x==="error"&&e.jsxs(r.Box,{sx:{border:"1.5px solid",borderColor:"error.main",borderRadius:2,p:2,bgcolor:P=>E(P.palette.error.main,.04),display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsx(w.ErrorOutline,{sx:{fontSize:20,color:"error.main",flexShrink:0,mt:.1}}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,color:"error.main",fontSize:"0.875rem"},children:"Connection failed"}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.75rem",display:"block",mt:.25},children:_})]})]})]})]})}),e.jsxs(r.DialogActions,{sx:{px:3,py:2,gap:1,borderTop:"1px solid",borderColor:"divider"},children:[e.jsx(r.Button,{onClick:Q,variant:"text",sx:{textTransform:"none",color:"primary.main",fontWeight:500,fontSize:"0.875rem",borderRadius:"4px",px:2,py:.625,minWidth:64,"&:hover":{bgcolor:P=>E(P.palette.primary.main,.04)}},children:"Cancel"}),e.jsx(r.Button,{onClick:oe,disabled:a==="json"&&!le||a==="api"&&x!=="ready",variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"4px",px:2.5,py:.625,minWidth:64,"&:hover":{bgcolor:"primary.dark",boxShadow:2},"&:disabled":{bgcolor:"action.disabledBackground",color:"action.disabled"}},children:"Create"})]})]}),e.jsxs(r.Dialog,{open:v,onClose:()=>j(!1),maxWidth:"sm",PaperProps:{sx:{borderRadius:3,width:560,maxHeight:"80vh",boxShadow:8}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:2,fontWeight:500,fontSize:"1.25rem",color:"text.primary",letterSpacing:"-0.01em"},children:["JSON format guide",e.jsx(r.IconButton,{onClick:()=>j(!1),size:"small",sx:{color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{sx:{px:3,py:2},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Required format"}),e.jsx(r.Typography,{variant:"body2",sx:{color:"text.secondary",fontSize:"0.8125rem",lineHeight:1.5},children:"Your JSON file must be an array of objects. Each object represents a row, and all should have the same field names."})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Example structure"}),e.jsx(r.Box,{component:"pre",sx:{bgcolor:"action.hover",border:1,borderColor:"divider",p:2,borderRadius:1,overflow:"auto",maxHeight:200,fontSize:"0.75rem",fontFamily:"monospace",lineHeight:1.5,color:"text.primary"},children:`[
|
|
70
70
|
{
|
|
71
71
|
"id": 1,
|
|
72
72
|
"customerName": "John Smith",
|
|
@@ -76,7 +76,7 @@ To suppress this warning, you need to explicitly provide the \`palette.${o}Chann
|
|
|
76
76
|
"memberSince": "2024-01-15",
|
|
77
77
|
"status": "active"
|
|
78
78
|
}
|
|
79
|
-
]`})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Supported data types"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"Text, numbers, booleans, dates, and null values"})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Guidelines"}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• Must be valid JSON with array format"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• All objects should have consistent field names"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:'• Field names auto-format (e.g., "customerName" → "Customer Name")'})]})]})]})}),e.jsx(r.DialogActions,{sx:{px:3,py:2},children:e.jsx(r.Button,{onClick:()=>j(!1),variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"4px",px:2.5,py:.625,minWidth:64,"&:hover":{bgcolor:"primary.dark",boxShadow:2}},children:"Got it"})})]})]})}function
|
|
79
|
+
]`})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Supported data types"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"Text, numbers, booleans, dates, and null values"})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",sx:{fontWeight:500,mb:.75,color:"text.primary",fontSize:"0.875rem"},children:"Guidelines"}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• Must be valid JSON with array format"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:"• All objects should have consistent field names"}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.secondary"},children:'• Field names auto-format (e.g., "customerName" → "Customer Name")'})]})]})]})}),e.jsx(r.DialogActions,{sx:{px:3,py:2},children:e.jsx(r.Button,{onClick:()=>j(!1),variant:"contained",disableElevation:!0,sx:{textTransform:"none",fontWeight:500,fontSize:"0.875rem",bgcolor:"primary.main",color:"primary.contrastText",borderRadius:"4px",px:2.5,py:.625,minWidth:64,"&:hover":{bgcolor:"primary.dark",boxShadow:2}},children:"Got it"})})]})]})}function Ri({isOpen:t,onClose:o}){return t?e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"md",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(640px, calc(100vh - 180px))",my:"auto",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)",display:"flex",flexDirection:"column"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:["JSON Format Guide",e.jsx(r.IconButton,{onClick:o,size:"small",sx:{color:"text.secondary"},children:e.jsx(w.Close,{sx:{fontSize:20}})})]}),e.jsx(r.DialogContent,{dividers:!0,sx:{overflowY:"auto",flex:1},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:3,py:1},children:[e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Expected JSON Structure"}),e.jsxs(r.Typography,{variant:"body2",color:"text.secondary",children:["The uploaded JSON must be an ",e.jsx("strong",{children:"array of objects"}),". Each object represents a single row in your report, and the keys of each object become the column names."]})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Example JSON"}),e.jsx(r.Paper,{elevation:0,sx:{p:2,bgcolor:"action.hover",border:1,borderColor:"divider",borderRadius:1,overflowX:"auto"},children:e.jsx(r.Box,{component:"pre",sx:{fontSize:"caption.fontSize",fontFamily:"monospace",m:0},children:`[
|
|
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 zc({onFileUpload:t,onError:o,isUploading:n}){const[i,a]=p.useState(!1),[l,c]=p.useState(""),[d,u]=p.useState(!1),f=p.useRef(null),h=async b=>{if(!b.name.endsWith(".json")){o("Only .json files are allowed");return}const g=10*1024*1024;if(b.size>g){o("File size exceeds 10MB limit");return}c(b.name);try{const S=await b.text();let s;try{s=JSON.parse(S)}catch{o("Invalid JSON syntax — please check your file and try again");return}if(!Array.isArray(s)){o("JSON must be an array of objects");return}if(s.length===0){o("No data rows found in JSON file");return}t(s)}catch{o("Network error — please try again")}finally{c("")}},m=b=>{b.preventDefault(),a(!0)},v=b=>{b.preventDefault(),a(!1)},w=b=>{b.preventDefault(),a(!1);const g=b.dataTransfer.files[0];g&&h(g)},z=()=>{var b;(b=f.current)==null||b.click()},y=b=>{var S;const g=(S=b.target.files)==null?void 0:S[0];g&&h(g)},j=b=>{b.stopPropagation(),u(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{onDragOver:m,onDragLeave:v,onDrop:w,onPaste:b=>b.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?b=>R(b.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:f,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..."}),l&&e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:l})]}):e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{width:64,height:64,borderRadius:"50%",bgcolor:b=>R(b.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:j,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(bi,{isOpen:d,onClose:()=>u(!1)})]})}function Ic({schema:t,onConfirm:o,hasConflicts:n}){return e.jsxs(r.Paper,{sx:{border:2,borderColor:"divider",p:3},children:[e.jsxs(r.Box,{sx:{mb:2},children:[e.jsx(r.Typography,{variant:"h6",sx:{fontWeight:600,mb:.5},children:"Schema Preview"}),e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"Review the detected schema before generating your table"})]}),n&&e.jsxs(r.Alert,{severity:"warning",sx:{mb:2},children:[e.jsx(r.AlertTitle,{sx:{fontWeight:600},children:"Schema Conflict Detected"}),"Some columns have inconsistent data types across rows. Please resolve these conflicts before proceeding."]}),e.jsx(r.TableContainer,{sx:{mb:3},children:e.jsxs(r.Table,{children:[e.jsx(r.TableHead,{children:e.jsxs(r.TableRow,{sx:{bgcolor:"action.hover"},children:[e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Column Name"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Detected Type"}),e.jsx(r.TableCell,{sx:{fontWeight:600,textTransform:"uppercase",fontSize:"caption.fontSize"},children:"Status"})]})}),e.jsx(r.TableBody,{children:t.map(i=>e.jsxs(r.TableRow,{sx:{bgcolor:i.hasConflict?a=>R(a.palette.warning.main,.12):"transparent"},children:[e.jsxs(r.TableCell,{sx:{fontWeight:500},children:[i.name,i.hasConflict&&e.jsx(r.Box,{component:"span",sx:{ml:1,color:"warning.main"},children:"⚠"})]}),e.jsx(r.TableCell,{children:e.jsx(r.Chip,{label:i.type,size:"small",sx:{bgcolor:"action.hover"}})}),e.jsx(r.TableCell,{children:e.jsx(r.Chip,{label:i.required?"Required":"Optional",size:"small",color:i.required?"success":"default"})})]},i.name))})]})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pt:2,borderTop:1,borderColor:"divider"},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(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 Ec({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=>R(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=>R(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=>R(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 Dc({value:t,onChange:o,searchHistory:n,onAddToHistory:i,onToggleFavourite:a,onDeleteHistory:l,disabled:c}){const[d,u]=p.useState(!1),[f,h]=p.useState(!1),[m,v]=p.useState(-1),w=p.useRef(null),z=p.useRef(null);p.useEffect(()=>{function N(K){w.current&&!w.current.contains(K.target)&&(u(!1),h(!1))}return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[]);const y=p.useCallback(()=>{h(!0),v(-1),n.length>0&&u(!0)},[n.length]),j=p.useCallback(N=>{o(N),v(-1)},[o]),b=p.useCallback(N=>{var K;o(N),i(N),u(!1),(K=z.current)==null||K.blur()},[o,i]),g=p.useCallback(N=>{v(-1),b(N)},[b]),S=p.useCallback(N=>{var K;N.key==="Enter"?m>=0&&m<n.length?(N.preventDefault(),g(n[m].query)):t.trim()&&b(t.trim()):N.key==="Escape"?(u(!1),v(-1),(K=z.current)==null||K.blur()):N.key==="ArrowDown"?(N.preventDefault(),n.length>0&&(d||u(!0),v(te=>te<n.length-1?te+1:te))):N.key==="ArrowUp"&&(N.preventDefault(),v(te=>te>0?te-1:-1))},[m,n,t,d,g,b]),s=p.useCallback(()=>{var N;o(""),(N=z.current)==null||N.focus()},[o]),I=p.useMemo(()=>n.filter(N=>N.isFavourite),[n]),A=p.useMemo(()=>n.filter(N=>!N.isFavourite),[n]),H=d&&n.length>0;return e.jsxs(r.Box,{sx:{position:"relative",width:240},ref:w,children:[e.jsx(r.TextField,{inputRef:z,size:"small",fullWidth:!0,value:t,onChange:N=>j(N.target.value),onFocus:y,onKeyDown:S,placeholder:"Search data...",disabled:c,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(k.Search,{sx:{fontSize:18,color:"text.secondary"}})}),endAdornment:t?e.jsx(r.InputAdornment,{position:"end",children:e.jsx(r.IconButton,{size:"small",onClick:s,edge:"end",sx:{mr:-.5},children:e.jsx(k.Close,{sx:{fontSize:16}})})}):null}}),H&&e.jsxs(r.Paper,{sx:{position:"absolute",zIndex:50,mt:.5,width:"100%",maxHeight:384,overflowY:"auto"},elevation:3,children:[I.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"}),I.map((N,K)=>e.jsx(Wn,{entry:N,isSelected:m===K,onClick:()=>g(N.query),onToggleFavourite:()=>a(N.query),onDelete:()=>l(N.query)},`fav-${N.query}`))]}),A.length>0&&e.jsxs(r.Box,{sx:{py:1},children:[I.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((N,K)=>{const te=I.length+K;return e.jsx(Wn,{entry:N,isSelected:m===te,onClick:()=>g(N.query),onToggleFavourite:()=>a(N.query),onDelete:()=>l(N.query)},`recent-${N.query}`)})]})]})]})}const Wn=p.memo(function({entry:o,isSelected:n,onClick:i,onToggleFavourite:a,onDelete:l}){const c=p.useCallback(u=>{u.stopPropagation(),a()},[a]),d=p.useCallback(u=>{u.stopPropagation(),l()},[l]);return e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:1.5,py:1,cursor:"pointer",bgcolor:n?u=>R(u.palette.primary.main,.12):"transparent","&:hover":{bgcolor:n?u=>R(u.palette.primary.main,.12):"action.hover"}},children:[e.jsx(r.Box,{sx:{flex:1,minWidth:0},onClick:i,children:e.jsx(r.Typography,{variant:"body2",noWrap:!0,children:o.query})}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,ml:1},children:[e.jsx(r.IconButton,{size:"small",onClick:c,title:o.isFavourite?"Remove from favourites":"Add to favourites",sx:{p:.5},children:o.isFavourite?e.jsx(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:d,title:"Delete from history",sx:{p:.5,"&:hover":{color:"error.main"}},children:e.jsx(k.Delete,{sx:{fontSize:14,opacity:.5}})})]})]})});function Bc({views:t,activeViewId:o,isDirty:n,onSelectView:i,onCreateView:a,onManageViews:l,onToggleDefault:c,onToggleFavorite:d,onRestoreView:u,onPermanentDelete:f,isReadOnly:h}){const m=wc(),[v,w]=p.useState(!1),[z,y]=p.useState(!1),[j,b]=p.useState({top:0,left:0}),[g,S]=p.useState(null),s=p.useRef(null),I=p.useRef(null),A=t.find(_=>_.id===o),H=A==null?void 0:A.isDefault,N=t.filter(_=>_.isDefault&&!_.isDeleted),K=t.filter(_=>!_.isDefault&&!_.isDeleted).sort((_,O)=>(O.updatedAt||0)-(_.updatedAt||0)),te=t.filter(_=>_.isFavorite&&!_.isDeleted).sort((_,O)=>(O.updatedAt||0)-(_.updatedAt||0)),se=t.filter(_=>_.isDeleted);p.useEffect(()=>{if(v&&I.current){const _=I.current.getBoundingClientRect();b({top:_.bottom+window.scrollY+8,left:_.right+window.scrollX-320})}},[v]),p.useEffect(()=>{const _=O=>{s.current&&!s.current.contains(O.target)&&I.current&&!I.current.contains(O.target)&&w(!1)};return v&&document.addEventListener("mousedown",_),()=>{document.removeEventListener("mousedown",_)}},[v]);const x=_=>{if(n&&_!==o){S(_),w(!1);return}i(_),w(!1)},V=()=>{g&&(i(g),S(null))},$=()=>{S(null)},J=(_,O=!1)=>e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:o===_.id?m.palette.primary.light+"20":"transparent",transition:"background-color 0.2s","&:hover":{backgroundColor:o===_.id?m.palette.primary.light+"20":m.palette.grey[50]}},children:[e.jsxs(r.Button,{onClick:()=>x(_.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===_.id&&e.jsx(k.Check,{sx:{fontSize:16,flexShrink:0}}),o!==_.id&&e.jsx(r.Box,{sx:{width:"16px",flexShrink:0}}),e.jsx(r.Typography,{sx:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:o===_.id?m.palette.primary.dark:m.palette.text.primary,fontWeight:o===_.id?500:400},children:_.name}),O&&e.jsx(r.Typography,{component:"span",sx:{fontSize:"caption.fontSize",color:m.palette.text.secondary,backgroundColor:m.palette.grey[100],px:1,py:.25,borderRadius:1,flexShrink:0},children:"Default"})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[d&&e.jsx(r.IconButton,{onClick:L=>{L.stopPropagation(),d(_.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[200]}},title:_.isFavorite?"Remove from favorites":"Add to favorites",children:e.jsx(k.Star,{sx:{fontSize:16}})}),c&&!_.isDefault&&e.jsx(r.IconButton,{onClick:L=>{L.stopPropagation(),c(_.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[200]}},title:"Set as default",children:e.jsx(k.RadioButtonUnchecked,{sx:{fontSize:16}})})]})]},_.id),oe=_=>e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:2,py:1,fontSize:"body2.fontSize",backgroundColor:m.palette.grey[50]},children:[e.jsx(r.Typography,{sx:{color:m.palette.text.secondary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:_.name}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[u&&e.jsx(r.IconButton,{onClick:O=>{O.stopPropagation(),u(_.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[200]}},title:"Restore view",children:e.jsx(k.Undo,{sx:{fontSize:16,color:"success.main"}})}),f&&e.jsx(r.IconButton,{onClick:O=>{O.stopPropagation(),f(_.id)},size:"small",sx:{p:.5,transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[200]}},title:"Delete permanently",children:e.jsx(k.Delete,{sx:{fontSize:16,color:"error.main"}})})]})]},_.id),ue=n||!H,pe=n;return e.jsxs(r.Box,{sx:{position:"relative"},children:[e.jsxs(r.IconButton,{ref:I,onClick:()=>w(!v),size:"small",sx:{position:"relative",color:ue?"warning.main":"text.secondary",bgcolor:ue?R(m.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:ue?R(m.palette.warning.main,.2):R(m.palette.text.primary,.06),color:ue?"warning.dark":"text.primary"}},title:`View: ${(A==null?void 0:A.name)||"Default View"}`,children:[e.jsx(k.Visibility,{sx:{fontSize:20}}),pe&&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"}})]}),v&&Fn.createPortal(e.jsxs(r.Box,{ref:s,sx:{position:"fixed",width:"320px",backgroundColor:m.palette.background.paper,border:`1px solid ${m.palette.divider}`,borderRadius:1,boxShadow:m.shadows[8],zIndex:50,maxHeight:"500px",overflowY:"auto",top:j.top,left:j.left},children:[N.length>0&&e.jsxs(r.Box,{sx:{py:.5},children:[e.jsx(r.Typography,{sx:{px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Default Views"}),N.map(_=>J(_,!0))]}),te.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${m.palette.divider}`}}),e.jsxs(r.Box,{sx:{py:.5},children:[e.jsxs(r.Box,{sx:{px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",gap:.5},children:[e.jsx(k.Star,{sx:{fontSize:12,color:"warning.light"}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:"Favorite Views"})]}),te.map(_=>J(_))]})]}),K.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${m.palette.divider}`}}),e.jsxs(r.Box,{sx:{py:.5},children:[e.jsx(r.Typography,{sx:{px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Custom Views"}),K.map(_=>J(_))]})]}),se.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(r.Box,{sx:{borderTop:`1px solid ${m.palette.divider}`}}),e.jsxs(r.Box,{sx:{py:.5},children:[e.jsxs(r.Button,{onClick:()=>y(!z),sx:{width:"100%",px:2,py:1,fontSize:"caption.fontSize",fontWeight:600,color:m.palette.text.secondary,textTransform:"uppercase",letterSpacing:"0.05em",display:"flex",alignItems:"center",justifyContent:"space-between",transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[50]}},children:[e.jsxs(r.Typography,{component:"span",sx:{fontSize:"inherit",fontWeight:"inherit"},children:["Recently Deleted (",se.length,")"]}),e.jsx(k.ChevronRight,{sx:{fontSize:16}})]}),z&&e.jsx(r.Box,{sx:{backgroundColor:m.palette.grey[50]},children:se.map(_=>oe(_))})]})]}),e.jsx(r.Box,{sx:{borderTop:`1px solid ${m.palette.divider}`}}),e.jsxs(r.Button,{onClick:()=>{a(),w(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:m.palette.text.primary,textTransform:"none",justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[50]}},children:[e.jsx(k.Add,{sx:{fontSize:16}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit"},children:"Create New Report View"})]}),e.jsxs(r.Button,{onClick:()=>{l(),w(!1)},sx:{width:"100%",display:"flex",alignItems:"center",gap:1,px:2,py:1,fontSize:"body2.fontSize",color:m.palette.text.primary,textTransform:"none",justifyContent:"flex-start",transition:"background-color 0.2s","&:hover":{backgroundColor:m.palette.grey[50]}},children:[e.jsx(k.Settings,{sx:{fontSize:16}}),e.jsx(r.Typography,{component:"span",sx:{fontSize:"inherit"},children:"View Setup"})]})]}),document.body),e.jsxs(r.Dialog,{open:g!==null,onClose:$,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:$,variant:"text",sx:{textTransform:"none",fontWeight:500},children:"Stay here"}),e.jsx(r.Button,{onClick:V,variant:"contained",color:"warning",disableElevation:!0,sx:{textTransform:"none",fontWeight:500},children:"Discard & switch"})]})]})]})}function Oc({columnName:t,columnType:o="string",currentSort:n,hasFilters:i,isInSortStack:a,position:l,onSort:c,onRemoveSort:d,onSortAscending:u,onSortDescending:f,onFilter:h,onClearFilter:m,onHideColumn:v,onManageColumns:w,onManageViews:z,onResetLayout:y,onClose:j}){const b=p.useRef(null);p.useEffect(()=>{const S=I=>{b.current&&!b.current.contains(I.target)&&j()},s=I=>{I.key==="Escape"&&j()};return document.addEventListener("mousedown",S),document.addEventListener("keydown",s),()=>{document.removeEventListener("mousedown",S),document.removeEventListener("keydown",s)}},[j]);const g=()=>n?n.direction==="asc"?o==="number"?"(0→9)":o==="boolean"?"(False→True)":"(A→Z)":o==="number"?"(9→0)":o==="boolean"?"(True→False)":"(Z→A)":"";return Fn.createPortal(e.jsxs(r.Paper,{ref:b,sx:{position:"fixed",left:`${l.x}px`,top:`${l.y}px`,zIndex:100,minWidth:240},elevation:3,children:[e.jsxs(r.Box,{sx:{px:2,py:1},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500},children:"Sorting"}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx(r.IconButton,{size:"small",onClick:()=>{u?u(t):(n==null?void 0:n.direction)!=="asc"&&(c(t),(n==null?void 0:n.direction)==="desc"&&setTimeout(()=>c(t),0))},title:"Sort Ascending",sx:{p:.75},children:e.jsx(k.ArrowUpward,{color:(n==null?void 0:n.direction)==="asc"?"primary":void 0,sx:{fontSize:16}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>{f?f(t):n?n.direction==="asc"&&c(t):(c(t),setTimeout(()=>c(t),0))},title:"Sort Descending",sx:{p:.75},children:e.jsx(k.ArrowDownward,{color:(n==null?void 0:n.direction)==="desc"?"primary":void 0,sx:{fontSize:16}})}),e.jsx(r.IconButton,{size:"small",onClick:()=>d(t),title:"Clear sorting",disabled:!n,sx:{p:.75,"&:hover":{color:"error.main"}},children:e.jsx(k.Close,{sx:{fontSize:16}})})]})]}),n&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,mt:.5},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:g()}),e.jsx(r.Chip,{label:`Level ${n.priority}`,size:"small",color:"primary",sx:{height:20,fontSize:"caption.fontSize"}})]})]}),e.jsx(r.Divider,{}),e.jsxs(r.MenuList,{dense:!0,children:[e.jsxs(r.MenuItem,{onClick:()=>{h(t),j()},children:[e.jsx(k.FilterList,{sx:{fontSize:16,mr:1}}),"Filter this column",i&&e.jsx(r.Chip,{label:"Active",size:"small",color:"primary",sx:{ml:"auto",height:20,fontSize:"caption.fontSize"}})]}),i&&e.jsxs(r.MenuItem,{onClick:()=>{m(t),j()},sx:{color:"warning.main"},children:[e.jsx(k.FilterListOff,{sx:{fontSize:16,mr:1}}),"Clear Filters"]})]}),e.jsx(r.Divider,{}),e.jsx(r.MenuList,{dense:!0,children:e.jsxs(r.MenuItem,{onClick:()=>{v(t),j()},children:[e.jsx(k.VisibilityOff,{sx:{fontSize:16,mr:1}}),"Hide column"]})}),e.jsx(r.Divider,{}),e.jsxs(r.MenuList,{dense:!0,children:[e.jsxs(r.MenuItem,{onClick:()=>{w(),j()},children:[e.jsx(k.Settings,{sx:{fontSize:16,mr:1}}),"Column Settings"]}),e.jsxs(r.MenuItem,{onClick:()=>{z(),j()},children:[e.jsx(k.Description,{sx:{fontSize:16,mr:1}}),"View Setup"]}),e.jsxs(r.MenuItem,{onClick:()=>{y(),j()},children:[e.jsx(k.Undo,{sx:{fontSize:16,mr:1}}),"Reset to Default Layout"]})]})]}),document.body)}const Ac=150,Rn="COLUMN_HEADER",Mc=p.memo(function({column:o,index:n,sortRule:i,hasFilters:a,isInSortStack:l,width:c,onColumnClick:d,onMoveColumn:u,onResizeStart:f,onSort:h,onRemoveSort:m,onSortAscending:v,onSortDescending:w,onOpenFilterForColumn:z,onClearFiltersForColumn:y,onHideColumn:j,onManageColumns:b,onManageViews:g,onResetLayout:S}){const s=p.useRef(null),[I,A]=p.useState(!1),[H,N]=p.useState({x:0,y:0}),[{handlerId:K,isOver:te},se]=St.useDrop({accept:Rn,collect(O){return{handlerId:O.getHandlerId(),isOver:O.isOver()}},hover(O,L){var ee;if(!s.current)return;const re=O.index,Q=n;if(re===Q)return;const X=(ee=s.current)==null?void 0:ee.getBoundingClientRect(),ae=(X.right-X.left)/2,Z=L.getClientOffset(),W=((Z==null?void 0:Z.x)??0)-X.left;re<Q&&W<ae||re>Q&&W>ae||(u(re,Q),O.index=Q)}}),[{isDragging:x},V]=St.useDrag({type:Rn,item:()=>({index:n,columnName:o.name}),collect:O=>({isDragging:O.isDragging()})});V(se(s));const $=p.useCallback(O=>{O.preventDefault(),O.stopPropagation(),N({x:O.clientX,y:O.clientY}),A(!0)},[]),J=p.useCallback(()=>{A(!1)},[]),oe=p.useCallback(()=>{d(o.name)},[d,o.name]),ue=p.useCallback(O=>{O.stopPropagation(),z(o.name)},[z,o.name]),pe=p.useCallback(()=>i?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25,color:"primary.main"},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:"#fff",fontSize:"0.6rem",fontWeight:700,borderRadius:"50%",lineHeight:1},children:i.priority})]}):null,[i]),_=p.useCallback(()=>a?e.jsx(r.Box,{onClick:ue,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,[a,ue]);return e.jsxs(e.Fragment,{children:[e.jsxs(r.TableCell,{ref:s,"data-handler-id":K,"data-column-index":n,onClick:oe,onContextMenu:$,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:x?.25:1,transition:"background-color 0.12s ease, opacity 0.15s ease",bgcolor:te?O=>R(O.palette.primary.main,.08):"#f5f5f5",backgroundImage:"none",borderBottom:"1px solid",borderColor:"#e0e0e0",py:0,px:2,height:34,"&:hover":{bgcolor:"#e8e8e8",color:"primary.dark"},width:c?`${c}px`:`${Ac}px`},children:[e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center"},children:[ct(o.name),pe(),_()]}),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:O=>{O.stopPropagation(),f(O,o.name)},onClick:O=>O.stopPropagation()}),te&&e.jsx(r.Box,{sx:{position:"absolute",left:0,top:0,bottom:0,width:4,bgcolor:"primary.main"}})]}),I&&e.jsx(Oc,{columnName:o.name,columnType:o.type,currentSort:i,hasFilters:a,isInSortStack:l,position:H,onSort:h,onRemoveSort:m,onSortAscending:v,onSortDescending:w,onFilter:z,onClearFilter:y,onHideColumn:j,onManageColumns:b,onManageViews:g,onResetLayout:S,onClose:J})]})});function Wc({selectedCount:t,selectedRowIds:o,resolvedFavoritesSet:n,viewMode:i="list",onExportSelected:a,onClearSelection:l,onBulkSetFavorites:c}){const[d,u]=p.useState(null),f=p.useMemo(()=>Array.from(o),[o]),h=p.useMemo(()=>f.filter(b=>n.has(b)),[f,n]),m=p.useMemo(()=>f.filter(b=>!n.has(b)),[f,n]),v=h.length>0,w=m.length>0;if(t===0)return null;const z=()=>{c&&c(f,!0)},y=()=>{c&&c(f,!1)},j=b=>{a(b),u(null)};return e.jsx(r.Box,{sx:{width:"100%",flexShrink:0,bgcolor:b=>R(b.palette.primary.main,.08),borderBottom:b=>`1px solid ${R(b.palette.primary.main,.25)}`,zIndex:10},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:1.25},children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"primary.main"},children:[t," ",i==="grid"?t===1?"card":"cards":t===1?"row":"rows"," selected"]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.Button,{onClick:l,startIcon:e.jsx(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:b=>R(b.palette.text.primary,.06),color:"text.primary"}},children:"Clear"}),e.jsx(r.Button,{onClick:b=>u(b.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:b=>R(b.palette.primary.main,.4),color:"primary.main","&:hover":{borderColor:"primary.main",bgcolor:b=>R(b.palette.primary.main,.06)}},children:"Export Selected"}),e.jsxs(r.Menu,{anchorEl:d,open:!!d,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"})]}),c&&w&&e.jsx(r.Button,{onClick:z,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:b=>R(b.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:b=>R(b.palette.warning.main,.06)}},children:"Add to Favorites"}),c&&v&&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:b=>R(b.palette.warning.main,.5),color:"warning.dark","&:hover":{borderColor:"warning.main",bgcolor:b=>R(b.palette.warning.main,.06)}},children:"Remove from Favorites"})]})]})})}const Rc={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"}},_c={low:"text.secondary",medium:"#e65100",high:"#e8710a",critical:"#c5221f",urgent:"#c5221f"};function Pc(t){const o=t.toLowerCase().trim(),n=Rc[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 $c(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 Pc(n);if(/\b(priority|severity|urgency)\b/.test(i)){const a=_c[n.toLowerCase().trim()];return a?e.jsx(r.Box,{component:"span",sx:{color:a,fontWeight:600,fontSize:"0.8125rem"},children:n}):e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:n})}return typeof o=="boolean"?e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:o?"Yes":"No"}):typeof o=="object"?e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:JSON.stringify(o)}):e.jsx(r.Box,{component:"span",sx:{fontSize:"0.8125rem"},children:n})}function Nc(t){const o=t.find(a=>{const l=a.name.toLowerCase();return/\b(name|title|label|subject|task_?name|taskname)\b/.test(l)})||t[0]||null,n=t.find(a=>{const l=a.name.toLowerCase().replace(/[\s_-]/g,"");return/(^id$|id$|_id$|taskid|code$|ref$)/.test(l)&&a!==o})||null,i=t.filter(a=>a!==o&&a!==n).slice(0,4);return{primaryCol:o,idCol:n,bodyColumns:i}}function Fc({row:t,rowIndex:o,visibleColumns:n,isSelected:i,isFavorite:a,isReadOnly:l,onToggleSelection:c,onToggleFavorite:d,onView:u,onEdit:f,onDuplicate:h,onDelete:m}){const[v,w]=p.useState(null),[z,y]=p.useState(!1),{primaryCol:j,idCol:b,bodyColumns:g}=p.useMemo(()=>Nc(n),[n]),S=j?t[j.name]:null,s=b?t[b.name]:null,I=z||i||a||!!v;return e.jsxs(r.Box,{onMouseEnter:()=>y(!0),onMouseLeave:()=>y(!1),onClick:()=>c(o),sx:{position:"relative",display:"flex",flexDirection:"column",bgcolor:"background.paper",border:"1px solid",borderColor:i?"primary.main":A=>R(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 ${R(A.palette.primary.main,.15)}, 0 2px 8px ${R(A.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:A=>R(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:[g.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:ct(A.name)}),e.jsx(r.Box,{sx:{flex:1,lineHeight:1},children:$c(A,t[A.name])})]},A.name)),g.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=>R(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:s?.85:0,userSelect:"none"},children:s?String(s):" "}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.25,opacity:I?1:0,transition:"opacity 0.15s ease"},onClick:A=>A.stopPropagation(),children:[d&&e.jsx(r.Tooltip,{title:a?"Remove from favorites":"Add to favorites",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:A=>{A.stopPropagation(),d(t)},sx:{width:28,height:28,color:a?"#fbbc04":"action.disabled","&:hover":{bgcolor:A=>R(A.palette.warning.main,.1),color:"#fbbc04"}},children:a?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(),w(A.currentTarget)},sx:{width:28,height:28,color:"action.active","&:hover":{bgcolor:A=>R(A.palette.text.primary,.08)}},children:e.jsx(k.MoreVert,{sx:{fontSize:17}})})})]})]}),e.jsxs(r.Popover,{open:!!v,anchorEl:v,onClose:()=>w(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),w(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"})]}),!l&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{f(t,o),w(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"})]}),!l&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{h(o,t),w(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"})]}),!l&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{sx:{my:.5,mx:.5}}),e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{m(o,t),w(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 Lc({row:t,grouping:o,onToggleCollapse:n}){var i;return e.jsxs(r.Box,{onClick:()=>n(t.groupKey),sx:{gridColumn:"1 / -1",display:"flex",alignItems:"center",gap:1,px:2,py:1,mt:1,mb:.5,bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:"8px",cursor:"pointer",boxShadow:"0 1px 2px rgba(60,64,67,0.06)","&:hover":{bgcolor:a=>R(a.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:Yn(t.groupLevel,((i=o==null?void 0:o.levels[t.groupLevel])==null?void 0:i.column)||"",t.groupValue)}),e.jsxs(r.Box,{sx:{px:1,py:.125,fontSize:"0.6875rem",fontWeight:600,bgcolor:a=>R(a.palette.primary.main,.1),color:"primary.main",borderRadius:"10px"},children:[t.rowCount," ",t.rowCount===1?"row":"rows"]}),Object.keys(t.aggregates).length>0&&e.jsx(r.Typography,{variant:"caption",sx:{ml:.5,color:"text.secondary"},children:Object.entries(t.aggregates).map(([a,l])=>Gn(l)).filter(Boolean).join(" • ")})]})}function Vc({data:t,visibleColumns:o,grouping:n,selectedRowIds:i,resolvedFavoritesSet:a,isReadOnly:l,isGrouped:c,sortStack:d=[],onSort:u,onToggleRowSelection:f,onToggleRowFavorite:h,onToggleGroupCollapse:m,onViewRow:v,onEditRow:w,onDuplicateRow:z,onDeleteRow:y}){const j=p.useMemo(()=>{const b=new Set;return i.forEach(g=>{const S=g==null?void 0:g.__urm_row_id__;S!==void 0&&b.add(S)}),b},[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(b=>{const g=d.find(S=>S.column===b.name);return e.jsxs(r.Box,{onClick:()=>u(b.name),sx:{display:"inline-flex",alignItems:"center",gap:.5,px:1.25,py:.375,borderRadius:"6px",border:"1px solid",borderColor:g?"primary.main":"divider",bgcolor:g?S=>R(S.palette.primary.main,.07):"transparent",cursor:"pointer",transition:"all 0.15s ease","&:hover":{borderColor:"primary.light",bgcolor:S=>R(S.palette.primary.main,.05)}},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",fontWeight:g?600:400,color:g?"primary.main":"text.secondary",whiteSpace:"nowrap"},children:ct(b.name)}),g?g.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"}})]},b.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((b,g)=>c&&b.isGroupHeader?e.jsx(Lc,{row:b,grouping:n,onToggleCollapse:m||(()=>{})},`group-${b.groupKey}`):e.jsx(Fc,{row:b,rowIndex:g,visibleColumns:o,isSelected:j.has(b==null?void 0:b.__urm_row_id__),isFavorite:a.has(b),isReadOnly:l,onToggleSelection:()=>f(b),onToggleFavorite:h,onView:v,onEdit:w,onDuplicate:z,onDelete:y},`card-${g}`))})]})}const _n=[10,15,25,50,100];function Hc({currentPage:t,pageSize:o,totalRows:n,totalFields:i,onPageChange:a,onPageSizeChange:l}){const c=Math.ceil(n/o);if(n<=Math.min(..._n))return null;const d=()=>{t>1&&a(t-1)},u=()=>{t<c&&a(t+1)},f=(t-1)*o+1,h=Math.min(t*o,n);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:m=>l(Number(m.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:_n.map(m=>e.jsx(r.MenuItem,{value:m,sx:{fontSize:"0.8125rem"},children:m},m))})]}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400,userSelect:"none",WebkitUserSelect:"none"},children:[f,"–",h," of ",n]}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",fontWeight:400,userSelect:"none",WebkitUserSelect:"none"},children:["Page ",t," of ",c]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx(r.IconButton,{onClick:d,disabled:t===1,size:"small",title:"Previous page",sx:{p:.75,color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"action.disabled"}},children:e.jsx(k.ChevronLeft,{sx:{fontSize:20}})}),e.jsx(r.IconButton,{onClick:u,disabled:t===c,size:"small",title:"Next page",sx:{p:.75,color:"text.secondary","&:hover":{bgcolor:"action.hover"},"&.Mui-disabled":{color:"action.disabled"}},children:e.jsx(k.ChevronRight,{sx:{fontSize:20}})})]})]})]})}function Uc(){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 Si="urm_hint_seen_";function Gc(t){try{return localStorage.getItem(Si+t)==="true"}catch{return!1}}function Yc(t){try{localStorage.setItem(Si+t,"true")}catch{}}function qc(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 Jc({open:t,onClose:o,row:n,schema:i,reportName:a}){if(!n)return null;const l=i.filter(c=>c.name in n);return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(680px, calc(100vh - 180px))",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)"}},children:[e.jsxs(r.Box,{sx:{px:2,py:1.5,bgcolor:"#fff",borderBottom:"1px solid divider",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(r.Stack,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(k.Visibility,{sx:{fontSize:18,color:"primary.main"}}),e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"0.9375rem",fontWeight:500,color:"text.primary"},children:"View Record"})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{p:.5,color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:e.jsx(k.Close,{sx:{fontSize:18}})})]}),e.jsx(r.DialogContent,{sx:{p:0,bgcolor:"grey.50",overflowY:"auto",flex:1},children:e.jsx(r.Box,{children:l.map(c=>{const d=n[c.name],u=qc(d,c.type),f=u==="—";return e.jsxs(r.Box,{sx:{px:2,py:1.25,borderBottom:"1px solid divider",bgcolor:"#fff",transition:"background-color 0.15s ease","&:hover":{bgcolor:"grey.50"},"&:last-child":{borderBottom:"none"}},children:[e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",fontSize:"0.6875rem",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.02em",display:"block",mb:.5},children:ct(c.name)}),e.jsx(r.Typography,{variant:"body2",sx:{color:f?"#9e9e9e":"text.primary",fontStyle:f?"italic":"normal",fontSize:"0.875rem",wordBreak:"break-word",whiteSpace:c.type==="object"||c.type==="array"?"pre-wrap":"normal",fontFamily:c.type==="number"?"monospace":"inherit",fontWeight:400,lineHeight:1.5},children:u})]},c.name)})})}),e.jsx(r.DialogActions,{sx:{px:2,py:1.25,borderTop:"1px solid divider",bgcolor:"#fff",gap:1,justifyContent:"flex-end"},children:e.jsx(r.Button,{onClick:o,variant:"contained",sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,bgcolor:"primary.main",color:"#fff",px:2.5,py:.625,minHeight:32,borderRadius:"4px",boxShadow:"none","&:hover":{bgcolor:"primary.dark",boxShadow:"none"}},children:"Close"})})]})}function Kc({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 Xc({open:t,onClose:o,onSave:n,row:i,schema:a,reportName:l}){const[c,d]=p.useState({});if(p.useEffect(()=>{t&&i&&d({...i})},[t,i]),!i)return null;const u=a.filter(v=>v.name in i),f=(v,w)=>{d(z=>({...z,[v]:w}))},h=()=>{const v={...c};u.forEach(w=>{const z=c[w.name];if(w.type==="number"){const y=Number(z);v[w.name]=isNaN(y)?i[w.name]:y}else w.type==="boolean"&&(v[w.name]=!!z)}),n(v),o()},m=v=>{const w=c[v.name],z=ct(v.name);return v.type==="boolean"?e.jsx(r.FormControlLabel,{control:e.jsx(r.Switch,{checked:!!w,onChange:y=>f(v.name,y.target.checked),size:"small",sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"primary.main"},"& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track":{bgcolor:"primary.main"}}}),label:e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem",color:"text.primary",fontWeight:500},children:z}),sx:{m:0,bgcolor:"#fff",px:2,py:1,borderRadius:"4px",border:"1px solid divider"}},v.name):e.jsx(r.TextField,{label:z,value:w??"",onChange:y=>f(v.name,y.target.value),type:v.type==="number"?"number":"text",size:"small",fullWidth:!0,variant:"outlined",InputLabelProps:v.type==="string"&&String(w).match(/^\d{4}-\d{2}-\d{2}/)?{shrink:!0}:void 0,sx:{"& .MuiOutlinedInput-root":{fontSize:"0.8125rem",borderRadius:"4px",bgcolor:"common.white","& fieldset":{borderColor:"divider"},"&:hover fieldset":{borderColor:"primary.main"},"&.Mui-focused fieldset":{borderColor:"primary.main",borderWidth:"2px"}},"& .MuiInputLabel-root":{fontSize:"0.8125rem",color:"text.secondary","&.Mui-focused":{color:"primary.main"}},"& .MuiInputBase-input":{color:"text.primary",py:1}}},v.name)};return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",maxHeight:"min(680px, calc(100vh - 180px))",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)"}},children:[e.jsxs(r.Box,{sx:{px:2,py:1.5,bgcolor:"#fff",borderBottom:"1px solid divider",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs(r.Stack,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(k.Edit,{sx:{fontSize:18,color:"#ea8600"}}),e.jsx(r.Typography,{variant:"h6",sx:{fontSize:"0.9375rem",fontWeight:500,color:"text.primary"},children:"Edit Record"})]}),e.jsx(r.IconButton,{size:"small",onClick:o,sx:{p:.5,color:"text.secondary","&:hover":{bgcolor:"action.hover"}},children:e.jsx(k.Close,{sx:{fontSize:18}})})]}),e.jsx(r.DialogContent,{sx:{p:2,bgcolor:"grey.50",overflowY:"auto",flex:1},children:e.jsx(r.Stack,{spacing:1.5,children:u.map(v=>e.jsx(r.Box,{children:m(v)},v.name))})}),e.jsxs(r.DialogActions,{sx:{px:2,py:1.25,borderTop:"1px solid divider",bgcolor:"#fff",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,py:.625,minHeight:32,"&:hover":{bgcolor:"action.hover"}},children:"Cancel"}),e.jsx(r.Button,{onClick:h,variant:"contained",startIcon:e.jsx(k.Save,{sx:{fontSize:16}}),sx:{textTransform:"none",fontSize:"0.8125rem",fontWeight:500,bgcolor:"primary.main",color:"#fff",px:2.5,py:.625,minHeight:32,borderRadius:"4px",boxShadow:"none","&:hover":{bgcolor:"primary.dark",boxShadow:"none"}},children:"Save"})]})]})}const Qc=160,Zc={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"}},ed={low:"text.secondary",medium:"warning.dark",high:"warning.main",critical:"error.main",urgent:"error.main"};function td(t){const o=t.toLowerCase().trim(),n=Zc[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 rd(t){const o=t.toLowerCase().trim(),n=ed[o];return n?e.jsx(r.Box,{component:"span",sx:{color:n,fontWeight:500,fontSize:"inherit"},children:t}):t}function od(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 nd(t,o){const n=t.name.toLowerCase().replace(/[_\s-]/g,""),i=t.name.toLowerCase(),a=o.findIndex(f=>f.name===t.name),l=/(\bid\b|id$|_id$|code$|ref$|no$|num$)/.test(n),c=i.includes("name")||i.includes("task")||i.includes("title")||i.includes("label")||i.includes("subject")||i.includes("description")||i.includes("filename"),d=i.includes("assignee")||i.includes("assigned")||i.includes("owner")||i.includes("author")||i.includes("creator")||i.includes("member")||i.includes("contact")||i.includes("recipient")||i.includes("sender"),u=a===0&&t.type!=="boolean"&&!i.includes("status")&&!i.includes("state");return l||c&&!d||u&&!d}function id(t){return e.jsx(r.Box,{component:"span",sx:{fontWeight:700,color:"text.primary",fontSize:"inherit"},children:t})}function sd(t,o,n=!1){if(o==null||o==="")return e.jsx(r.Box,{component:"span",sx:{color:"grey.400"},children:"—"});const i=String(o),a=t.name.toLowerCase().replace(/[_\s-]/g,""),l=/\b(status|state|stage|employmenttype|contracttype|availability)\b/.test(t.name.toLowerCase());if(l)return td(i);const c=/\b(priority|severity|urgency|importance|criticality)\b/.test(t.name.toLowerCase());if(c)return rd(i);const d=/(\bid\b|id$|_id$|code$|ref$|no$|num$)/.test(a)||/^[A-Z]{2,8}-\d{2,}$/.test(i);if(d)return od(i);if(n&&!l&&!c&&!d)return id(i);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 u=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:[u,o.length>3?` +${o.length-3} more`:""]})}if(typeof o=="object"){const u=JSON.stringify(o);return e.jsx(r.Box,{component:"span",title:u,sx:{color:"text.secondary",fontSize:"0.8125rem",fontFamily:"monospace",cursor:"help"},children:u.length>40?u.slice(0,40)+"…":u})}return i}function ad({schema:t,data:o,sortStack:n=[],filters:i=[],views:a=[],activeViewId:l="",isDirty:c=!1,isExporting:d=!1,columnVisibility:u={},columnOrder:f=[],columnWidths:h={},grouping:m=null,onSort:v,onSortAscending:w,onSortDescending:z,onOpenFilters:y,onOpenSort:j,onOpenFilterForColumn:b,onSelectView:g,onCreateView:S,onManageViews:s,onUpdateCurrentView:I,onSaveAsNewView:A,onToggleDefault:H,onToggleFavorite:N,onRestoreView:K,onPermanentDelete:te,onExport:se,onOpenColumns:x,onUpdateColumnWidth:V,onUpdateColumnOrder:$,onUpdateColumnVisibility:J,onClearFiltersForColumn:oe,onResetLayout:ue,onOpenGroup:pe,onToggleGroupCollapse:_,onOpenAuditHistory:O,onOpenScheduledReports:L,searchQuery:re,searchHistory:Q=[],onAddToSearchHistory:X,onToggleSearchFavourite:ae,onDeleteSearchHistory:Z,selectedRowIds:W=new Set,onSearchChange:ee,onToggleRowSelection:ie,onToggleAllRows:ne,onRangeSelection:ke,onClearSelection:U,onExportSelected:Oe,currentPage:Le=1,pageSize:dt=15,totalRowsBeforePagination:$r=o.length,onPageChange:Re,onPageSizeChange:jt,isReadOnly:Ae=!1,userRole:Ge,reportName:Ke,onEditRow:Xe,onDuplicateRow:_e,onDeleteRow:wt,favoriteRowIndices:Yt=[],resolvedFavoritesSet:rt=new Set,showFavoritesOnly:Qe=!1,onToggleRowFavorite:$e,onBulkSetFavorites:dr,showDevPanel:qt=!1,onOpenDevConfig:ot,onToggleFavoritesFilter:kt}){const[At,ut]=p.useState(null),[ur,Nr]=p.useState(0),[Mt,pr]=p.useState(0),[Wt,Ze]=p.useState(null),[Tt,je]=p.useState(null),[xr,zt]=p.useState(null),[nt,P]=p.useState(!1),[et,ge]=p.useState(!1),[Pe,Rt]=p.useState(null),[fr,pt]=p.useState(""),[hr,Ye]=p.useState(!1),[Jt,_t]=p.useState(null),[Kt,Te]=p.useState(null),[F,Me]=p.useState(null),[Ce,it]=p.useState(null),[Ne,mr]=p.useState("list"),[gr,Xt]=p.useState(!1),[yr,br]=p.useState(()=>!Gc("toolbar_search"));p.useRef(null);const Qt=p.useCallback(()=>{Yc("toolbar_search"),br(!1)},[]),Zt=p.useMemo(()=>f.length>0?f.map(D=>t.find(G=>G.name===D)).filter(D=>D!==void 0):t,[f,t]),Ve=p.useMemo(()=>Zt.filter(D=>u[D.name]!==!1),[Zt,u]),st=p.useMemo(()=>t.filter(D=>u[D.name]===!1).length,[t,u]),Pt=p.useMemo(()=>t.map(D=>D.name),[t]),It=p.useMemo(()=>JSON.stringify(f)!==JSON.stringify(Pt),[f,Pt]),xt=p.useCallback((D,G)=>{D.preventDefault(),D.stopPropagation(),ut(G),Nr(D.clientX),pr(h[G]||150)},[h]);p.useEffect(()=>{if(!At)return;const D=de=>{const We=de.clientX-ur,le=Math.max(100,Mt+We);V==null||V(At,le)},G=()=>{ut(null)};return document.addEventListener("mousemove",D),document.addEventListener("mouseup",G),()=>{document.removeEventListener("mousemove",D),document.removeEventListener("mouseup",G)}},[At,ur,Mt,V]);const at=p.useCallback(D=>D==null?"-":typeof D=="object"?JSON.stringify(D):typeof D=="boolean"?D?"true":"false":String(D),[]);p.useCallback(D=>{const G=n.find(de=>de.column===D);return G?e.jsxs(r.Box,{sx:{display:"inline-flex",alignItems:"center",ml:.5,gap:.25},children:[G.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:G.priority})]}):null},[n]),p.useCallback(D=>i.some(de=>de.column===D)?e.jsx(r.IconButton,{size:"small",onClick:de=>{de.stopPropagation(),b==null||b(D)},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,b]);const $t=p.useCallback(D=>{v&&v(D)},[v]),Nt=p.useCallback((D,G)=>{if(!$)return;const de=[...f.length>0?f:t.map(le=>le.name)],[We]=de.splice(D,1);de.splice(G,0,We),$(de)},[$,f,t]),vr=p.useCallback(D=>{if(!v)return;const G=n.find(de=>de.column===D);(!G||G.direction!=="asc")&&v(D)},[v,n]),Sr=p.useCallback(D=>{if(!v)return;const G=n.find(de=>de.column===D);G?G.direction==="asc"&&v(D):(v(D),setTimeout(()=>v(D),0))},[v,n]),Cr=p.useCallback(D=>{if(!v)return;const G=n.find(de=>de.column===D);G&&(G.direction==="asc"?(v(D),setTimeout(()=>v(D),0)):G.direction==="desc"&&v(D))},[v,n]),jr=p.useCallback(D=>{J&&J(D,!1)},[J]),er=(m==null?void 0:m.enabled)&&o.length>0&&o[0]&&"isGroupHeader"in o[0],wr=(Le-1)*dt,Be=o,ft=p.useMemo(()=>{const D=new Set;return W.forEach(G=>{const de=G==null?void 0:G.__urm_row_id__;de!==void 0&&D.add(de)}),D},[W]);p.useEffect(()=>{const D=G=>{!ne||!U||G.target instanceof HTMLInputElement||G.target instanceof HTMLTextAreaElement||((G.ctrlKey||G.metaKey)&&G.key==="a"&&(G.preventDefault(),ne(!0,Be)),G.key==="Escape"&&(G.preventDefault(),U()))};return document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)},[ne,U,Be]);const tr=p.useCallback((D,G)=>{ie&&(G.shiftKey&&Wt!==null?(G.preventDefault(),ke&&ke(Wt,D,Be)):(ie(Be[D]),Ze(D)))},[ie,Wt,ke,Be]);!p.useMemo(()=>Be.length>0&&ft.size>0&&Be.every(D=>ft.has(D==null?void 0:D.__urm_row_id__)),[Be,ft])&&Be.some(D=>ft.has(D==null?void 0:D.__urm_row_id__));const ht=ie&&ne,kr=p.useCallback(D=>{var We;const G=D.groupLevel,de=G*24;return e.jsx(r.TableRow,{onClick:()=>_==null?void 0:_(D.groupKey),sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"},cursor:"pointer",borderTop:2,borderColor:"divider"},children:e.jsx(r.TableCell,{colSpan:Ve.length+(ht?1:0),sx:{pl:`${de+24}px`},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[D.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:Yn(G,((We=m==null?void 0:m.levels[G])==null?void 0:We.column)||"",D.groupValue)}),e.jsxs(r.Box,{sx:{px:1,py:.25,fontSize:"caption.fontSize",fontWeight:500,bgcolor:le=>R(le.palette.primary.main,.12),color:"primary.main",borderRadius:2},children:[D.rowCount," ",D.rowCount===1?"row":"rows"]}),Object.keys(D.aggregates).length>0&&e.jsx(r.Typography,{variant:"caption",sx:{ml:1,color:"text.secondary"},children:Object.entries(D.aggregates).map(([le,ce])=>Gn(ce)).filter(Boolean).join(" • ")})]})})},D.groupKey)},[Ve,ht,m,_]),rr=p.useCallback((D,G)=>{const de=ft.has(D==null?void 0:D.__urm_row_id__),We=Tt===G;return e.jsxs(r.TableRow,{"data-row-index":G,onMouseEnter:()=>je(G),onMouseLeave:()=>je(null),onClick:le=>{!ie||le.target.closest("[data-row-action]")||tr(G,le)},onContextMenu:le=>{le.preventDefault(),le.stopPropagation(),Me({mouseX:le.clientX,mouseY:le.clientY,row:D,rowIndex:G})},sx:{height:34,cursor:"pointer",bgcolor:de?le=>R(le.palette.warning.main,.12):"background.paper",transition:"background-color 0.12s ease","&:hover":{bgcolor:de?le=>R(le.palette.warning.main,.2):"action.hover"},borderBottom:"1px solid",borderColor:"divider"},children:[Ve.map((le,ce)=>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:h[le.name]?`${h[le.name]}px`:`${Qc}px`},children:sd(le,D[le.name],nd(le,Ve))},le.name)),e.jsxs(r.TableCell,{"data-row-action":"true",onClick:le=>le.stopPropagation(),sx:{position:"sticky",right:0,width:$e?76:40,minWidth:$e?76:40,maxWidth:$e?76:40,p:0,border:"none",bgcolor:"transparent",opacity:We?1:0,transition:"opacity 0.12s ease",zIndex:2,verticalAlign:"middle",display:"flex",alignItems:"center",justifyContent:"flex-end",gap:.25},children:[$e&&e.jsx(r.IconButton,{size:"small",onClick:le=>{le.stopPropagation(),le.preventDefault(),$e(D)},title:rt.has(D)?"Remove from favorites":"Add to favorites",sx:{color:rt.has(D)?"warning.main":"text.secondary","&:hover":{bgcolor:le=>R(le.palette.warning.main,.08),color:"warning.main"}},children:rt.has(D)?e.jsx(k.Star,{sx:{fontSize:18}}):e.jsx(k.StarBorder,{sx:{fontSize:18}})}),e.jsx(r.IconButton,{size:"small",onClick:le=>{le.stopPropagation(),le.preventDefault(),Me({anchorEl:le.currentTarget,row:D,rowIndex:G})},sx:{color:"text.secondary","&:hover":{bgcolor:le=>R(le.palette.text.primary,.08),color:"text.primary"}},children:e.jsx(k.MoreVert,{sx:{fontSize:18}})})]})]},G)},[W,wr,Tt,tr,Ve,h,at,Xe,_e,wt,ie,$e,rt,zt,P,Me]);return e.jsxs(St.DndProvider,{backend:_o.HTML5Backend,children:[e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[ht&&Oe&&U&&e.jsx(Wc,{selectedCount:W.size,selectedRowIds:W,resolvedFavoritesSet:rt,viewMode:Ne,onExportSelected:Oe,onClearSelection:U,onBulkSetFavorites:dr}),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:[Ae&&e.jsx(Uc,{}),ee&&X&&ae&&Z&&e.jsx(r.Tooltip,{open:yr,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:Qt},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(Dc,{value:re||"",onChange:ee,searchHistory:Q,onAddToHistory:X,onToggleFavourite:ae,onDeleteHistory:Z,disabled:Ae})})}),e.jsx(r.Tooltip,{title:"JSON format guide",children:e.jsx(r.IconButton,{size:"small",onClick:()=>Xt(!0),sx:{color:"text.secondary",borderRadius:1,"&:hover":{bgcolor:D=>R(D.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(k.InfoOutlined,{sx:{fontSize:20}})})}),kt&&e.jsx(r.Tooltip,{title:Qe?"Show all data":"Show favorites only",children:e.jsxs(r.IconButton,{onClick:kt,size:"small",disabled:Ae,sx:{position:"relative",color:Qe?"warning.main":"text.secondary",bgcolor:Qe?D=>R(D.palette.warning.main,.12):"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:Qe?D=>R(D.palette.warning.main,.2):D=>R(D.palette.text.primary,.06),color:Qe?"warning.main":"text.primary"},"&.Mui-disabled":{color:"action.disabled"}},children:[Qe?e.jsx(k.Star,{sx:{fontSize:20}}):e.jsx(k.StarBorder,{sx:{fontSize:20}}),Qe&&Yt.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:Yt.length})]})}),qt&&ot&&e.jsx(r.Tooltip,{title:"Developer configuration",children:e.jsx(r.IconButton,{size:"small",onClick:ot,sx:{color:"text.secondary",borderRadius:1,border:"1px dashed",borderColor:D=>R(D.palette.text.secondary,.3),"&:hover":{bgcolor:D=>R(D.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}}),g&&S&&s&&I&&a.length>0&&e.jsx(Bc,{views:a||[],activeViewId:l||"",isDirty:c,onSelectView:g,onCreateView:S,onManageViews:s,onToggleDefault:H,onToggleFavorite:N,onRestoreView:K,onPermanentDelete:te,isReadOnly:Ae}),!Ae&&j&&e.jsx(r.Tooltip,{title:"Sort",children:e.jsxs(r.IconButton,{onClick:j,size:"small",sx:{position:"relative",color:n.length>0?"primary.main":"text.secondary",bgcolor:n.length>0?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:n.length>0?D=>R(D.palette.primary.main,.2):D=>R(D.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})]})}),!Ae&&y&&e.jsx(r.Tooltip,{title:"Filter",children:e.jsxs(r.IconButton,{onClick:y,size:"small",sx:{position:"relative",color:i.length>0?"primary.main":"text.secondary",bgcolor:i.length>0?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:i.length>0?D=>R(D.palette.primary.main,.2):D=>R(D.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})]})}),!Ae&&x&&e.jsx(r.Tooltip,{title:"Columns",children:e.jsxs(r.IconButton,{onClick:x,size:"small",sx:{position:"relative",color:st>0||It?"primary.main":"text.secondary",bgcolor:st>0||It?"primary.lighter":"transparent",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:st>0||It?D=>R(D.palette.primary.main,.2):D=>R(D.palette.text.primary,.06),color:st>0||It?"primary.main":"text.primary"}},children:[e.jsx(k.ViewColumn,{sx:{fontSize:20}}),st>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:st})]})}),e.jsx(r.Divider,{orientation:"vertical",flexItem:!0,sx:{mx:.5,my:1.5}}),e.jsx(r.Tooltip,{title:"List view",children:e.jsx(r.IconButton,{size:"small",onClick:()=>mr("list"),sx:{borderRadius:1,color:Ne==="list"?"primary.main":"text.secondary",bgcolor:Ne==="list"?"primary.lighter":"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:Ne==="list"?D=>R(D.palette.primary.main,.2):D=>R(D.palette.text.primary,.06),color:Ne==="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:()=>mr("grid"),sx:{borderRadius:1,color:Ne==="grid"?"primary.main":"text.secondary",bgcolor:Ne==="grid"?"primary.lighter":"transparent",transition:"all 0.15s ease","&:hover":{bgcolor:Ne==="grid"?D=>R(D.palette.primary.main,.2):D=>R(D.palette.text.primary,.06),color:Ne==="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:D=>it(D.currentTarget),size:"small",sx:{color:"text.secondary",borderRadius:1,transition:"all 0.15s ease","&:hover":{bgcolor:D=>R(D.palette.text.primary,.06),color:"text.primary"}},children:e.jsx(k.Settings,{sx:{fontSize:20}})})})]}),e.jsxs(r.Popover,{open:!!Ce,anchorEl:Ce,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:[se&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{se(),it(null)},disabled:d,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"})]}),!Ae&&pe&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{pe(),it(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"})]}),O&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{O(),it(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"})]}),L&&e.jsxs(r.MenuItem,{dense:!0,onClick:()=>{L(),it(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",overflow:"hidden",flex:1,display:"flex",flexDirection:"column"},children:[Ne==="grid"&&e.jsx(r.Box,{sx:{flex:1,overflowY:"auto",overflowX:"hidden",bgcolor:"action.hover"},children:e.jsx(Vc,{data:Be,visibleColumns:Ve,grouping:m,selectedRowIds:W,resolvedFavoritesSet:rt,isReadOnly:Ae,isGrouped:!!er,sortStack:n,onSort:v,onToggleRowSelection:ie||(()=>{}),onToggleRowFavorite:$e,onToggleGroupCollapse:_,onViewRow:D=>{zt(D),P(!0)},onEditRow:(D,G)=>{_t(D),Te(G),Ye(!0)},onDuplicateRow:(D,G)=>_e==null?void 0:_e(D,G),onDeleteRow:(D,G)=>{Rt(G);const de=Object.values(G).find(We=>We!=null&&We!=="");pt(de?String(de):""),ge(!0)}})}),Ne==="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:D=>D.palette.mode==="dark"?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.2)",borderRadius:4,"&:hover":{bgcolor:D=>D.palette.mode==="dark"?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.3)"}}},children:e.jsxs(r.Table,{sx:{tableLayout:"fixed",borderCollapse:"collapse",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:[Ve.map((D,G)=>e.jsx(Mc,{column:D,index:G,sortRule:n.find(de=>de.column===D.name),hasFilters:i.some(de=>de.column===D.name),isInSortStack:n.some(de=>de.column===D.name),width:h[D.name],onColumnClick:$t,onMoveColumn:Nt,onResizeStart:xt,onSort:$t,onRemoveSort:Cr,onSortAscending:vr,onSortDescending:Sr,onOpenFilterForColumn:b||(()=>{}),onClearFiltersForColumn:oe||(()=>{}),onHideColumn:jr,onManageColumns:x||(()=>{}),onManageViews:s||(()=>{}),onResetLayout:ue||(()=>{})},D.name)),e.jsx(r.TableCell,{sx:{position:"sticky",top:0,right:0,width:$e?76:40,minWidth:$e?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:Ve.length+(ht?1:0),align:"center",sx:{py:4},children:e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:"No data matches the current filters"})})}):er?Be.map((D,G)=>D.isGroupHeader?kr(D):rr(D,G)):Be.map((D,G)=>rr(D,G))})]})}),Re&&jt&&e.jsx(Hc,{currentPage:Le,pageSize:dt,totalRows:$r,totalFields:t.length,onPageChange:Re,onPageSizeChange:jt}),!(Re&&jt)&&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:!!F,onClose:()=>Me(null),anchorEl:(F==null?void 0:F.anchorEl)||null,anchorReference:F!=null&&F.anchorEl?"anchorEl":"anchorPosition",anchorPosition:F&&!F.anchorEl?{top:F.mouseY,left:F.mouseX}:void 0,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:F!=null&&F.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:()=>{F&&(zt(F.row),P(!0)),Me(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:()=>{F&&(_t(F.row),Te(F.rowIndex),Ye(!0)),Me(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:()=>{F&&(_e==null||_e(F.rowIndex,F.row)),Me(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(F){Rt(F.row);const D=Object.values(F.row).find(G=>G!=null&&G!=="");pt(D?String(D):""),ge(!0)}Me(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(Jc,{open:nt,onClose:()=>{P(!1),zt(null)},row:xr,schema:t,reportName:Ke}),e.jsx(Xc,{open:hr,onClose:()=>{Ye(!1),_t(null),Te(null)},onSave:D=>{Kt!==null&&(Xe==null||Xe(Kt,D))},row:Jt,schema:t,reportName:Ke}),e.jsx(Kc,{open:et,onClose:()=>{ge(!1),Rt(null)},onConfirm:()=>{Pe!==null&&(wt==null||wt(Pe))},rowPreview:fr}),e.jsx(bi,{isOpen:gr,onClose:()=>Xt(!1)})]})}function Ut({content:t,isDev:o=!1}){const[n,i]=p.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(r.IconButton,{size:"small",onClick:a=>i(a.currentTarget),"aria-label":`Help: ${t.title}`,sx:{p:.375,color:"text.disabled","&:hover":{color:"primary.main",bgcolor:a=>R(a.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:a=>R(a.palette.primary.main,.06)},children:e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,color:"primary.main",fontSize:"0.875rem"},children:t.title})}),e.jsx(r.Divider,{}),e.jsxs(r.Box,{sx:{px:2,py:1.5,display:"flex",flexDirection:"column",gap:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{color:"text.secondary",fontSize:"0.8125rem",lineHeight:1.6},children:t.description}),t.tips&&t.tips.length>0&&e.jsx(r.Box,{component:"ul",sx:{m:0,pl:2,display:"flex",flexDirection:"column",gap:.5},children:t.tips.map((a,l)=>e.jsx(r.Box,{component:"li",sx:{fontSize:"0.8125rem",color:"text.secondary",lineHeight:1.5},children:a},l))}),o&&t.devNote&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{sx:{my:.5}}),e.jsxs(r.Box,{sx:{px:1.25,py:.75,borderRadius:"6px",bgcolor:a=>R(a.palette.warning.main,.08),border:"1px solid",borderColor:a=>R(a.palette.warning.main,.2)},children:[e.jsx(r.Typography,{variant:"caption",sx:{color:"warning.dark",fontWeight:500,display:"block",mb:.25},children:"Dev note"}),e.jsx(r.Typography,{variant:"caption",sx:{color:"warning.dark",lineHeight:1.5},children:t.devNote})]})]})]})]})]})}const 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 ld({schema:t,filters:o,onAddFilter:n,onRemoveFilter:i,onUpdateFilter:a,onClearAll:l,onClose:c,focusColumn:d}){const[u,f]=p.useState(""),[h,m]=p.useState(""),[v,w]=p.useState(""),[z,y]=p.useState([]),j=Rr();p.useEffect(()=>{y([...o])},[o]),p.useEffect(()=>{d&&f(d)},[d]);const b=p.useCallback(()=>{f(""),m(""),w("")},[]),g=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),s=p.useMemo(()=>{const x=S?an(S.type):[],V=j.filter.allowedOperators;return V.length>0?x.filter($=>V.includes($.value)):x},[S]),I=p.useCallback(()=>!(!u||!h||Ur(h)&&!v.trim()||z.length>=j.filter.maxConditions),[u,h,v,z,j]),A=p.useCallback(()=>{if(!I())return;const x={column:u,operator:h};if(Ur(h)){const $=S==null?void 0:S.type;x.value=$==="number"?Number(v):v}if(z.some($=>$.column===x.column&&$.operator===x.operator&&$.value===x.value)){b();return}y([...z,x]),b()},[I,u,h,S,v,z,b]),H=p.useCallback(x=>{y(z.filter((V,$)=>$!==x))},[z]),N=p.useMemo(()=>z.length!==o.length?!0:JSON.stringify(z)!==JSON.stringify(o),[z,o]),K=p.useCallback(()=>{l(),z.forEach(x=>n(x)),c()},[z,n,l,c]),te=p.useCallback(()=>{y([...o]),b(),c()},[o,b,c]),se=p.useCallback(x=>{var oe;const V=t.find(ue=>ue.name===x.column);if(!V)return"";const J=((oe=an(V.type).find(ue=>ue.value===x.operator))==null?void 0:oe.label)||x.operator;return Ur(x.operator)?`${x.column} ${J.toLowerCase()} "${x.value}"`:`${x.column} ${J.toLowerCase()}`},[t]);return e.jsx(r.Box,{onClick:te,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(Ut,{content:Gt.filter,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:te,size:"small",sx:{p:.75,color:"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"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=>{f(x.target.value),m(""),w("")},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:g.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:V=>R(V.palette.primary.main,.2)}}},children:[ct(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=>{m(x.target.value),w("")},label:"Operator",sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300",transition:"border-color 0.2s ease"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:s.map(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:V=>R(V.palette.primary.main,.2)}}},children:x.label},x.value))})]}),h&&Ur(h)&&e.jsx(r.TextField,{size:"small",fullWidth:!0,type:(S==null?void 0:S.type)==="number"?"number":"text",value:v,onChange:x=>w(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:!I(),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:()=>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:z.map((x,V)=>e.jsx(r.Chip,{label:se(x),onDelete:()=>H(V),sx:{bgcolor:"primary.lighter",color:"primary.main",fontSize:"0.875rem",fontWeight:400,height:32,borderRadius:"16px",border:$=>`1px solid ${R($.palette.primary.main,.3)}`,transition:"all 0.2s ease","&:hover":{bgcolor:$=>R($.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"}}}},V))})]})]}),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:te,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,disabled:!N,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 Pn="SORT_RULE";function cd({rule:t,index:o,onToggleDirection:n,onRemove:i,onMove:a}){const l=p.useRef(null),[{handlerId:c},d]=St.useDrop({accept:Pn,collect(h){return{handlerId:h.getHandlerId()}},hover(h,m){var g;if(!l.current)return;const v=h.index,w=o;if(v===w)return;const z=(g=l.current)==null?void 0:g.getBoundingClientRect(),y=(z.bottom-z.top)/2,j=m.getClientOffset(),b=((j==null?void 0:j.y)??0)-z.top;v<w&&b<y||v>w&&b>y||(a(v,w),h.index=w)}}),[{isDragging:u},f]=St.useDrag({type:Pn,item:()=>({index:o}),collect:h=>({isDragging:h.isDragging()})});return f(d(l)),e.jsxs(r.Box,{ref:l,"data-handler-id":c,sx:{display:"flex",alignItems:"center",gap:1.25,px:2,py:1.25,borderRadius:"8px",bgcolor:"background.paper",border:"1px solid divider",opacity:u?.4:1,cursor:"move",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{bgcolor:"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=>R(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=>R(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 dd({schema:t,sortStack:o,onUpdateSortStack:n,onClose:i}){const[a,l]=p.useState(""),[c,d]=p.useState([]);p.useEffect(()=>{d([...o])},[o]);const u=Rr(),f=p.useCallback(()=>!(c.length>=u.sort.maxLevels||!a||c.some(g=>g.column===a)),[c,a]),h=p.useCallback(()=>{if(!f())return;const g=c.length+1,S={column:a,direction:"asc",priority:g};d([...c,S]),l("")},[f,a,c]),m=p.useCallback(g=>{const s=c.filter((I,A)=>A!==g).map((I,A)=>({...I,priority:A+1}));d(s)},[c]),v=p.useCallback((g,S)=>{const s=[...c];s[g]={...s[g],direction:S},d(s)},[c]),w=p.useCallback((g,S)=>{const s=[...c],[I]=s.splice(g,1);s.splice(S,0,I);const A=s.map((H,N)=>({...H,priority:N+1}));d(A)},[c]),z=p.useCallback(()=>{d([])},[]),y=p.useCallback(()=>{n(c),i()},[c,n,i]),j=p.useCallback(()=>{d([...o]),l(""),i()},[o,i]),b=t.filter(g=>!c.some(S=>S.column===g.name));return e.jsx(St.DndProvider,{backend:_o.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:g=>g.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(Ut,{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(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:c.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:a,onChange:g=>l(g.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:b.map(g=>e.jsx(r.MenuItem,{value:g.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:S=>R(S.palette.primary.main,.2)}}},children:ct(g.name)},g.name))})]}),e.jsx(r.Button,{onClick:h,disabled:!f(),sx:{mt:1.5,textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"primary.main",p:0,justifyContent:"flex-start",minHeight:"auto",transition:"color 0.2s ease","&:hover":{bgcolor:"transparent",color:"primary.dark",textDecoration:"underline"},"&.Mui-disabled":{color:"grey.400"}},children:"+ Add sort column"}),c.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"]})]}),c.length>0&&e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1.5},children:[e.jsxs(r.Typography,{variant:"overline",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",textTransform:"uppercase"},children:["Sorted sequence (",c.length,"/",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:c.map((g,S)=>e.jsx(cd,{rule:g,index:S,onToggleDirection:v,onRemove:m,onMove:w},`${g.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: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: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 ud({views:t,activeViewId:o,onSelectView:n,onCreateView:i,onEditView:a,onDeleteView:l,onRestoreView:c,onPermanentDelete:d,onClose:u}){return e.jsxs(r.Dialog,{open:!0,onClose:u,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:["Manage Views",e.jsx(r.IconButton,{onClick:u,size:"small",sx:{color:"text.secondary"},children:e.jsx(k.Close,{sx:{fontSize:20}})})]}),e.jsxs(r.DialogContent,{children:[e.jsx(r.Box,{sx:{mb:2},children:e.jsx(r.Button,{onClick:i,variant:"contained",startIcon:e.jsx(k.Add,{sx:{fontSize:16}}),size:"small",children:"Create New Report View"})}),e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:t.map(f=>e.jsx(r.Paper,{sx:{p:2,border:1,borderColor:f.isDeleted?"error.light":o===f.id?"primary.main":"divider",bgcolor:f.isDeleted?h=>R(h.palette.error.main,.12):o===f.id?h=>R(h.palette.primary.main,.12):"background.paper",opacity:f.isDeleted?.75:1,cursor:f.isDeleted?"default":"pointer","&:hover":f.isDeleted?{}:{bgcolor:"action.hover"}},onClick:()=>!f.isDeleted&&n(f.id),elevation:0,children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"flex-start",gap:1.5},children:[e.jsxs(r.Box,{sx:{flex:1},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,textDecoration:f.isDeleted?"line-through":"none",color:f.isDeleted?"text.secondary":"text.primary"},children:f.name}),f.isDeleted&&e.jsx(r.Chip,{label:"Deleted",size:"small",color:"error",sx:{height:20}}),f.isDefault&&e.jsx(r.Chip,{label:"Default",size:"small",color:"primary",sx:{height:20}}),f.isFavorite&&e.jsx(r.Chip,{label:"★ Favorite",size:"small",sx:{height:20}})]}),f.description&&e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:f.description})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[!f.isDeleted&&e.jsxs(e.Fragment,{children:[e.jsx(r.IconButton,{size:"small",onClick:h=>{h.stopPropagation(),a(f.id)},title:"Edit view",children:e.jsx(k.Edit,{sx:{fontSize:16}})}),e.jsx(r.IconButton,{size:"small",onClick:h=>{h.stopPropagation(),l(f.id)},title:"Delete view",sx:{"&:hover":{color:"error.main"}},children:e.jsx(k.Delete,{sx:{fontSize:16}})})]}),f.isDeleted&&c&&e.jsx(r.IconButton,{size:"small",onClick:h=>{h.stopPropagation(),c(f.id)},title:"Restore view",sx:{color:"success.main"},children:e.jsx(k.Undo,{sx:{fontSize:16}})}),f.isDeleted&&d&&e.jsx(r.IconButton,{size:"small",onClick:h=>{h.stopPropagation(),d(f.id)},title:"Delete permanently",sx:{color:"error.main"},children:e.jsx(k.Delete,{sx:{fontSize:16}})})]})]})},f.id))})]}),e.jsx(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:u,variant:"contained",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)"}},children:"Close"})})]})}function $n({currentSnapshot:t,onSave:o,onClose:n,isEditMode:i=!1,initialName:a="",initialDescription:l="",initialIsDefault:c=!1}){const[d,u]=p.useState(a),[f,h]=p.useState(!1),[m,v]=p.useState(l),[w,z]=p.useState(c),y=()=>{if(!d.trim()){h(!0);return}o(d.trim(),m.trim(),w),n()},j=g=>{g.key==="Enter"&&!g.shiftKey?y():g.key==="Escape"&&n()},b=()=>i&&a?`Update ${a} view`:"Create New Report View";return e.jsxs(r.Dialog,{open:!0,onClose:n,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{mt:8,borderRadius:"12px",boxShadow:"0 8px 16px 4px rgba(60, 64, 67, 0.12), 0 4px 16px 0px rgba(60, 64, 67, 0.08), 0 0 0 1px rgba(60, 64, 67, 0.05)"}},children:[e.jsxs(r.DialogTitle,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",pb:1},children:[b(),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:[e.jsx(r.TextField,{label:"View Name",required:!0,value:d,onChange:g=>{u(g.target.value),f&&g.target.value.trim()&&h(!1)},onKeyDown:j,placeholder:"e.g., Active Users",autoFocus:!0,fullWidth:!0,size:"small",inputProps:{maxLength:100},error:f&&!d.trim(),helperText:f&&!d.trim()?"View name is required":void 0}),e.jsx(r.TextField,{label:"Description (optional)",value:m,onChange:g=>v(g.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: ",gs(t.sortStack)]}),e.jsx("li",{children:"Column order & visibility"})]})]}),!i&&e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{checked:w,onChange:g=>z(g.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:y,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: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 pd({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 Wo=80,Ro=600,Nn="COLUMN";function xd({column:t,index:o,isVisible:n,width:i,onToggleVisibility:a,onWidthChange:l,moveColumn:c}){const d=p.useRef(null),[u,f]=p.useState(i.toString());p.useEffect(()=>{f(i.toString())},[i]);const[{handlerId:h},m]=St.useDrop({accept:Nn,collect(g){return{handlerId:g.getHandlerId()}},hover(g,S){var te;if(!d.current)return;const s=g.index,I=o;if(s===I)return;const A=(te=d.current)==null?void 0:te.getBoundingClientRect(),H=(A.bottom-A.top)/2,N=S.getClientOffset(),K=((N==null?void 0:N.y)??0)-A.top;s<I&&K<H||s>I&&K>H||(c(s,I),g.index=I)}}),[{isDragging:v},w]=St.useDrag({type:Nn,item:()=>({index:o}),collect:g=>({isDragging:g.isDragging()})});w(m(d));const z=()=>{const g=parseInt(u);if(isNaN(g)){f(i.toString()),l(t.name,i);return}const S=Math.max(Wo,Math.min(Ro,g));f(S.toString()),l(t.name,S)},y=g=>{if(g===""||/^\d+$/.test(g)){f(g);const S=parseInt(g);if(!isNaN(S)&&S>=Wo){const s=Math.min(Ro,S);l(t.name,s)}}},j=g=>{g.key==="Enter"&&(g.preventDefault(),z(),g.target.blur())},b=g=>({string:"primary.main",number:"success.main",boolean:"#9334e6",array:"#ea8600",object:"error.main",null:"text.secondary",mixed:"text.secondary"})[g]||"text.secondary";return e.jsxs(r.TableRow,{ref:d,"data-handler-id":h,sx:{opacity:v?.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:ct(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:`${b(t.type)}15`,color:b(t.type),border:`1px solid ${b(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:g=>y(g.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:()=>a(t.name,!n),title:n?"Hide column":"Show column",size:"small",sx:{p:.75,color:n?"primary.main":"text.secondary",transition:"all 0.2s ease","&:hover":{bgcolor:"grey.100",color:n?"primary.dark":"primary.main"}},children:n?e.jsx(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 fd({schema:t,columnVisibility:o,columnOrder:n,columnWidths:i={},views:a=[],activeViewId:l="",onUpdateColumnVisibility:c,onUpdateColumnOrder:d,onUpdateColumnWidth:u,onResetLayout:f,onSaveToCurrentView:h,onSaveToAllViews:m,onSelectView:v,onClose:w}){const[z,y]=p.useState(!1),[j,b]=p.useState(n),[g,S]=p.useState(i),[s,I]=p.useState("all"),[A,H]=p.useState(null);p.useEffect(()=>{b(n)},[n]),p.useEffect(()=>{S(i)},[i]);const N=(_,O)=>{S(L=>({...L,[_]:O}))},K=(_,O)=>{const L=[...j],[re]=L.splice(_,1);L.splice(O,0,re),b(L),d(L)},te=()=>{f(),y(!1)},x=j.map(_=>t.find(O=>O.name===_)).filter(_=>_!==void 0).filter(_=>{const O=o[_.name]??!0;return s==="active"?O:s==="hidden"?!O:!0}),V=Object.values(o).filter(_=>_).length,$=t.length,J=a.find(_=>_.id===l),oe=a.filter(_=>!_.isDeleted),ue=oe.length>1,pe=p.useMemo(()=>{if(!J)return!1;const _=J.snapshot,O=JSON.stringify(o)!==JSON.stringify(_.columnVisibility),L=JSON.stringify(n)!==JSON.stringify(_.columnOrder),re=JSON.stringify(g)!==JSON.stringify(_.columnWidths);return O||L||re},[J,o,n,g]);return e.jsx(St.DndProvider,{backend:_o.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:_=>_.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(Ut,{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:[V," of ",$," columns visible • Drag to reorder"]})]}),oe.length>0&&v&&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:_=>H(_.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:(J==null?void 0:J.name)||"Select View"})}),e.jsx(r.Menu,{anchorEl:A,open:!!A,onClose:()=>H(null),PaperProps:{sx:{mt:.5,borderRadius:"8px",boxShadow:"0 2px 6px rgba(60, 64, 67, 0.15)"}},children:oe.map(_=>e.jsx(r.MenuItem,{onClick:()=>{v(_.id),H(null)},selected:_.id===l,sx:{fontSize:"0.875rem",color:"text.primary",py:1,px:2,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:O=>R(O.palette.primary.main,.2)}}},children:_.name},_.id))})]}),e.jsx(r.IconButton,{onClick:w,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:s,onChange:(_,O)=>I(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: ${Wo}px, max: ${Ro}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((_,O)=>e.jsx(xd,{column:_,index:O,isVisible:o[_.name]??!0,width:g[_.name]||150,onToggleVisibility:c,onWidthChange:N,moveColumn:K},_.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(g),w()},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"}),m&&ue&&e.jsx(r.Button,{onClick:()=>{m(g),w()},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"})]})]}),z&&e.jsx(r.Box,{onClick:()=>y(!1),sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1400},children:e.jsxs(r.Paper,{onClick:_=>_.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:te,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 hd({schema:t,grouping:o,onApply:n,onClose:i}){var A;const[a,l]=p.useState(o||{enabled:!1,levels:[],collapsedGroups:[]}),[c,d]=p.useState(""),[u,f]=p.useState(null),h=p.useMemo(()=>us(t),[t]),m=p.useMemo(()=>h.filter(H=>!a.levels.some((N,K)=>N.column===H.name&&K!==u)),[h,a.levels,u]),v=Rr(),w=a.levels.length<v.grouping.maxLevels&&m.length>0,z=p.useCallback(()=>{!w||!c||(l({...a,levels:[...a.levels,{column:c}],enabled:!0}),d(""))},[w,c,a]),y=p.useCallback(H=>{const N=a.levels.filter((K,te)=>te!==H);if(N.length===0){n(null),i();return}l({...a,levels:N,enabled:N.length>0})},[a,n,i]),j=p.useCallback(H=>{f(H),d(a.levels[H].column)},[a.levels]),b=p.useCallback(()=>{if(u===null||!c)return;const H=[...a.levels];H[u]={column:c},l({...a,levels:H}),f(null),d("")},[u,c,a]),g=p.useCallback(()=>{f(null),d("")},[]),S=p.useCallback((H,N)=>{const K=N==="up"?H-1:H+1;if(K<0||K>=a.levels.length)return;const te=[...a.levels],[se]=te.splice(H,1);te.splice(K,0,se),l({...a,levels:te})},[a]),s=p.useCallback(()=>{n(null),i()},[n,i]),I=p.useCallback(()=>{a.levels.length===0?n(null):n({...a,enabled:!0,collapsedGroups:(o==null?void 0:o.collapsedGroups)||[]}),i()},[a,o,n,i]);return e.jsx(r.Box,{onClick:i,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"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:H=>H.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(Ut,{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(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:c,onChange:H=>d(H.target.value),disabled:!w,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..."}),m.map(H=>e.jsxs(r.MenuItem,{value:H.name,sx:{fontSize:"0.875rem",color:"text.primary",py:1,"&:hover":{bgcolor:"grey.100"},"&.Mui-selected":{bgcolor:"primary.lighter","&:hover":{bgcolor:N=>R(N.palette.primary.main,.2)}}},children:[ct(H.name)," (",H.type.toUpperCase(),")"]},H.name))]})}),e.jsx(r.Button,{onClick:z,disabled:!w||!c,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"}),a.levels.length>=v.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:c,onChange:H=>d(H.target.value),sx:{fontSize:"0.875rem",height:40,borderRadius:"4px",bgcolor:"background.paper","& .MuiOutlinedInput-notchedOutline":{borderColor:"grey.300"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main",borderWidth:"2px"}},children:[e.jsx(r.MenuItem,{value:"",sx:{fontSize:"0.875rem"},children:"Select a column..."}),e.jsxs(r.MenuItem,{value:a.levels[u].column,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:"primary.lighter"}},children:[a.levels[u].column," (",(A=t.find(H=>H.name===a.levels[u].column))==null?void 0:A.type.toUpperCase(),")"]}),m.filter(H=>H.name!==a.levels[u].column).map(H=>e.jsxs(r.MenuItem,{value:H.name,sx:{fontSize:"0.875rem","&.Mui-selected":{bgcolor:"primary.lighter"}},children:[ct(H.name)," (",H.type.toUpperCase(),")"]},H.name))]})}),e.jsxs(r.Stack,{direction:"row",spacing:1.5,children:[e.jsx(r.Button,{onClick:b,disabled:!c,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:g,variant:"outlined",fullWidth:!0,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"text.secondary",borderColor:"grey.300",py:.875,"&:hover":{borderColor:"grey.400",bgcolor:"grey.50"}},children:"Cancel"})]})]}),a.levels.length>0&&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:s,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,color:"error.main",p:0,minWidth:"auto","&:hover":{bgcolor:"transparent",color:"#b3190e",textDecoration:"underline"}},children:"Clear all"})]}),e.jsx(r.Stack,{spacing:1.5,children:a.levels.map((H,N)=>{const K=t.find(te=>te.name===H.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${N+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:H.column}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:K==null?void 0:K.type.toUpperCase()})]}),e.jsxs(r.Stack,{direction:"row",spacing:.5,children:[e.jsx(r.IconButton,{size:"small",onClick:()=>S(N,"up"),disabled:N===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(N,"down"),disabled:N===a.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:()=>j(N),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(N),sx:{color:"text.secondary","&:hover":{bgcolor:"rgba(217, 48, 37, 0.08)",color:"error.main"}},children:e.jsx(k.Delete,{sx:{fontSize:18}})})]})]},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: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:I,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 md={filters:k.FilterList,sorting:k.UnfoldMore,visibility:k.Visibility,order:k.ViewColumn,widths:k.Straighten,grouping:k.Layers};function gd({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,a)=>{const l=md[i.category];return e.jsxs(r.Paper,{elevation:0,sx:{display:"flex",gap:1.5,p:1.5,border:1,borderColor:"divider",borderRadius:1},children:[e.jsx(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,borderRadius:1,bgcolor:`${n(i.category)}.lighter`,color:`${n(i.category)}.main`,flexShrink:0},children:e.jsx(l,{sx:{fontSize:16}})}),e.jsxs(r.Box,{sx:{flex:1,minWidth:0},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500},children:i.label}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",children:i.description})]})]},a)})})]})}),e.jsx(r.DialogActions,{sx:{px:3,py:1.75,borderTop:"1px solid divider",bgcolor:"action.hover",gap:1.25,justifyContent:"flex-end"},children:e.jsx(r.Button,{onClick:o,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"common.white",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Close"})})]})}function yd({viewName:t,isDefaultView:o,changes:n=[],onSaveToCurrentView:i,onSaveAsNewView:a,onCancel:l}){const[c,d]=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 ${R(u.palette.primary.main,.3)}`,zIndex:10},children:e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",px:3,py:1.25},children:[e.jsxs(r.Typography,{variant:"body2",sx:{fontWeight:400,fontSize:"0.875rem",color:"text.primary"},children:['Unsaved changes to "',t,'"']}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(r.Button,{onClick:l,variant:"text",size:"small",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2,py:.625,borderRadius:"18px",color:"text.secondary",bgcolor:"transparent",minHeight:32,"&:hover":{bgcolor:"rgba(60, 64, 67, 0.08)",color:"text.primary"}},children:"Discard"}),e.jsx(r.Button,{onClick:a,variant:"contained",size:"small",disableElevation:!0,sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2.5,py:.625,borderRadius:"18px",minHeight:32,boxShadow:"none","&:hover":{boxShadow:"0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px rgba(60, 64, 67, 0.15)"}},children:"Save as new view"})]})]})}),c&&e.jsx(gd,{changes:n,onClose:()=>d(!1)})]})}function bd({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"})]})]})})}function vd({auditHistory:t,onClose:o}){const[n,i]=p.useState(new Set),a=c=>{i(d=>{const u=new Set(d);return u.has(c)?u.delete(c):u.add(c),u})},l=[...t].sort((c,d)=>new Date(d.timestamp).getTime()-new Date(c.timestamp).getTime());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:c=>c.stopPropagation(),elevation:0,sx:{position:"relative",width:480,maxWidth:"calc(100vw - 120px)",maxHeight:"min(720px, 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:"flex-start",justifyContent:"space-between",px:3,py:2,borderBottom:"1px solid divider",flexShrink:0},children:[e.jsxs(r.Box,{children:[e.jsxs(r.Typography,{variant:"h6",sx:{fontSize:"1.125rem",fontWeight:500,color:"text.primary",letterSpacing:"0",lineHeight:1.5},children:["Audit history",e.jsx(Ut,{content:Gt.auditHistory,isDev:process.env.NODE_ENV==="development"})]}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.8125rem",color:"text.secondary",mt:.5,display:"block"},children:[l.length," event",l.length!==1?"s":""," recorded"]})]}),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:2,py:1,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:4,"&:hover":{bgcolor:"grey.400"}}},children:l.length===0?e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",py:8,textAlign:"center"},children:[e.jsx(k.AccessTime,{sx:{fontSize:64,color:"divider",mb:2}}),e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary",mb:.5},children:"No audit events recorded yet"}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"grey.400"},children:"Changes to this report will appear here"})]}):e.jsx(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:l.map(c=>{const d=n.has(c.id),u=Os(c.feature);return e.jsxs(r.Paper,{elevation:0,sx:{border:"1px solid divider",borderRadius:"8px",overflow:"hidden",transition:"all 0.2s ease","&:hover":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.1)",borderColor:"grey.300"}},children:[e.jsxs(r.Box,{onClick:()=>a(c.id),sx:{px:2.5,py:1.75,display:"flex",alignItems:"center",gap:1.5,cursor:"pointer",bgcolor:"background.paper",transition:"background-color 0.2s ease","&:hover":{bgcolor:"grey.50"}},children:[e.jsx(r.Box,{sx:{flexShrink:0,color:"text.secondary",transition:"transform 0.2s ease",transform:"rotate(0deg)"},children:d?e.jsx(k.KeyboardArrowDown,{sx:{fontSize:20}}):e.jsx(k.ChevronRight,{sx:{fontSize:20}})}),e.jsx(r.Chip,{label:Bs(c.feature),size:"small",sx:{height:24,fontSize:"0.6875rem",fontWeight:600,bgcolor:`${u}15`,color:u,border:`1px solid ${u}30`,"& .MuiChip-label":{px:1}}}),e.jsx(r.Typography,{variant:"body2",sx:{flex:1,fontWeight:400,fontSize:"0.875rem",color:"text.primary"},children:Ds(c.action)}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,flexShrink:0},children:[e.jsx(k.AccessTime,{sx:{fontSize:16,color:"text.secondary",opacity:.6}}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:As(c.timestamp)})]}),c.user&&e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:.75,flexShrink:0},children:[e.jsx(k.Person,{sx:{fontSize:16,color:"text.secondary",opacity:.6}}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:c.user})]})]}),e.jsx(r.Collapse,{in:d,timeout:200,children:e.jsxs(r.Box,{sx:{px:2.5,pb:2,pt:1.5,borderTop:"1px solid divider",bgcolor:"grey.50"},children:[c.previousState&&e.jsxs(r.Box,{sx:{mb:2},children:[e.jsx(r.Typography,{variant:"caption",sx:{fontWeight:600,fontSize:"0.6875rem",color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.1em",mb:1,display:"block"},children:"Previous state"}),e.jsx(r.Box,{component:"pre",sx:{fontSize:"0.75rem",fontFamily:'"Roboto Mono", "Courier New", monospace',bgcolor:"background.paper",border:"1px solid grey.300",borderRadius:"4px",p:1.5,overflow:"auto",maxHeight:200,color:"text.primary",lineHeight:1.6,"&::-webkit-scrollbar":{width:6,height:6},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:3}},children:rn(c.previousState)})]}),c.newState&&e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontWeight:600,fontSize:"0.6875rem",color:"text.secondary",textTransform:"uppercase",letterSpacing:"0.1em",mb:1,display:"block"},children:"New state"}),e.jsx(r.Box,{component:"pre",sx:{fontSize:"0.75rem",fontFamily:'"Roboto Mono", "Courier New", monospace',bgcolor:"background.paper",border:"1px solid grey.300",borderRadius:"4px",p:1.5,overflow:"auto",maxHeight:200,color:"text.primary",lineHeight:1.6,"&::-webkit-scrollbar":{width:6,height:6},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"grey.300",borderRadius:3}},children:rn(c.newState)})]})]})})]},c.id)})})})]})})}function Sd({onSave:t,onClose:o}){const[n,i]=p.useState(""),[a,l]=p.useState(""),[c,d]=p.useState(""),[u,f]=p.useState([]),[h,m]=p.useState(""),[v,w]=p.useState(""),z=I=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(I),y=()=>{const I=c.trim();if(I){if(!z(I)){w("Please enter a valid email address");return}if(u.includes(I)){w("This email is already added");return}f([...u,I]),d(""),w("")}},j=I=>{f(u.filter(A=>A!==I))},b=I=>{I.key==="Enter"&&(I.preventDefault(),y())},g=()=>{if(!n.trim()){m("Preset name is required");return}t(n.trim(),a.trim(),u.length>0?u:void 0)},S=I=>{i(I),h&&m("")},s=I=>{d(I),v&&w("")};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:I=>I.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:I=>`1px solid ${R(I.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:I=>S(I.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:a,onChange:I=>l(I.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:c,onChange:I=>s(I.target.value),onKeyPress:b,placeholder:"Enter email address",error:!!v,helperText:v,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(I=>e.jsx(r.Chip,{label:I,onDelete:()=>j(I),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"}}}},I))}),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:g,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 Cd({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=>R(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 jd({presets:t,reportId:o,onOpenPreset:n,onDeletePreset:i,onClose:a}){const[l,c]=p.useState(null),d=u=>new Date(u).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"});return e.jsx(r.Box,{onClick:a,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"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:a,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 ${d(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:a,variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"common.white",px:3,py:.875,minHeight:36,borderRadius:"4px",boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15)",transition:"all 0.2s ease","&:hover":{bgcolor:"primary.dark",boxShadow:"0 1px 3px 0 rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15)"},"&:active":{boxShadow:"0 1px 2px 0 rgba(60, 64, 67, 0.3)",transform:"translateY(1px)"}},children:"Close"})})]})})}function wd({totalRows:t,visibleRows:o,hasGrouping:n,visibleColumnsCount:i,totalColumnsCount:a,onExport:l,onClose:c}){const d=Rr(),[u,f]=p.useState(d.export.allowedFormats[0]||"csv"),[h,m]=p.useState("visible"),[v,w]=p.useState("visible"),z=t>5e4,y=h==="visible"?o:t,j=v==="visible"?i:a,b=()=>{l({format:u,scope:h,columnScope:v}),c()},g={csv:"CSV",excel:"Excel (.xlsx)",json:"JSON"};return e.jsx(r.Box,{onClick:c,sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(0, 0, 0, 0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1300,animation:"fadeIn 0.225s cubic-bezier(0.4, 0, 0.2, 1)","@keyframes fadeIn":{from:{opacity:0},to:{opacity:1}}},children:e.jsxs(r.Paper,{onClick:S=>S.stopPropagation(),elevation:0,sx:{position:"relative",width:480,maxWidth:"calc(100vw - 120px)",maxHeight:"min(620px, calc(100vh - 280px))",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,{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:"Export report"}),e.jsx(Ut,{content:Gt.export,isDev:process.env.NODE_ENV==="development"})]}),e.jsx(r.IconButton,{onClick:c,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.5,"&::-webkit-scrollbar":{width:8},"&::-webkit-scrollbar-track":{bgcolor:"transparent"},"&::-webkit-scrollbar-thumb":{bgcolor:"divider",borderRadius:4,"&:hover":{bgcolor:"#bdc1c6"}}},children:e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:2.5},children:[z&&e.jsxs(r.Alert,{severity:"warning",icon:e.jsx(k.Warning,{sx:{fontSize:20}}),sx:{borderRadius:"8px",border:"1px solid #fdd663",bgcolor:"#fef7e0","& .MuiAlert-icon":{color:"#ea8600"},"& .MuiAlertTitle-root":{fontSize:"0.875rem",fontWeight:500,color:"text.primary",mb:.5},"& .MuiAlert-message":{fontSize:"0.8125rem",color:"text.secondary"}},children:[e.jsx(r.AlertTitle,{children:"Large dataset warning"}),"This export contains over 50,000 rows. Processing may take a few moments."]}),e.jsxs(r.FormControl,{component:"fieldset",children:[e.jsx(r.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,textTransform:"uppercase"},children:"Format"}),e.jsxs(r.RadioGroup,{value:u,onChange:S=>f(S.target.value),children:[d.export.allowedFormats.includes("csv")&&e.jsx(r.FormControlLabel,{value:"csv",control:e.jsx(r.Radio,{size:"small",sx:{color:"text.secondary","&.Mui-checked":{color:"primary.main"}}}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"CSV"}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:"Comma-separated values, compatible with Excel"})]}),sx:{mb:1.25,alignItems:"flex-start",px:1.5,py:1,borderRadius:"8px",transition:"background-color 0.2s ease","&:hover":{bgcolor:"#f8f9fa"}}}),d.export.allowedFormats.includes("excel")&&e.jsx(r.FormControlLabel,{value:"excel",control:e.jsx(r.Radio,{size:"small",sx:{color:"text.secondary","&.Mui-checked":{color:"primary.main"}}}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Excel (.xlsx)"}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:"Native Excel format with formatting support"})]}),sx:{mb:1.25,alignItems:"flex-start",px:1.5,py:1,borderRadius:"8px",transition:"background-color 0.2s ease","&:hover":{bgcolor:"#f8f9fa"}}}),d.export.allowedFormats.includes("json")&&e.jsx(r.FormControlLabel,{value:"json",control:e.jsx(r.Radio,{size:"small",sx:{color:"text.secondary","&.Mui-checked":{color:"primary.main"}}}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"JSON"}),e.jsx(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:"Structured data with metadata and filters"})]}),sx:{alignItems:"flex-start",px:1.5,py:1,borderRadius:"8px",transition:"background-color 0.2s ease","&:hover":{bgcolor:"#f8f9fa"}}})]})]}),e.jsxs(r.FormControl,{component:"fieldset",children:[e.jsx(r.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,textTransform:"uppercase"},children:"Rows"}),e.jsxs(r.RadioGroup,{value:h,onChange:S=>m(S.target.value),children:[e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small",sx:{color:"text.secondary","&.Mui-checked":{color:"primary.main"}}}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Visible rows"}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export ",o.toLocaleString()," rows (filtered and searched)"]})]}),sx:{mb:1.25,alignItems:"flex-start",px:1.5,py:1,borderRadius:"8px",transition:"background-color 0.2s ease","&:hover":{bgcolor:"#f8f9fa"}}}),e.jsx(r.FormControlLabel,{value:"all",control:e.jsx(r.Radio,{size:"small",sx:{color:"text.secondary","&.Mui-checked":{color:"primary.main"}}}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"All rows"}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export ",t.toLocaleString()," rows (complete original dataset)"]})]}),sx:{alignItems:"flex-start",px:1.5,py:1,borderRadius:"8px",transition:"background-color 0.2s ease","&:hover":{bgcolor:"#f8f9fa"}}})]})]}),e.jsxs(r.FormControl,{component:"fieldset",children:[e.jsx(r.FormLabel,{component:"legend",sx:{fontSize:"0.6875rem",fontWeight:600,color:"text.secondary",letterSpacing:"0.1em",mb:1.5,textTransform:"uppercase"},children:"Columns"}),e.jsxs(r.RadioGroup,{value:v,onChange:S=>w(S.target.value),children:[e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small",sx:{color:"text.secondary","&.Mui-checked":{color:"primary.main"}}}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"Visible columns only"}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export ",i," visible columns"]})]}),sx:{mb:1.25,alignItems:"flex-start",px:1.5,py:1,borderRadius:"8px",transition:"background-color 0.2s ease","&:hover":{bgcolor:"#f8f9fa"}}}),e.jsx(r.FormControlLabel,{value:"all",control:e.jsx(r.Radio,{size:"small",sx:{color:"text.secondary","&.Mui-checked":{color:"primary.main"}}}),label:e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:"All columns"}),e.jsxs(r.Typography,{variant:"caption",sx:{fontSize:"0.75rem",color:"text.secondary"},children:["Export all ",a," columns (including hidden)"]})]}),sx:{alignItems:"flex-start",px:1.5,py:1,borderRadius:"8px",transition:"background-color 0.2s ease","&:hover":{bgcolor:"#f8f9fa"}}})]})]}),e.jsxs(r.Box,{sx:{pt:1},children:[e.jsx(r.Divider,{sx:{mb:2,borderColor:"divider"}}),e.jsxs(r.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:[e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary"},children:"Format:"}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:g[u]})]}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary"},children:"Rows to export:"}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:y.toLocaleString()})]}),e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.875rem",color:"text.secondary"},children:"Columns to export:"}),e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:500,fontSize:"0.875rem",color:"text.primary"},children:j})]})]})]})]})}),e.jsxs(r.Box,{sx:{px:3,py:2,borderTop:"1px solid divider",display:"flex",gap:1.5,justifyContent:"flex-end",flexShrink:0,bgcolor:"#f8f9fa"},children:[e.jsx(r.Button,{onClick:c,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.jsxs(r.Button,{onClick:b,variant:"contained",startIcon:e.jsx(k.Download,{sx:{fontSize:18}}),sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,bgcolor:"primary.main",color:"common.white",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:["Download ",g[u]]})]})]})})}function kd({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 Td({error:t,onDismiss:o,autoDismiss:n=!0,autoDismissDelay:i=5e3}){p.useEffect(()=>{if(n){const d=setTimeout(()=>{o()},i);return()=>clearTimeout(d)}},[n,i,o]);const l=(()=>{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}})}}})(),c=Gs(t);return e.jsx(r.Box,{sx:{position:"fixed",top:16,right:16,zIndex:50,maxWidth:448},children:e.jsxs(r.Alert,{severity:l.severity,icon:l.icon,action:e.jsx(r.IconButton,{size:"small",onClick:o,sx:{color:`${l.severity}.main`},children:e.jsx(k.Close,{sx:{fontSize:16}})}),sx:{borderLeft:4,borderColor:`${l.severity}.main`,boxShadow:3},children:[e.jsxs(r.AlertTitle,{sx:{fontWeight:600},children:[t.context.charAt(0).toUpperCase()+t.context.slice(1)," Error"]}),e.jsx(r.Box,{sx:{fontSize:"body2.fontSize"},children:c}),t.details&&process.env.NODE_ENV==="development"&&e.jsx(r.Box,{component:"pre",sx:{fontSize:"caption.fontSize",mt:1,fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:JSON.stringify(t.details,null,2)})]})})}class zd 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){Vt.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=>R(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=>R(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 Er({children:t,feature:o,onError:n}){return e.jsx(zd,{context:o,onError:(i,a)=>{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 Id=[{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"}],Ed=[{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 Dr({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 Dd({open:t,onClose:o,config:n,onApply:i}){const[a,l]=p.useState(0),[c,d]=p.useState(n),u=()=>d(n),f=()=>d(tt),h=()=>{i(c),o()},m={sort:j=>d(b=>({...b,sort:{...b.sort,...j}})),filter:j=>d(b=>({...b,filter:{...b.filter,...j}})),columns:j=>d(b=>({...b,columns:{...b.columns,...j}})),grouping:j=>d(b=>({...b,grouping:{...b.grouping,...j}})),export:j=>d(b=>({...b,export:{...b.export,...j}}))},v=j=>{const b=c.filter.allowedOperators,g=b.includes(j)?b.filter(S=>S!==j):[...b,j];g.length!==0&&m.filter({allowedOperators:g})},w=j=>{const b=c.export.allowedFormats,g=b.includes(j)?b.filter(S=>S!==j):[...b,j];g.length!==0&&m.export({allowedFormats:g})},z=[{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=j=>JSON.stringify(c[j])===JSON.stringify(tt[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=>R(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(k.Close,{sx:{fontSize:20}})})]}),e.jsx(r.Box,{sx:{borderBottom:"1px solid",borderColor:"divider",flexShrink:0},children:e.jsx(r.Tabs,{value:a,onChange:(j,b)=>l(b),variant:"fullWidth",sx:{minHeight:44,"& .MuiTab-root":{minHeight:44,fontSize:"0.8125rem",textTransform:"none",fontWeight:500,gap:.5}},children:z.map((j,b)=>e.jsx(r.Tab,{label:j.label,icon:j.icon,iconPosition:"start"},b))})}),e.jsxs(r.DialogContent,{sx:{overflowY:"auto",flex:1,px:3,py:0},children:[e.jsxs(Dr,{active:a===0,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum sort levels"}),!y("sort")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users can sort by at most this many columns simultaneously."}),e.jsx(r.Slider,{value:c.sort.maxLevels,onChange:(j,b)=>m.sort({maxLevels:b}),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(Dr,{active:a===1,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum filter conditions"}),!y("filter")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users can apply at most this many simultaneous filter conditions."}),e.jsx(r.Slider,{value:c.filter.maxConditions,onChange:(j,b)=>m.filter({maxConditions:b}),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:Id.filter(b=>b.group===j).map(b=>e.jsx(r.FormControlLabel,{control:e.jsx(r.Checkbox,{size:"small",checked:c.filter.allowedOperators.includes(b.value),onChange:()=>v(b.value)}),label:e.jsx(r.Typography,{variant:"body2",sx:{fontSize:"0.8125rem"},children:b.label}),sx:{mr:1.5}},b.value))})]},j))]})]}),e.jsxs(Dr,{active:a===2,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum visible columns"}),!y("columns")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users cannot make more than this many columns visible simultaneously."}),e.jsx(r.Slider,{value:c.columns.maxVisible,onChange:(j,b)=>m.columns({maxVisible:b}),min:1,max:50,step:1,valueLabelDisplay:"on"})]}),e.jsx(r.Divider,{}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,mb:.5},children:"Column width range (px)"}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:2},children:"Users cannot resize columns outside this minimum / maximum range."}),e.jsxs(r.Box,{sx:{display:"flex",gap:2},children:[e.jsxs(r.Box,{sx:{flex:1},children:[e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:.5},children:"Minimum width"}),e.jsx(r.Slider,{value:c.columns.minColumnWidth,onChange:(j,b)=>m.columns({minColumnWidth:b}),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:c.columns.maxColumnWidth,onChange:(j,b)=>m.columns({maxColumnWidth:b}),min:100,max:2e3,step:50,valueLabelDisplay:"on",valueLabelFormat:j=>`${j}px`})]})]})]})]}),e.jsxs(Dr,{active:a===3,children:[e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Maximum group levels"}),!y("grouping")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Box,{sx:{display:"flex",gap:1.5,mb:2},children:[1,2,3].map(j=>e.jsxs(r.Box,{onClick:()=>m.grouping({maxLevels:j}),sx:{flex:1,py:2.5,borderRadius:"10px",border:"2px solid",cursor:"pointer",textAlign:"center",transition:"all 0.15s ease",borderColor:c.grouping.maxLevels===j?"primary.main":"divider",bgcolor:c.grouping.maxLevels===j?b=>R(b.palette.primary.main,.06):"transparent","&:hover":{borderColor:"primary.light",bgcolor:b=>R(b.palette.primary.main,.04)}},children:[e.jsx(r.Typography,{variant:"h5",sx:{fontWeight:700,color:c.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:c.grouping.allowNested,onChange:j=>m.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:c.grouping.allowCollapse,onChange:j=>m.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(Dr,{active:a===4,children:e.jsxs(r.Box,{children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600},children:"Allowed export formats"}),!y("export")&&e.jsx(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:600},children:"Modified"})]}),e.jsx(r.Typography,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1.5},children:"Only checked formats appear in the Export dialog and the bulk export action. At least one must remain checked."}),e.jsx(r.FormGroup,{sx:{gap:1},children:Ed.map(j=>e.jsxs(r.Box,{onClick:()=>w(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:c.export.allowedFormats.includes(j.value)?"primary.main":"divider",bgcolor:c.export.allowedFormats.includes(j.value)?b=>R(b.palette.primary.main,.04):"transparent","&:hover":{borderColor:"primary.light"}},children:[e.jsx(r.Checkbox,{size:"small",checked:c.export.allowedFormats.includes(j.value),onChange:()=>w(j.value),onClick:b=>b.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=>R(j.palette.action.hover,.4),justifyContent:"space-between",flexShrink:0},children:[e.jsx(r.Button,{startIcon:e.jsx(k.RestartAlt,{sx:{fontSize:18}}),onClick:f,size:"small",sx:{textTransform:"none",fontSize:"0.875rem",color:"text.secondary","&:hover":{color:"text.primary",bgcolor:j=>R(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:h,size:"small",variant:"contained",sx:{textTransform:"none",fontSize:"0.875rem",fontWeight:500,px:2.5,borderRadius:"18px"},children:"Apply"})]})]})]})}const Bd=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Od={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 Xr(t,o,n,i,a=new Date){const[l,c]=o.split(":").map(Number),d=new Date(a);if(d.setSeconds(0,0),d.setHours(l,c,0,0),t==="daily")return d<=a&&d.setDate(d.getDate()+1),d.toISOString();if(t==="weekly"){const u=n??1,f=d.getDay();let h=u-f;return h<0&&(h+=7),h===0&&d<=a&&(h=7),d.setDate(d.getDate()+h),d.toISOString()}if(t==="monthly"){const u=Math.min(i??1,28);return d.setDate(u),d<=a&&(d.setMonth(d.getMonth()+1),d.setDate(u)),d.toISOString()}return d.toISOString()}function Ad(t){const o=Ci(t.time);return t.frequency==="daily"?`Daily at ${o}`:t.frequency==="weekly"?`Every ${Bd[t.dayOfWeek??1]} at ${o}`:t.frequency==="monthly"?`Monthly on the ${Od[t.dayOfMonth??1]??`${t.dayOfMonth}th`} at ${o}`:o}function Ci(t){const[o,n]=t.split(":").map(Number),i=o>=12?"PM":"AM";return`${o%12||12}:${String(n).padStart(2,"0")} ${i}`}function Md(t){const o=new Date(t).getTime()-Date.now();if(o<=0)return"now";const n=Math.floor(o/1e3),i=Math.floor(n/86400),a=Math.floor(n%86400/3600),l=Math.floor(n%3600/60);return i>0?`in ${i}d ${a}h`:a>0?`in ${a}h ${l}m`:l>0?`in ${l}m`:"in less than a minute"}function Wd(t){const o=new Date(t),n=new Date,i=o.toDateString()===n.toDateString(),a=Ci(`${String(o.getHours()).padStart(2,"0")}:${String(o.getMinutes()).padStart(2,"0")}`);return i?`Today at ${a}`:`${o.toLocaleDateString("en-US",{month:"short",day:"numeric"})} at ${a}`}function ji(t){return`urm_schedules_${t}`}function wi(t){try{const o=localStorage.getItem(ji(t));return o?JSON.parse(o).map(i=>({...i,runCount:typeof i.runCount=="number"?i.runCount:0,isActive:typeof i.isActive=="boolean"?i.isActive:!0,createdAt:i.createdAt||new Date().toISOString()})):[]}catch{return[]}}function ki(t,o){try{localStorage.setItem(ji(t),JSON.stringify(o))}catch{}}const Rd=[{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"}],Ti={name:"",frequency:"daily",dayOfWeek:1,dayOfMonth:1,time:"09:00",format:"csv",scope:"all",email:""},Lt={"& .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 _d({initial:t=Ti,isEditing:o=!1,onSave:n,onBack:i}){const[a,l]=p.useState(t),[c,d]=p.useState(!1),u=(h,m)=>l(v=>({...v,[h]:m})),f=a.name.trim().length>0&&/^\d{2}:\d{2}$/.test(a.time)&&(a.frequency!=="monthly"||a.dayOfMonth>=1&&a.dayOfMonth<=28);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:h=>R(h.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:a.name,onChange:h=>{u("name",h.target.value),c&&h.target.value.trim()&&d(!1)},onBlur:()=>d(!0),placeholder:"e.g. Weekly Sales Report",autoFocus:!0,inputProps:{maxLength:50},error:c&&!a.name.trim(),helperText:c&&!a.name.trim()?"Schedule name is required":`${a.name.length}/50`,sx:Lt}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:Lt,children:[e.jsx(r.InputLabel,{children:"Frequency"}),e.jsxs(r.Select,{value:a.frequency,label:"Frequency",onChange:h=>u("frequency",h.target.value),children:[e.jsx(r.MenuItem,{value:"daily",children:"Daily"}),e.jsx(r.MenuItem,{value:"weekly",children:"Weekly"}),e.jsx(r.MenuItem,{value:"monthly",children:"Monthly"})]})]}),a.frequency==="weekly"&&e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:Lt,children:[e.jsx(r.InputLabel,{children:"Day of week"}),e.jsx(r.Select,{value:a.dayOfWeek,label:"Day of week",onChange:h=>u("dayOfWeek",Number(h.target.value)),children:Rd.map(h=>e.jsx(r.MenuItem,{value:h.value,children:h.label},h.value))})]}),a.frequency==="monthly"&&e.jsx(r.TextField,{label:"Day of month (1–28)",size:"small",type:"number",fullWidth:!0,value:a.dayOfMonth,onChange:h=>{const m=Number(h.target.value);u("dayOfMonth",m)},inputProps:{min:1,max:28},error:a.dayOfMonth<1||a.dayOfMonth>28,helperText:a.dayOfMonth<1||a.dayOfMonth>28?"Day must be between 1 and 28":"Max 28 — works safely across all months including February",sx:Lt}),e.jsx(r.TextField,{label:"Time",size:"small",type:"time",fullWidth:!0,value:a.time,onChange:h=>u("time",h.target.value),InputLabelProps:{shrink:!0},helperText:"24-hour format · Tab must be open for the schedule to fire",sx:Lt}),e.jsxs(r.FormControl,{size:"small",fullWidth:!0,sx:Lt,children:[e.jsx(r.InputLabel,{children:"Export format"}),e.jsxs(r.Select,{value:a.format,label:"Export format",onChange:h=>u("format",h.target.value),children:[e.jsx(r.MenuItem,{value:"csv",children:"CSV — Comma-separated values"}),e.jsx(r.MenuItem,{value:"excel",children:"Excel (.xlsx) — Native format"}),e.jsx(r.MenuItem,{value:"json",children:"JSON — Structured data"})]})]}),e.jsxs(r.Box,{children:[e.jsx(r.Typography,{variant:"caption",sx:{fontWeight:500,color:"text.secondary",display:"block",mb:.75},children:"Data scope"}),e.jsxs(r.RadioGroup,{row:!0,value:a.scope,onChange:h=>u("scope",h.target.value),sx:{gap:2},children:[e.jsx(r.FormControlLabel,{value:"all",control:e.jsx(r.Radio,{size:"small"}),label:e.jsx(r.Typography,{variant:"body2",children:"All rows"})}),e.jsx(r.FormControlLabel,{value:"visible",control:e.jsx(r.Radio,{size:"small"}),label:e.jsx(r.Typography,{variant:"body2",children:"Filtered rows only"})})]})]}),e.jsxs(r.Box,{children:[e.jsx(r.TextField,{label:"Email reminder (optional)",size:"small",fullWidth:!0,type:"email",value:a.email,onChange:h=>u("email",h.target.value),placeholder:"user@company.com",InputProps:{startAdornment:e.jsx(k.Email,{sx:{fontSize:15,color:"text.disabled",mr:1}})},sx:Lt}),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:h=>R(h.palette.text.primary,.06)}},children:"Cancel"}),e.jsx(r.Button,{onClick:()=>f&&n(a),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 Pd({schedule:t,onToggle:o,onRunNow:n,onEdit:i,onDelete:a}){const l=t.isActive;return e.jsxs(r.Box,{sx:{border:"1px solid",borderColor:l?"primary.main":"divider",borderRadius:"10px",p:1.75,bgcolor:l?c=>R(c.palette.primary.main,.025):"background.paper",transition:"border-color 0.15s ease, background-color 0.15s ease"},children:[e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[e.jsx(r.Typography,{variant:"body2",sx:{fontWeight:600,flex:1,minWidth:0,color:l?"text.primary":"text.secondary",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.name}),e.jsx(r.Chip,{label:l?"Active":"Paused",size:"small",sx:{height:18,fontSize:"0.6875rem",fontWeight:600,flexShrink:0,bgcolor:l?c=>R(c.palette.success.main,.1):c=>R(c.palette.text.primary,.06),color:l?"success.dark":"text.secondary"}})]}),e.jsx(r.Typography,{variant:"caption",sx:{color:"text.secondary",display:"block",mb:1},children:Ad(t)}),e.jsxs(r.Box,{sx:{display:"flex",flexWrap:"wrap",gap:.5,mb:1},children:[e.jsx(r.Chip,{label:t.format.toUpperCase(),size:"small",sx:{height:20,fontSize:"0.6875rem",fontWeight:500,bgcolor:c=>R(c.palette.primary.main,.08),color:"primary.main"}}),e.jsx(r.Chip,{label:t.scope==="all"?"All rows":"Filtered rows",size:"small",sx:{height:20,fontSize:"0.6875rem",bgcolor:c=>R(c.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:c=>R(c.palette.text.primary,.06),color:"text.secondary","& .MuiChip-label":{overflow:"hidden",textOverflow:"ellipsis"}}})]}),e.jsxs(r.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:1},children:[e.jsxs(r.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1.5,alignItems:"center"},children:[l&&e.jsxs(r.Typography,{variant:"caption",sx:{color:"primary.main",fontWeight:500},children:["Next: ",Md(t.nextRunAt)]}),t.lastRunAt?e.jsxs(r.Typography,{variant:"caption",color:"text.secondary",children:["Last: ",Wd(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:()=>i(t),sx:{color:"text.secondary","&:hover":{color:"primary.main",bgcolor:c=>R(c.palette.primary.main,.08)}},children:e.jsx(k.Edit,{sx:{fontSize:15}})})}),e.jsx(r.Tooltip,{title:l?"Pause":"Resume",placement:"top",children:e.jsx(r.IconButton,{size:"small",onClick:()=>o(t.id),sx:{color:l?"warning.main":"success.main","&:hover":{bgcolor:l?c=>R(c.palette.warning.main,.08):c=>R(c.palette.success.main,.08)}},children:l?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:()=>n(t),sx:{color:"primary.main","&:hover":{bgcolor:c=>R(c.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:()=>a(t.id),sx:{color:"error.main","&:hover":{bgcolor:c=>R(c.palette.error.main,.08)}},children:e.jsx(k.Delete,{sx:{fontSize:15}})})})]})]})]})}function $d({open:t,onClose:o,reportId:n,reportName:i,onRunNow:a}){const[l,c]=p.useState([]),[d,u]=p.useState({type:"list"}),[f,h]=p.useState(0);p.useEffect(()=>{t&&(c(wi(n)),u({type:"list"}))},[t,n]),p.useEffect(()=>{if(!t)return;const S=setInterval(()=>h(s=>s+1),3e4);return()=>clearInterval(S)},[t]);const m=p.useCallback(S=>{c(S),ki(n,S)},[n]),v=S=>{const s=Xr(S.frequency,S.time,S.dayOfWeek,S.dayOfMonth),I={id:`sched-${Date.now()}`,reportId:n,name:S.name.trim(),frequency:S.frequency,dayOfWeek:S.frequency==="weekly"?S.dayOfWeek:void 0,dayOfMonth:S.frequency==="monthly"?S.dayOfMonth:void 0,time:S.time,format:S.format,scope:S.scope,email:S.email.trim()||void 0,isActive:!0,createdAt:new Date().toISOString(),nextRunAt:s,runCount:0};m([...l,I]),u({type:"list"})},w=S=>{if(d.type!=="edit")return;const s=d.schedule,I=Xr(S.frequency,S.time,S.dayOfWeek,S.dayOfMonth);m(l.map(A=>A.id===s.id?{...s,name:S.name.trim(),frequency:S.frequency,dayOfWeek:S.frequency==="weekly"?S.dayOfWeek:void 0,dayOfMonth:S.frequency==="monthly"?S.dayOfMonth:void 0,time:S.time,format:S.format,scope:S.scope,email:S.email.trim()||void 0,nextRunAt:I}:A)),u({type:"list"})},z=S=>{m(l.map(s=>{if(s.id!==S)return s;const I=s.isActive?s.nextRunAt:Xr(s.frequency,s.time,s.dayOfWeek,s.dayOfMonth);return{...s,isActive:!s.isActive,nextRunAt:I}}))},y=S=>m(l.filter(s=>s.id!==S)),j=S=>({name:S.name,frequency:S.frequency,dayOfWeek:S.dayOfWeek??1,dayOfMonth:S.dayOfMonth??1,time:S.time,format:S.format,scope:S.scope,email:S.email??""}),b=d.type!=="list",g=l.filter(S=>S.isActive).length;return e.jsxs(r.Dialog,{open:t,onClose:o,maxWidth:"sm",fullWidth:!0,disableEscapeKeyDown:b,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:S=>R(S.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(Ut,{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:S=>R(S.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:[b&&e.jsx(_d,{initial:d.type==="edit"?j(d.schedule):Ti,isEditing:d.type==="edit",onSave:d.type==="edit"?w:v,onBack:()=>u({type:"list"})}),d.type==="list"&&e.jsxs(e.Fragment,{children:[e.jsxs(r.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1.75,pt:1.5},children:[e.jsx(r.Typography,{variant:"body2",color:"text.secondary",children:l.length===0?"No schedules yet":`${g} of ${l.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"})]}),l.length===0?e.jsxs(r.Box,{sx:{border:"1.5px dashed",borderColor:"divider",borderRadius:"10px",py:5,px:2,textAlign:"center"},children:[e.jsx(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:l.map(S=>e.jsx(Pd,{schedule:S,tick:f,onToggle:z,onRunNow:a,onEdit:s=>u({type:"edit",schedule:s}),onDelete:y},S.id))})]})]}),d.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:S=>R(S.palette.warning.main,.06),border:"1px solid",borderColor:S=>R(S.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:S=>R(S.palette.text.primary,.06)}},children:"Close"})]})]})}const Nd=6e4;function Fd({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:a,activeView:l,columnVisibility:c,columnOrder:d,filters:u,sortStack:f,onFired:h}){const m=p.useRef({reportId:t,reportName:o,uploadedData:n,processedData:i,schema:a,activeView:l,columnVisibility:c,columnOrder:d,filters:u,sortStack:f,onFired:h});p.useEffect(()=>{m.current={reportId:t,reportName:o,uploadedData:n,processedData:i,schema:a,activeView:l,columnVisibility:c,columnOrder:d,filters:u,sortStack:f,onFired:h}});const v=p.useCallback(w=>{var H,N;const{reportName:z,uploadedData:y,processedData:j,schema:b,activeView:g,columnVisibility:S,columnOrder:s,filters:I,sortStack:A}=m.current;try{const K=w.scope==="all"?y:j,te=Qr(K,b,I,A,g,S,s),se=`${w.name}_scheduled`;switch(w.format){case"csv":Zr(te,se,{scope:w.scope});break;case"excel":eo(te,se,{scope:w.scope});break;case"json":to(te,se,{scope:w.scope});break}if(w.email){const x=encodeURIComponent(`Scheduled Report: ${w.name}`),V=encodeURIComponent(`Your scheduled report "${w.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 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.
|
|
90
90
|
|
|
91
91
|
Report: ${z}
|
|
92
|
-
Format: ${
|
|
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:${w.email}?subject=${x}&body=${V}`,"_blank")}(N=(H=m.current).onFired)==null||N.call(H,w)}catch(K){Vt.error("urm:scheduler",`Export failed for schedule: ${w.name}`,K)}},[]);p.useEffect(()=>{if(!t)return;const w=()=>{const{reportId:y}=m.current;if(!y)return;const j=wi(y),b=new Date;let g=!1;const S=j.map(s=>{if(!s.isActive)return s;if(new Date(s.nextRunAt)<=b){v(s);const A=Xr(s.frequency,s.time,s.dayOfWeek,s.dayOfMonth,b);return g=!0,{...s,lastRunAt:b.toISOString(),nextRunAt:A,runCount:s.runCount+1}}return s});g&&ki(y,S)};w();const z=setInterval(w,Nd);return()=>clearInterval(z)},[t,v])}function zi({reportEngine:t}){var G,de,We,le;const{activeReport:o,paginatedData:n,processedData:i,displayData:a,tableMetrics:l,tableEngine:c,activeView:d,isDirty:u,currentTableState:f,viewChanges:h,showFilterPanel:m,setShowFilterPanel:v,filterFocusColumn:w,handleAddFilter:z,handleUpdateFilter:y,handleRemoveFilter:j,handleClearAllFilters:b,handleOpenFilterForColumn:g,handleCloseFilterPanel:S,handleClearFiltersForColumn:s,showSortPanel:I,setShowSortPanel:A,handleSort:H,handleUpdateSortStack:N,handleSortAscending:K,handleSortDescending:te,showManageViews:se,setShowManageViews:x,showCreateViewModal:V,setShowCreateViewModal:$,showEditViewModal:J,setShowEditViewModal:oe,showDeleteConfirmation:ue,setShowDeleteConfirmation:pe,editingView:_,deletingView:O,handleSelectView:L,handleCreateView:re,handleUpdateCurrentView:Q,handleSaveColumnConfigToCurrentView:X,handleSaveColumnConfigToAllViews:ae,handleSaveAsNewView:Z,handleRevertChanges:W,handleToggleDefault:ee,handleToggleFavorite:ie,handleSoftDelete:ne,handleRestoreView:ke,handlePermanentDelete:U,handleEditView:Oe,handleSaveEditView:Le,handleConfirmDelete:dt,showManageColumns:$r,setShowManageColumns:Re,handleUpdateColumnVisibility:jt,handleUpdateColumnOrder:Ae,handleUpdateColumnWidth:Ge,handleResetColumnLayout:Ke,showGroupPanel:Xe,setShowGroupPanel:_e,handleGroup:wt,handleToggleGroupCollapse:Yt,searchQuery:rt,searchHistory:Qe,handleSearchChange:$e,handleAddToSearchHistory:dr,handleToggleSearchFavourite:qt,handleDeleteSearchHistory:ot,selectedRowIds:kt,handleToggleRowSelection:At,handleToggleAllRows:ut,handleRangeSelection:ur,handleClearSelection:Nr,handleUpdateSelectionAfterDelete:Mt,currentPage:pr,pageSize:Wt,paginationEngine:Ze,handlePageChange:Tt,handlePageSizeChange:je,isExporting:xr,showExportModal:zt,setShowExportModal:nt,showDirtyExportWarning:P,handleExport:et,handleExportWithConfig:ge,handleExportSelected:Pe,handleExportAnyway:Rt,handleSaveAndExport:fr,handleCancelExport:pt,showAuditHistory:hr,setShowAuditHistory:Ye,showCreatePreset:Jt,setShowCreatePreset:_t,showManagePresets:Kt,setShowManagePresets:Te,generatedPreset:F,activePreset:Me,handleOpenManagePresets:Ce,handleCreatePreset:it,handleCopyPresetLink:Ne,handleOpenPreset:mr,handleClearActivePreset:gr,handleOpenPresetById:Xt,handleCopyPresetLinkById:yr,handleDeletePresetById:br,isViewerRole:Qt,userRole:Zt,featureLimitWarning:Ve,setFeatureLimitWarning:st,reportError:Pt,setReportError:It,handleError:xt,updateReport:at,showSnack:$t,favoriteRowIndices:Nt,resolvedFavoritesSet:vr,showFavoritesOnly:Sr,handleToggleRowFavorite:Cr,handleBulkSetFavorites:jr,handleToggleFavoritesFilter:er}=t,[wr,Be]=p.useState(!1);Fd({reportId:o==null?void 0:o.id,reportName:(o==null?void 0:o.name)||"Report",uploadedData:(o==null?void 0:o.uploadedData)||[],processedData:i||[],schema:(o==null?void 0:o.schema)||[],activeView:d,columnVisibility:(o==null?void 0:o.columnVisibility)||((G=d==null?void 0:d.snapshot)==null?void 0:G.columnVisibility)||{},columnOrder:(o==null?void 0:o.columnOrder)||((de=d==null?void 0:d.snapshot)==null?void 0:de.columnOrder)||[],filters:(o==null?void 0:o.filters)||[],sortStack:(o==null?void 0:o.sortStack)||[],onFired:ce=>{$t(`Scheduled export "${ce.name}" completed`,"success")}});const ft=p.useCallback((ce,Se)=>{if(!(o!=null&&o.uploadedData))return;const Fe=[...o.uploadedData];Fe[ce]=Se,at(o.id,{uploadedData:Fe})},[o,at]),tr=p.useCallback(ce=>{if(!(o!=null&&o.uploadedData))return;const Se=o.uploadedData.indexOf(ce);if(Se===-1)return;const Fe=o.uploadedData.filter((Et,Co)=>Co!==Se),So=(o.favoriteRowIndices||[]).filter(Et=>Et!==Se).map(Et=>Et>Se?Et-1:Et);at(o.id,{uploadedData:Fe,favoriteRowIndices:So}),Mt(ce)},[o,at,Mt]),Fr=p.useCallback((ce,Se)=>{if(!(o!=null&&o.uploadedData))return;const Fe=[...o.uploadedData];Fe.splice(ce+1,0,{...Se}),at(o.id,{uploadedData:Fe})},[o,at]),ht=Rr(),{handleDevConfigChange:kr}=io(),[rr,D]=p.useState(!1);return p.useEffect(()=>{const ce=Se=>{Se.ctrlKey&&Se.shiftKey&&Se.key==="D"&&(Se.preventDefault(),D(!0))};return document.addEventListener("keydown",ce),()=>document.removeEventListener("keydown",ce)},[]),!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:[!Qt&&u&&d&&e.jsx(yd,{viewName:d.name,isDefaultView:d.isDefault,changes:h,onSaveToCurrentView:d.isDefault?void 0:Q,onSaveAsNewView:Z,onCancel:W}),e.jsxs(r.Box,{id:"table-content-area",sx:{flex:1,minHeight:0,overflow:"hidden",display:"flex",flexDirection:"column",position:"relative"},children:[Ve&&e.jsx(kd,{warning:Ve,onDismiss:()=>st(null)}),Pt&&e.jsx(Td,{error:Pt,onDismiss:()=>It(null)}),P&&e.jsx(bd,{onExportAnyway:Rt,onSaveAndExport:fr,onCancel:pt}),e.jsx(ad,{schema:o.schema,data:n,sortStack:o.sortStack,filters:o.filters,views:o.views,activeViewId:o.activeViewId,isDirty:u,isExporting:xr,columnVisibility:o.columnVisibility||(d==null?void 0:d.snapshot.columnVisibility),columnOrder:o.columnOrder||(d==null?void 0:d.snapshot.columnOrder),columnWidths:o.columnWidths||(d==null?void 0:d.snapshot.columnWidths),grouping:o.grouping,onSort:H,onSortAscending:K,onSortDescending:te,onOpenFilters:()=>v(!0),onOpenSort:()=>A(!0),onOpenFilterForColumn:g,onSelectView:L,onCreateView:()=>$(!0),onManageViews:()=>x(!0),onUpdateCurrentView:Q,onSaveAsNewView:Z,onToggleDefault:ee,onToggleFavorite:ie,onRestoreView:ke,onPermanentDelete:U,onExport:et,onOpenColumns:()=>Re(!0),onUpdateColumnWidth:Ge,onUpdateColumnOrder:Ae,onUpdateColumnVisibility:jt,onClearFiltersForColumn:s,onResetLayout:Ke,onOpenGroup:()=>_e(!0),onToggleGroupCollapse:Yt,onOpenAuditHistory:()=>Ye(!0),onOpenScheduledReports:()=>Be(!0),searchQuery:rt,searchHistory:Qe,onAddToSearchHistory:dr,onToggleSearchFavourite:qt,onDeleteSearchHistory:ot,selectedRowIds:kt,onSearchChange:$e,onToggleRowSelection:At,onToggleAllRows:ut,onRangeSelection:ur,onClearSelection:Nr,onExportSelected:Pe,currentPage:(Ze==null?void 0:Ze.currentPage)||pr,pageSize:(Ze==null?void 0:Ze.pageSize)||Wt,onPageChange:Tt,onPageSizeChange:je,totalRowsBeforePagination:(l==null?void 0:l.searchedRows)||i.length,isReadOnly:Qt,userRole:Zt,reportName:o.name,onEditRow:ft,onDeleteRow:tr,onDuplicateRow:Fr,favoriteRowIndices:Nt,resolvedFavoritesSet:vr,showFavoritesOnly:Sr,onToggleRowFavorite:Cr,onBulkSetFavorites:jr,onToggleFavoritesFilter:er,showDevPanel:ht.display.showDevPanel,onOpenDevConfig:()=>D(!0)})]}),m&&e.jsx(Er,{feature:"Filters",onError:ce=>{const Se=vt("ui","filters",ce);xt(Se)},children:e.jsx(ld,{schema:o.schema,filters:o.filters??[],onAddFilter:z,onUpdateFilter:y,onRemoveFilter:j,onClearAll:b,onClose:S,focusColumn:w})}),I&&e.jsx(Er,{feature:"Sorting",onError:ce=>{const Se=vt("ui","sorting",ce);xt(Se)},children:e.jsx(dd,{schema:o.schema,sortStack:o.sortStack??[],onUpdateSortStack:N,onClose:()=>A(!1)})}),se&&e.jsx(Er,{feature:"Views",onError:ce=>{const Se=vt("ui","views",ce);xt(Se)},children:e.jsx(ud,{views:o.views,activeViewId:o.activeViewId??"",onSelectView:L,onCreateView:()=>{x(!1),$(!0)},onEditView:Oe,onDeleteView:ne,onRestoreView:ke,onPermanentDelete:U,onClose:()=>x(!1)})}),V&&f&&e.jsx($n,{currentSnapshot:f,onSave:re,onClose:()=>$(!1)}),J&&_&&e.jsx($n,{currentSnapshot:_.snapshot,onSave:Le,onClose:()=>{oe(!1)},isEditMode:!0,initialName:_.name,initialDescription:_.description,initialIsDefault:_.isDefault}),ue&&O&&e.jsx(pd,{viewName:O.name,onConfirm:dt,onCancel:()=>{pe(!1)}}),$r&&d&&e.jsx(fd,{schema:o.schema,columnVisibility:o.columnVisibility||d.snapshot.columnVisibility,columnOrder:o.columnOrder||d.snapshot.columnOrder,columnWidths:o.columnWidths||d.snapshot.columnWidths,views:o.views,activeViewId:o.activeViewId,onUpdateColumnVisibility:jt,onUpdateColumnOrder:Ae,onUpdateColumnWidth:Ge,onResetLayout:Ke,onSelectView:ce=>{L(ce)},onSaveToCurrentView:ce=>{X(ce),Re(!1)},onSaveToAllViews:ce=>{ae(ce),Re(!1)},onClose:()=>Re(!1)}),Xe&&e.jsx(Er,{feature:"Grouping",onError:ce=>{const Se=vt("ui","grouping",ce);xt(Se)},children:e.jsx(hd,{schema:o.schema,grouping:o.grouping||null,onApply:wt,onClose:()=>_e(!1)})}),hr&&e.jsx(vd,{auditHistory:o.auditHistory||[],onClose:()=>Ye(!1)}),Jt&&e.jsx(Sd,{onSave:it,onClose:()=>_t(!1)}),Kt&&e.jsx(jd,{presets:o.presets||[],reportId:o.id,onOpenPreset:Xt,onCopyLink:yr,onDeletePreset:br,onClose:()=>Te(!1)}),Me&&e.jsx(r.Box,{sx:{mt:2},children:e.jsx(Cd,{presetName:Me.name,onClear:gr})}),zt&&e.jsx(Er,{feature:"Export",onError:ce=>{const Se=vt("ui","export",ce);xt(Se)},children:e.jsx(wd,{totalRows:(l==null?void 0:l.totalRows)||((We=o.uploadedData)==null?void 0:We.length)||0,visibleRows:(l==null?void 0:l.searchedRows)||i.length,visibleColumnsCount:((le=c==null?void 0:c.columnEngine)==null?void 0:le.visibleColumns.length)||o.schema.length,totalColumnsCount:o.schema.length,hasGrouping:(l==null?void 0:l.isGrouped)||!1,onExport:ge,onClose:()=>{nt(!1)}})}),o&&e.jsx($d,{open:wr,onClose:()=>Be(!1),reportId:o.id,reportName:o.name,onRunNow:ce=>{const Se=ce.scope==="all"?o.uploadedData||[]:i||[],Fe=Qr(Se,o.schema||[],o.filters||[],o.sortStack||[],d,o.columnVisibility,o.columnOrder);ce.format==="csv"&&Zr(Fe,ce.name),ce.format==="excel"&&eo(Fe,ce.name),ce.format==="json"&&to(Fe,ce.name),$t(`"${ce.name}" exported successfully`,"success")}}),e.jsx(Dd,{open:rr,onClose:()=>D(!1),config:ht,onApply:kr})]})}function Ii({open:t,message:o,severity:n,onClose:i}){return e.jsx(r.Snackbar,{open:t,autoHideDuration:2e3,onClose:(a,l)=>{l!=="escapeKeyDown"&&i()},anchorOrigin:{vertical:"top",horizontal:"right"},children:e.jsx(r.Alert,{severity:n,variant:"filled",sx:{width:"100%",boxShadow:3},children:o})})}function Ei({hasExternalData:t=!1}){const o=io(),{reports:n,activeReportId:i,activeReport:a,uploadState:l,schema:c,hasSchemaConflicts:d,isModalOpen:u,setIsModalOpen:f,setActiveReportId:h,createReport:m,handleFileUpload:v,handleUploadError:w,handleRetry:z,handleConfirm:y,snack:j,handleSnackClose:b}=o,g=t&&l==="uploading"&&n.length===0;return e.jsxs(r.Box,{sx:{height:"100%",display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsx(ma,{onCreateReport:()=>f(!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:g?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."}):a?e.jsx(e.Fragment,{children:a.schemaLocked&&a.schema&&a.uploadedData&&a.views?e.jsx(zi,{reportEngine:o}):e.jsx(r.Box,{sx:{p:3},children:l==="preview"&&a.schema&&a.uploadedData?e.jsx(Ic,{schema:a.schema,onConfirm:y,hasConflicts:d}):a.uploadError?e.jsx(Ec,{error:a.uploadError,onRetry:z}):e.jsx(zc,{onFileUpload:v,onError:w,isUploading:l==="uploading"})})}):null}),!t&&e.jsx(Tc,{isOpen:u,onClose:()=>f(!1),onCreate:m}),e.jsx(Ii,{open:j.open,message:j.message,severity:j.severity,onClose:b})]})}function Ld({data:t,dataSource:o,reportName:n,autoLoad:i=!0,config:a}={}){return e.jsx(No,{mode:"builder",data:t,dataSource:o,reportName:n,autoLoad:i,config:a,children:e.jsx(Ei,{hasExternalData:!!(t||o)})})}function Di(){const t=io(),{snack:o,handleSnackClose:n}=t;return e.jsxs(r.Box,{sx:{minHeight:"100vh"},children:[e.jsx(r.Box,{component:"main",children:t.activeReport?e.jsx(zi,{reportEngine:t}):e.jsx(vi,{title:"No report data",description:"This viewer requires report data to be loaded."})}),e.jsx(Ii,{open:o.open,message:o.message,severity:o.severity,onClose:n})]})}function Vd({data:t,autoLoad:o=!0,config:n}){return e.jsx(No,{data:t,mode:"viewer",autoLoad:o,config:n,children:e.jsx(Di,{})})}exports.URMBuilder=Ld;exports.URMBuilderRaw=Ei;exports.URMProvider=No;exports.URMViewer=Vd;exports.URMViewerRaw=Di;exports.useURMContext=io;
|
|
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;
|