orbcafe-ui 1.0.3 → 1.0.5

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.d.mts CHANGED
@@ -109,6 +109,7 @@ interface GraphReportConfig {
109
109
  interface CTableProps {
110
110
  appId?: string;
111
111
  title?: string;
112
+ showToolbar?: boolean;
112
113
  columns: any[];
113
114
  rows: any[];
114
115
  loading?: boolean;
package/dist/index.d.ts CHANGED
@@ -109,6 +109,7 @@ interface GraphReportConfig {
109
109
  interface CTableProps {
110
110
  appId?: string;
111
111
  title?: string;
112
+ showToolbar?: boolean;
112
113
  columns: any[];
113
114
  rows: any[];
114
115
  loading?: boolean;
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- 'use strict';var bo=require('react'),navigation=require('next/navigation'),lucideReact=require('lucide-react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),reactSlot=require('@radix-ui/react-slot'),classVarianceAuthority=require('class-variance-authority'),jsxRuntime=require('react/jsx-runtime'),material=require('@mui/material'),mo=require('@mui/material/Box'),oi=require('@mui/material/Paper'),ni=require('@mui/material/Table'),ai=require('@mui/material/TableBody'),Do=require('@mui/material/TableCell'),wn=require('@mui/material/TableContainer'),pa=require('@mui/material/TableHead'),ma=require('@mui/material/TableRow'),core=require('@dnd-kit/core'),modifiers=require('@dnd-kit/modifiers'),cn=require('@mui/icons-material/Search'),na=require('@mui/icons-material/ViewColumn'),yn=require('@mui/icons-material/Save'),ra=require('@mui/icons-material/Download'),ia=require('@mui/icons-material/AccountTree'),la=require('@mui/icons-material/Functions'),sa=require('@mui/icons-material/Insights'),ga=require('@mui/material/Checkbox'),fa=require('@mui/material/TableSortLabel'),Ca=require('@mui/icons-material/KeyboardArrowRight'),va=require('@mui/icons-material/KeyboardArrowDown'),La=require('@mui/icons-material/Check'),Aa=require('@mui/icons-material/ClearAll'),Ua=require('@mui/icons-material/Close'),Br=require('@mui/icons-material/Settings'),Lr=require('@mui/icons-material/KeyboardArrowUp'),Fr=require('@mui/icons-material/ArrowRightAlt'),rr=require('@mui/icons-material/Star'),DateCalendar=require('@mui/x-date-pickers/DateCalendar'),PickersDay=require('@mui/x-date-pickers/PickersDay'),Cr=require('@mui/icons-material/CalendarMonth'),vr=require('@mui/icons-material/Clear'),Sr=require('@mui/icons-material/ArrowForward'),De=require('dayjs'),Tr=require('dayjs/plugin/isBetween'),Kr=require('@mui/icons-material/Delete'),qr=require('@mui/icons-material/StarBorder'),Xr=require('@mui/icons-material/ViewQuilt'),Ti=require('@mui/icons-material/Language'),wi=require('@mui/icons-material/DesktopWindows'),Ii=require('@mui/icons-material/DarkMode'),ki=require('@mui/icons-material/LightMode');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var bo__namespace=/*#__PURE__*/_interopNamespace(bo);var mo__default=/*#__PURE__*/_interopDefault(mo);var oi__default=/*#__PURE__*/_interopDefault(oi);var ni__default=/*#__PURE__*/_interopDefault(ni);var ai__default=/*#__PURE__*/_interopDefault(ai);var Do__default=/*#__PURE__*/_interopDefault(Do);var wn__default=/*#__PURE__*/_interopDefault(wn);var pa__default=/*#__PURE__*/_interopDefault(pa);var ma__default=/*#__PURE__*/_interopDefault(ma);var cn__default=/*#__PURE__*/_interopDefault(cn);var na__default=/*#__PURE__*/_interopDefault(na);var yn__default=/*#__PURE__*/_interopDefault(yn);var ra__default=/*#__PURE__*/_interopDefault(ra);var ia__default=/*#__PURE__*/_interopDefault(ia);var la__default=/*#__PURE__*/_interopDefault(la);var sa__default=/*#__PURE__*/_interopDefault(sa);var ga__default=/*#__PURE__*/_interopDefault(ga);var fa__default=/*#__PURE__*/_interopDefault(fa);var Ca__default=/*#__PURE__*/_interopDefault(Ca);var va__default=/*#__PURE__*/_interopDefault(va);var La__default=/*#__PURE__*/_interopDefault(La);var Aa__default=/*#__PURE__*/_interopDefault(Aa);var Ua__default=/*#__PURE__*/_interopDefault(Ua);var Br__default=/*#__PURE__*/_interopDefault(Br);var Lr__default=/*#__PURE__*/_interopDefault(Lr);var Fr__default=/*#__PURE__*/_interopDefault(Fr);var rr__default=/*#__PURE__*/_interopDefault(rr);var Cr__default=/*#__PURE__*/_interopDefault(Cr);var vr__default=/*#__PURE__*/_interopDefault(vr);var Sr__default=/*#__PURE__*/_interopDefault(Sr);var De__default=/*#__PURE__*/_interopDefault(De);var Tr__default=/*#__PURE__*/_interopDefault(Tr);var Kr__default=/*#__PURE__*/_interopDefault(Kr);var qr__default=/*#__PURE__*/_interopDefault(qr);var Xr__default=/*#__PURE__*/_interopDefault(Xr);var Ti__default=/*#__PURE__*/_interopDefault(Ti);var wi__default=/*#__PURE__*/_interopDefault(wi);var Ii__default=/*#__PURE__*/_interopDefault(Ii);var ki__default=/*#__PURE__*/_interopDefault(ki);function re(...e){return tailwindMerge.twMerge(clsx.clsx(e))}var $t={primary:"#000000",primaryHover:"#333333"},dt={primary:"bg-primary text-primary-foreground hover:bg-primary/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",ghost:"hover:bg-accent hover:text-accent-foreground"},$e={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",full:"rounded-full"},yo=()=>"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50";var Hn=classVarianceAuthority.cva(yo(),{variants:{variant:{default:`${dt.primary} shadow-sm`,destructive:"bg-red-500 text-white hover:bg-red-600 active:bg-red-700 dark:bg-red-600 dark:hover:bg-red-500 dark:active:bg-red-700 shadow-sm",outline:`${dt.outline} shadow-sm`,secondary:"bg-gray-200 text-gray-700 hover:bg-gray-300 active:bg-gray-400 dark:bg-gray-700 dark:text-gray-200 dark:hover:bg-gray-600 dark:active:bg-gray-500 shadow-sm",ghost:dt.ghost,link:"text-blue-600 dark:text-blue-400 underline-offset-4 hover:underline hover:text-blue-700 dark:hover:text-blue-300 active:text-blue-800 dark:active:text-blue-200","chat-tool":"bg-[var(--orbai-surface-2)] border border-[var(--orbai-border-soft)] text-[var(--orbai-text-2)] hover:bg-[var(--orbai-surface-3)] hover:border-[var(--orbai-border-strong)] hover:text-[var(--orbai-text-1)] active:scale-95 transition-all duration-200","chat-send":`bg-[${$t.primary}] hover:bg-[${$t.primaryHover}] text-white border border-[var(--orbai-border-strong)] shadow-[var(--orbai-shadow-soft-sm)] hover:shadow-[var(--orbai-shadow-soft-md)] active:scale-95 transition-all duration-200`,"chat-stop":"bg-red-500 hover:bg-red-600 border border-[var(--orbai-border-strong)] shadow-[var(--orbai-shadow-soft-sm)] hover:shadow-[var(--orbai-shadow-soft-md)] active:scale-95 text-white transition-all duration-200","chat-disabled":"cursor-not-allowed opacity-50 bg-[var(--orbai-surface-2)] border border-[var(--orbai-border-soft)] text-[var(--orbai-muted)]"},size:{default:"h-10 px-4 py-2",sm:"h-9 px-3",lg:"h-11 px-8",icon:"h-10 w-10","chat-sm":"h-8 w-8 rounded-full","chat-md":"h-10 w-10 rounded-full","chat-lg":"h-12 w-12 rounded-full"},rounded:{none:$e.none,sm:$e.sm,md:$e.md,full:$e.full}},defaultVariants:{variant:"default",size:"default",rounded:"md"}}),_t=bo__namespace.forwardRef(({className:e,variant:o,size:t,asChild:i=false,...s},a)=>jsxRuntime.jsx(i?reactSlot.Slot:"button",{className:re(Hn({variant:o,size:t,className:e})),ref:a,...s}));_t.displayName="Button";function Ut({items:e,onItemClick:o,className:t="",level:i=0,expandedIds:s,onToggleExpand:a,colorMode:l="light"}){let n=l==="dark",u=navigation.usePathname(),[v,w]=bo.useState(new Set),S=s!==void 0&&a!==void 0,x=S?s:v,P=m=>{if(S)a(m);else {let g=new Set(v);g.has(m)?g.delete(m):g.add(m),w(g);}},k=m=>{m.children&&m.children.length>0&&P(m.id),o&&o(m);};return !e||!Array.isArray(e)?jsxRuntime.jsx("div",{className:re("tree-menu",t),children:jsxRuntime.jsx("div",{className:"text-sm text-gray-500 p-2",children:"No items to display"})}):jsxRuntime.jsx("div",{className:re("tree-menu",t),children:e.map(m=>{let g=x.has(m.id)||m.isExpanded,y=m.children&&m.children.length>0,d=m.appurl||m.href,I=d?u===d:false;return jsxRuntime.jsxs("div",{className:"tree-menu-item relative",children:[I&&jsxRuntime.jsx("div",{className:re("absolute left-0 top-2 bottom-2 w-[3px] rounded-r-full z-10",n?"bg-[#90caf9]":"bg-[#1976d2]")}),jsxRuntime.jsxs(_t,{variant:"ghost",className:re("w-full justify-start gap-2 h-auto py-2 relative overflow-hidden group",`ml-${i*4}`,I?n?"bg-transparent text-[#90caf9] hover:bg-gray-800/35":"bg-transparent text-[#1976d2] hover:bg-gray-100/60":n?"hover:bg-gray-800/50 text-gray-300":"hover:bg-gray-100/50 text-gray-700"),onClick:()=>k(m),children:[y&&jsxRuntime.jsx("div",{className:re("flex-shrink-0 transition-transform duration-200",g&&"rotate-90",I?n?"text-[#90caf9]":"text-[#1976d2]":n?"text-gray-500 group-hover:text-gray-300":"text-gray-400 group-hover:text-gray-600"),children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-4 w-4"})}),!y&&jsxRuntime.jsx("div",{className:"w-4 h-4 flex-shrink-0"}),m.icon&&jsxRuntime.jsx("div",{className:re("flex-shrink-0 transition-colors duration-200",I?n?"text-[#90caf9]":"text-[#1976d2]":n?"text-gray-500 group-hover:text-gray-300":"text-gray-400 group-hover:text-gray-600"),children:m.icon}),jsxRuntime.jsxs("div",{className:"flex-1 text-left overflow-hidden z-10",children:[jsxRuntime.jsx("div",{className:re("text-sm truncate transition-colors duration-200",I?"font-semibold":"font-medium"),children:m.title||m.label}),m.description&&jsxRuntime.jsx("div",{className:re("text-xs truncate transition-colors duration-200",I?n?"text-[#90caf9]/70":"text-[#1976d2]/75":n?"text-gray-400":"text-gray-500"),title:m.description,children:m.description})]})]}),y&&jsxRuntime.jsx("div",{className:re("grid transition-[grid-template-rows] duration-300 ease-in-out",g?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:jsxRuntime.jsx("div",{className:"overflow-hidden",children:jsxRuntime.jsx(Ut,{items:m.children,onItemClick:o,level:i+1,expandedIds:s,onToggleExpand:a,colorMode:l})})})]},m.id)})})}var To=({collapsed:e,onToggle:o,className:t="",maxHeight:i,menuData:s=[],colorMode:a="light"})=>{let l=a==="dark",n=navigation.useRouter(),[u,v]=bo.useState(""),[w,S]=bo.useState(new Set);bo.useEffect(()=>{e&&S(new Set);},[e]);let x=bo.useCallback(g=>{let y=[],d=I=>{I.forEach(r=>{y.push(r.id),r.children&&d(r.children);});};return d(g),y},[]),P=bo.useMemo(()=>{if(!u.trim())return s;let g=y=>y.reduce((d,I)=>{let r=I.title?.toLowerCase().includes(u.toLowerCase())||I.description?.toLowerCase().includes(u.toLowerCase()),b=I.children?g(I.children):[];return (r||b.length>0)&&d.push({...I,children:b.length>0?b:I.children}),d},[]);return g(s)},[u,s]),k=bo.useMemo(()=>u.trim()?new Set(x(s)):w,[u,s,w,x]),m=bo.useCallback(async g=>{if(console.log("\u{1F5B1}\uFE0F \u5BFC\u822A\u83DC\u5355\u9879\u70B9\u51FB:",g),g.id==="chat"||g.appurl==="/chat"){console.log("\u{1F4AC} \u68C0\u6D4B\u5230chat\u83DC\u5355\u70B9\u51FB\uFF0C\u8DF3\u8F6C\u5230\u65B0\u7684\u804A\u5929\u89C6\u56FE");try{n.push("/chat?new=true");}catch(d){console.error("\u274C \u65E0\u6CD5\u8DF3\u8F6C\u5230\u65B0\u804A\u5929\u89C6\u56FE:",d),n.push("/chat");}return}let y=g.appurl||g.href;y&&(y.startsWith("http://")||y.startsWith("https://")?window.open(y,"_blank"):n.push(y));},[n]);return jsxRuntime.jsxs("div",{className:`flex flex-col backdrop-blur-xl border shadow-[0_4px_8px_0_rgba(31,38,135,0.1)] ${e?"w-14 rounded-full":"w-[234px] rounded-2xl"} relative ${t} ${l?"bg-[#111111] border-white/10":"bg-white/70 border-white/30"}`,style:{backdropFilter:"blur(16px) saturate(180%)",WebkitBackdropFilter:"blur(16px) saturate(180%)",transition:"width 400ms cubic-bezier(0.4, 0.0, 0.2, 1), border-radius 0ms cubic-bezier(0.4, 0.0, 0.2, 1), box-shadow 400ms ease-out",maxHeight:i?`${i}px`:void 0},children:[jsxRuntime.jsx("div",{className:`pt-4 pb-2 transition-all duration-500 ease-in-out ${e?"px-1":"px-2"}`,children:e?jsxRuntime.jsx("div",{className:"flex justify-center",children:jsxRuntime.jsx("button",{onClick:o,className:`w-10 h-10 flex items-center justify-center rounded-lg transition-colors duration-200 ${l?"text-gray-300 hover:bg-gray-800":"text-gray-500 hover:bg-gray-50"}`,title:"\u5C55\u5F00\u5BFC\u822A",children:jsxRuntime.jsx(lucideReact.Search,{className:"h-5 w-5"})})}):jsxRuntime.jsxs("div",{className:`relative transition-opacity duration-300 ${e?"opacity-0":"opacity-100 delay-200"}`,children:[jsxRuntime.jsx("input",{type:"text",placeholder:"\u641C\u7D22\u83DC\u5355...",value:u,onChange:g=>v(g.target.value),className:`w-full pl-10 pr-4 py-2 text-sm border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent ${l?"border-gray-700 bg-[#1A1A1A] text-white placeholder-gray-400":"border-gray-300 bg-white text-gray-900 placeholder-gray-500"}`}),jsxRuntime.jsx("div",{className:"absolute left-3 top-1/2 transform -translate-y-1/2 pointer-events-none",children:jsxRuntime.jsx(lucideReact.Search,{className:`h-4 w-4 ${l?"text-gray-500":"text-gray-400"}`})})]})}),jsxRuntime.jsx("nav",{className:`flex-1 pb-4 transition-all duration-500 ease-in-out overflow-y-auto min-h-0 ${e?"px-1":"px-2"}`,children:P.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-gray-500 text-sm",children:e?"\u{1F4C2}":u?"\u672A\u627E\u5230\u5339\u914D\u7684\u83DC\u5355\u9879":"\u6682\u65E0\u53EF\u8BBF\u95EE\u7684\u5E94\u7528"}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[!e&&jsxRuntime.jsx("div",{className:`transition-opacity duration-300 ${e?"opacity-0":"opacity-100 delay-200"}`,children:jsxRuntime.jsx(Ut,{items:P,onItemClick:m,className:"space-y-1",expandedIds:k,colorMode:a,onToggleExpand:g=>{let y=new Set(w);P.some(I=>I.id===g)?y.has(g)?y.delete(g):(P.forEach(I=>{I.id!==g&&y.has(I.id)&&y.delete(I.id);}),y.add(g)):y.has(g)?y.delete(g):y.add(g),S(y);}})}),e&&jsxRuntime.jsx("div",{className:"space-y-2",children:s.map(g=>jsxRuntime.jsx("div",{className:"space-y-1",children:jsxRuntime.jsx("button",{onClick:()=>{o();let y=new Set([g.id]);S(y);},className:`w-full flex items-center justify-center p-2 rounded-lg cursor-pointer transition-colors duration-200 ${l?"text-gray-400 hover:bg-gray-800":"text-gray-600 hover:bg-gray-50"}`,title:`\u5C55\u5F00\u67E5\u770B ${g.title}`,children:g.icon||jsxRuntime.jsx("div",{className:`w-6 h-6 rounded text-xs flex items-center justify-center font-medium ${l?"bg-[#90caf9] text-[#0b0b0b]":"bg-[#1976d2] text-white"}`,children:g.title?.charAt(0)||"?"})})},g.id))})]})}),!e&&jsxRuntime.jsx("button",{onClick:o,className:`absolute -bottom-1 -right-1 w-6 h-6 bg-transparent rounded-full flex items-center justify-center transition-all duration-300 ease-in-out z-20 ${l?"hover:bg-gray-800/50":"hover:bg-white/20"}`,title:"\u6298\u53E0\u5BFC\u822A",children:jsxRuntime.jsx("div",{className:"absolute",style:{bottom:"0px",right:"0px",width:"16px",height:"16px",overflow:"hidden"},children:jsxRuntime.jsx("div",{className:l?"border-yellow-400":"",style:{width:"32px",height:"32px",borderRadius:"16px",border:"3px solid #21BCFF",backgroundColor:"transparent",position:"absolute",top:"-16px",left:"-16px"}})})})]})};var Io=(e={})=>{let{initialCollapsed:o=false,content:t=[]}=e,[i,s]=bo.useState(o),[a,l]=bo.useState(t),n=bo.useCallback(()=>{s(v=>!v);},[]),u=bo.useMemo(()=>({collapsed:i,onToggle:n,menuData:a}),[i,n,a]);return {collapsed:i,setCollapsed:s,toggleCollapsed:n,menuData:a,setMenuData:l,navigationIslandProps:u}};var ko=({title:e,hideHeader:o,children:t})=>jsxRuntime.jsxs(material.Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[!o&&jsxRuntime.jsx(material.Box,{sx:{mb:2},children:jsxRuntime.jsx(material.Typography,{variant:"h4",children:e})}),jsxRuntime.jsx(material.Box,{sx:{flex:1,overflow:"hidden"},children:t})]});var Ro=e=>{let o="0.75rem";return jsxRuntime.jsxs(material.Toolbar,{sx:{pl:{sm:2},pr:{xs:1,sm:1},alignItems:"center"},children:[jsxRuntime.jsx(material.Typography,{sx:{flex:"1 1 100%",fontWeight:"bold"},variant:"h6",id:"tableTitle",component:"div",children:e.title||"Table"}),jsxRuntime.jsxs(material.Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsxRuntime.jsx(material.TextField,{size:"small",placeholder:"Search...",value:e.filterText,onChange:t=>e.setFilterText(t.target.value),InputProps:{sx:{fontSize:o,"& .MuiInputBase-input":{fontSize:o},"& .MuiInputBase-input::placeholder":{fontSize:o,opacity:1}},startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(cn__default.default,{fontSize:"small"})})},sx:{width:300}}),jsxRuntime.jsx(material.Tooltip,{title:"Group By",children:jsxRuntime.jsx(material.IconButton,{onClick:t=>e.setGroupAnchorEl(t.currentTarget),children:jsxRuntime.jsx(material.Badge,{badgeContent:e.grouping?.length,color:"primary",children:jsxRuntime.jsx(ia__default.default,{})})})}),jsxRuntime.jsx(material.Tooltip,{title:"Summary",children:jsxRuntime.jsx(material.IconButton,{onClick:t=>e.setSummaryAnchorEl(t.currentTarget),color:e.showSummary?"primary":"default",children:jsxRuntime.jsx(la__default.default,{})})}),jsxRuntime.jsx(material.Tooltip,{title:"Columns",children:jsxRuntime.jsx(material.IconButton,{onClick:t=>e.setAnchorEl(t.currentTarget),children:jsxRuntime.jsx(na__default.default,{})})}),jsxRuntime.jsx(material.Tooltip,{title:"Export",children:jsxRuntime.jsx(material.IconButton,{onClick:e.handleExport,children:jsxRuntime.jsx(ra__default.default,{})})}),e.onOpenGraphReport&&jsxRuntime.jsx(material.Tooltip,{title:"Graphic Report",children:jsxRuntime.jsx(material.IconButton,{onClick:e.onOpenGraphReport,children:jsxRuntime.jsx(sa__default.default,{})})}),e.onLayoutSave&&!e.layoutManager&&jsxRuntime.jsx(material.Tooltip,{title:"Save Layout",children:jsxRuntime.jsx(material.IconButton,{onClick:t=>e.onLayoutSave(t),children:jsxRuntime.jsx(yn__default.default,{})})}),e.layoutManager]})]})};var Bo=e=>{let{onSelectAllClick:o,order:t,orderBy:i,numSelected:s=0,rowCount:a=0,onRequestSort:l,columns:n,visibleColumns:u,selectionMode:v,onColumnResize:w,columnWidths:S}=e,[x,P]=bo.useState(null),k=bo.useRef(null),m=r=>b=>{x||l(r);},g=(r,b,c)=>{r.preventDefault(),r.stopPropagation(),P(b),k.current={startX:r.clientX,startWidth:c,colId:b},document.addEventListener("mousemove",y),document.addEventListener("mouseup",d),document.body.style.cursor="col-resize";},y=r=>{if(!k.current)return;let{startX:b,startWidth:c,colId:C}=k.current,M=r.clientX-b,T=Math.max(50,c+M);w&&w(C,T);},d=()=>{P(null),k.current=null,document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",d),document.body.style.cursor="";};return bo.useEffect(()=>()=>{document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",d);},[]),jsxRuntime.jsx(pa__default.default,{children:jsxRuntime.jsxs(ma__default.default,{children:[(v==="multiple"||v==="single")&&jsxRuntime.jsx(Do__default.default,{padding:"checkbox",sx:r=>({width:48,backgroundColor:r.palette.mode==="dark"?"#000000":"#f5f5f5",color:r.palette.mode==="dark"?"#ffffff":r.palette.text.primary}),children:jsxRuntime.jsx(ga__default.default,{color:"primary",indeterminate:s>0&&s<a,checked:a>0&&s===a,onChange:o,disabled:v==="single"})}),n.filter(r=>u.includes(r.id)).map(r=>{let b=S?.[r.id]||r.minWidth||100;return jsxRuntime.jsxs(Do__default.default,{align:"left",padding:r.disablePadding?"none":"normal",sortDirection:i===r.id?t:false,style:{width:b,minWidth:b,maxWidth:b},sx:c=>({position:"relative",backgroundColor:c.palette.mode==="dark"?"#000000":"#f5f5f5",color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary,fontWeight:"bold",userSelect:"none"}),children:[jsxRuntime.jsx(fa__default.default,{active:i===r.id,direction:i===r.id?t:"asc",onClick:m(r.id),sx:c=>({"&.MuiTableSortLabel-root":{width:"100%"},"& .MuiTableSortLabel-icon":{color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary,opacity:i===r.id?1:0,transition:"opacity 0.2s"},"&:hover .MuiTableSortLabel-icon":{opacity:.5},"&.Mui-active .MuiTableSortLabel-icon":{opacity:1,color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary},fontWeight:"bold",color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary}),children:jsxRuntime.jsx(mo__default.default,{component:"span",sx:{overflow:"visible",textOverflow:"clip",whiteSpace:"normal",lineHeight:1.2,wordBreak:"break-word",pr:1},children:r.label})}),jsxRuntime.jsx(mo__default.default,{onMouseDown:c=>g(c,r.id,typeof b=="number"?b:100),onClick:c=>c.stopPropagation(),sx:{position:"absolute",right:0,top:0,bottom:0,width:5,cursor:"col-resize","&:hover":{backgroundColor:"primary.main",opacity:.5},zIndex:1}})]},r.id)})]})})};var Ao=e=>{let{visibleRows:o,visibleColumns:t,selected:i=[],handleClick:s,columns:a,toggleGroupExpand:l,expandedGroups:n=new Set,selectionMode:u}=e,v=x=>i.indexOf(x)!==-1,w=u==="multiple"||u==="single",S=t.length+(w?1:0);return jsxRuntime.jsxs(material.TableBody,{children:[o.map((x,P)=>{if(x.type==="group"){let k=n.has(x.id),m=x.childIds||[],g=m.filter(r=>v(r)).length,y=m.length>0&&g===m.length,d=g>0&&g<m.length,I=r=>{if(r.stopPropagation(),!!e.onSelectionChange)if(y){let b=i.filter(c=>!m.includes(c));e.onSelectionChange(b);}else {let b=Array.from(new Set([...i,...m]));e.onSelectionChange(b);}};return jsxRuntime.jsx(material.TableRow,{sx:{backgroundColor:"#f5f5f5"},children:jsxRuntime.jsx(material.TableCell,{colSpan:S,sx:{py:1,pl:x.level*4+2},children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center"},children:[jsxRuntime.jsx(material.IconButton,{size:"small",onClick:()=>l&&l(x.id),sx:{mr:1},children:k?jsxRuntime.jsx(va__default.default,{}):jsxRuntime.jsx(Ca__default.default,{})}),w&&jsxRuntime.jsx(material.Checkbox,{size:"small",checked:y,indeterminate:d,onChange:I,onClick:r=>r.stopPropagation(),sx:{mr:1,p:.5}}),jsxRuntime.jsxs(material.Typography,{variant:"body2",fontWeight:"bold",children:[x.field,": ",x.value," (",x.count,")"]})]})})},x.id)}else {let k=x.data||x,m=x.id||k.id||P,g=v(m),y=`enhanced-table-checkbox-${P}`,I=(x.level!==void 0?x.level:0)*4;return jsxRuntime.jsxs(material.TableRow,{hover:true,onClick:r=>s&&s(r,k),role:"checkbox","aria-checked":g,tabIndex:-1,selected:g,sx:{cursor:"pointer"},children:[w&&jsxRuntime.jsx(material.TableCell,{padding:"checkbox",sx:{pl:I>0?I+1:void 0},children:jsxRuntime.jsx(material.Checkbox,{color:"primary",checked:g,inputProps:{"aria-labelledby":y}})}),a.filter(r=>t.includes(r.id)).map((r,b)=>{let C=!w&&b===0&&I>0?{pl:I+2}:{};return jsxRuntime.jsx(material.TableCell,{align:"left",sx:C,children:r.render?r.render(k[r.id],k):(function(){let T=k[r.id];if(r.numeric){if(typeof T=="number")return T.toLocaleString();if(typeof T=="string"&&T.trim()!==""&&!isNaN(Number(T)))return Number(T).toLocaleString()}return T})()},r.id)})]},m)}}),o.length===0&&jsxRuntime.jsx(material.TableRow,{children:jsxRuntime.jsx(material.TableCell,{colSpan:S,align:"center",children:"No data"})})]})};var Vo=e=>{let{visibleColumns:o,summaryRow:t,selectionMode:i}=e;if(!e.showSummary)return null;let s=i==="multiple"||i==="single";return jsxRuntime.jsx(material.TableFooter,{sx:{position:"sticky",bottom:0,zIndex:e.zIndex,bgcolor:"background.paper"},children:jsxRuntime.jsxs(material.TableRow,{children:[s&&jsxRuntime.jsx(material.TableCell,{padding:"checkbox",sx:{bgcolor:"background.paper"}}),o.map(a=>jsxRuntime.jsx(material.TableCell,{sx:{fontWeight:"bold",fontSize:"0.875rem",bgcolor:"background.paper",color:"text.primary"},children:(function(){let n=t[a];return n==null||n===""?"":typeof n=="number"?n.toLocaleString():typeof n=="string"&&n.trim()!==""&&!isNaN(Number(n))?Number(n).toLocaleString():n})()},a))]})})};var Ho=e=>jsxRuntime.jsx(material.Box,{sx:{p:2},children:jsxRuntime.jsx(material.Typography,{children:"Mobile View Not Implemented"})});var Oo=({groupAnchorEl:e,setGroupAnchorEl:o,grouping:t,setGrouping:i,columns:s,toggleGroupField:a})=>jsxRuntime.jsxs(material.Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsxRuntime.jsxs(material.Box,{sx:{p:1,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[jsxRuntime.jsx(material.Typography,{variant:"subtitle2",sx:{px:1},children:"Group By"}),t.length>0&&jsxRuntime.jsx(material.Button,{size:"small",color:"error",onClick:()=>i([]),startIcon:jsxRuntime.jsx(Aa__default.default,{}),children:"Clear All"})]}),jsxRuntime.jsx(material.Divider,{}),s.map(l=>{let n=t.includes(l.id),u=t.indexOf(l.id)+1;return jsxRuntime.jsx(material.MenuItem,{onClick:()=>a(l.id),children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsxRuntime.jsx(material.Checkbox,{checked:n,size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:l.label}),n&&jsxRuntime.jsx(material.Badge,{badgeContent:u,color:"primary",sx:{mr:2}})]})},l.id)})]}),Go=({anchorEl:e,setAnchorEl:o,columns:t,visibleColumns:i,toggleColumnVisibility:s})=>jsxRuntime.jsxs(material.Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.ListItemText,{primary:"Visible Columns"})}),jsxRuntime.jsx(material.Divider,{}),t.map(a=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>s(a.id),children:[jsxRuntime.jsx(material.Checkbox,{checked:i.includes(a.id),size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:a.label})]},a.id))]}),Wo=({anchorEl:e,setAnchorEl:o,showSummary:t,setShowSummary:i,columns:s,summaryColumns:a,toggleSummaryColumn:l})=>jsxRuntime.jsxs(material.Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsxRuntime.jsx(material.MenuItem,{children:jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Switch,{checked:t,onChange:n=>i(n.target.checked),size:"small"}),label:"Show Summary Row"})}),jsxRuntime.jsx(material.Divider,{}),s.filter(n=>n.numeric).map(n=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>l(n.id),disabled:!t,children:[jsxRuntime.jsx(material.Checkbox,{checked:a.includes(n.id),size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:n.label})]},n.id)),s.filter(n=>n.numeric).length===0&&jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.ListItemText,{primary:"No numeric columns"})})]}),$o=({contextMenu:e,handleCloseContextMenu:o,columns:t,visibleColumns:i,toggleColumnVisibility:s})=>jsxRuntime.jsxs(material.Menu,{open:e!==null,onClose:o,anchorReference:"anchorPosition",anchorPosition:e!==null?{top:e.mouseY,left:e.mouseX}:void 0,children:[jsxRuntime.jsx(material.MenuItem,{onClick:o,children:"Copy"}),jsxRuntime.jsx(material.Divider,{}),jsxRuntime.jsx(material.MenuItem,{disabled:true,children:"Visible Columns"}),t.map(a=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>s(a.id),children:[jsxRuntime.jsx(material.ListItemIcon,{children:i.includes(a.id)&&jsxRuntime.jsx(La__default.default,{fontSize:"small"})}),jsxRuntime.jsx(material.ListItemText,{children:a.label})]},a.id))]});var _e=(e,o=2)=>e.toLocaleString(void 0,{maximumFractionDigits:o}),jo=({kpis:e})=>{let o=[{label:"Total Records",value:_e(e.totalRecords,0),color:"text.primary"},{label:"Total Report",value:_e(e.totalReportHours),color:"text.primary"},{label:"Total Billable",value:_e(e.totalBillableHours),color:"success.main"},{label:"Efficiency",value:`${e.efficiency.toFixed(2)}%`,color:"warning.main"},{label:"Amount",value:_e(e.totalAmount),color:"info.main"},{label:"Flagged",value:_e(e.flaggedCount,0),color:"error.main"}];return jsxRuntime.jsx(material.Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"repeat(2, minmax(0, 1fr))",lg:"repeat(6, minmax(0, 1fr))"},gap:1.5},children:o.map(t=>jsxRuntime.jsxs(material.Paper,{variant:"outlined",sx:{p:1.5,borderRadius:2,minHeight:96,display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",children:t.label}),jsxRuntime.jsx(material.Typography,{variant:"h4",fontWeight:800,sx:{color:t.color},children:t.value})]},t.label))})};var ft=["#1E88E5","#1ABC9C","#FBC02D","#EF5350","#7E57C2","#78909C"],za=({data:e})=>{let o=Math.max(...e.map(t=>t.value),1);return jsxRuntime.jsx(material.Stack,{spacing:1,children:e.map(t=>jsxRuntime.jsxs(material.Box,{sx:{display:"grid",gridTemplateColumns:"140px 1fr 64px",gap:1},children:[jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",noWrap:true,title:t.name,children:t.name}),jsxRuntime.jsx(material.Box,{sx:{alignSelf:"center",bgcolor:"action.hover",height:10,borderRadius:999,overflow:"hidden"},children:jsxRuntime.jsx(material.Box,{sx:{width:`${t.value/o*100}%`,height:"100%",bgcolor:"primary.main"}})}),jsxRuntime.jsx(material.Typography,{variant:"caption",sx:{textAlign:"right",fontWeight:600},children:t.value.toFixed(1)})]},t.name))})},Oa=({data:e})=>{let o=Math.max(...e.map(t=>t.value),1);return jsxRuntime.jsx(material.Box,{sx:{display:"flex",gap:1,alignItems:"flex-end",minHeight:210},children:e.map(t=>jsxRuntime.jsxs(material.Box,{sx:{flex:1,minWidth:0},children:[jsxRuntime.jsx(material.Box,{sx:{height:`${Math.max(t.value/o*180,6)}px`,bgcolor:"primary.main",borderRadius:"8px 8px 0 0"}}),jsxRuntime.jsx(material.Typography,{variant:"caption",noWrap:true,title:t.name,sx:{display:"block",mt:.5},children:t.name}),jsxRuntime.jsxs(material.Typography,{variant:"caption",color:"text.secondary",children:[t.value.toFixed(1),"%"]})]},t.name))})},Ga=({data:e})=>{if(e.length===0)return jsxRuntime.jsx(material.Typography,{variant:"body2",color:"text.secondary",children:"No data"});let o=0,i=`conic-gradient(${e.map((s,a)=>{let l=o;return o+=s.percent,`${ft[a%ft.length]} ${l}% ${o}%`}).join(", ")})`;return jsxRuntime.jsxs(material.Stack,{direction:{xs:"column",sm:"row"},spacing:2,alignItems:"center",children:[jsxRuntime.jsx(material.Box,{sx:{width:180,height:180,borderRadius:"50%",background:i,position:"relative"},children:jsxRuntime.jsx(material.Box,{sx:{position:"absolute",inset:30,bgcolor:"background.paper",borderRadius:"50%"}})}),jsxRuntime.jsx(material.Stack,{spacing:1,sx:{minWidth:180},children:e.map((s,a)=>jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsxRuntime.jsx(material.Box,{sx:{width:10,height:10,borderRadius:"50%",bgcolor:ft[a%ft.length]}}),jsxRuntime.jsx(material.Typography,{variant:"caption",sx:{flex:1},children:s.name}),jsxRuntime.jsxs(material.Typography,{variant:"caption",sx:{fontWeight:700},children:[s.percent.toFixed(0),"%"]})]},s.name))})]})},eo=({title:e,subtitle:o,children:t})=>jsxRuntime.jsxs(material.Paper,{variant:"outlined",sx:{p:2,borderRadius:2},children:[jsxRuntime.jsx(material.Typography,{variant:"subtitle1",fontWeight:700,children:e}),jsxRuntime.jsx(material.Typography,{variant:"body2",color:"text.secondary",sx:{mb:2},children:o}),t]}),Uo=({billableByPrimary:e,efficiencyBySecondary:o,statusDistribution:t})=>jsxRuntime.jsxs(material.Box,{sx:{display:"grid",gap:1.5,gridTemplateColumns:{xs:"1fr",lg:"1.2fr 1.2fr 1fr"}},children:[jsxRuntime.jsx(eo,{title:"Billable by Dimension",subtitle:"Top values by billable hours",children:jsxRuntime.jsx(za,{data:e})}),jsxRuntime.jsx(eo,{title:"Efficiency by Person",subtitle:"Lowest efficiency first",children:jsxRuntime.jsx(Oa,{data:o})}),jsxRuntime.jsx(eo,{title:"Status Distribution",subtitle:"Record ratio by status",children:jsxRuntime.jsx(Ga,{data:t})})]});var Yo=({open:e,onClose:o,model:t,tableContent:i})=>jsxRuntime.jsx(material.Dialog,{open:e,onClose:o,fullScreen:true,children:jsxRuntime.jsxs(material.Box,{sx:{height:"100%",display:"flex",flexDirection:"column",bgcolor:"background.default"},children:[jsxRuntime.jsx(material.Box,{sx:{p:2,borderBottom:1,borderColor:"divider"},children:jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",justifyContent:"space-between",spacing:2,children:[jsxRuntime.jsxs(material.Stack,{direction:"row",spacing:1.5,alignItems:"center",children:[jsxRuntime.jsx(material.Typography,{variant:"h5",fontWeight:800,children:t.title}),jsxRuntime.jsx(material.Chip,{size:"small",label:`${t.kpis.totalRecords} records`})]}),jsxRuntime.jsx(material.IconButton,{onClick:o,children:jsxRuntime.jsx(Ua__default.default,{})})]})}),jsxRuntime.jsxs(material.Box,{sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,overflow:"auto",minHeight:0},children:[jsxRuntime.jsx(jo,{kpis:t.kpis}),jsxRuntime.jsx(Uo,{billableByPrimary:t.charts.billableByPrimary,efficiencyBySecondary:t.charts.efficiencyBySecondary,statusDistribution:t.charts.statusDistribution}),i]})]})});var Se={primaryDimension:["Client","Customer","Category","Project"],secondaryDimension:["Person","Consultant","Owner","Name"],status:["Status","state"],date:["Date","WorkDate","CreatedAt"],description:["Description","Task","Title","Memo"],reportHours:["Report_Hour","Report Hours","Hours","ReportHours"],billableHours:["Billable_Hour","Billable Hours","BillableHours"],amount:["Amount","Billable_Amount","Total_Amount","Value"]},Ka=5,qo=e=>e.toLowerCase().replace(/[\s_-]/g,""),Te=(e,o,t,i)=>{if(o)return o;if(e.length===0)return i;let s=Object.keys(e[0]),a=new Map(s.map(l=>[qo(l),l]));for(let l of t){let n=a.get(qo(l));if(n)return n}return s[0]||i},ye=e=>{if(typeof e=="number")return Number.isFinite(e)?e:0;if(typeof e=="string"){let o=Number(e.replace(/,/g,"").trim());return Number.isFinite(o)?o:0}return 0},be=(e,o)=>e==null||e===""?o:String(e),Ya=(e,o,t,i)=>{let s=new Map;return e.forEach(a=>{let l=be(a[o],"Unassigned");s.set(l,(s.get(l)||0)+ye(a[t]));}),Array.from(s.entries()).map(([a,l])=>({name:a,value:l})).sort((a,l)=>l.value-a.value).slice(0,i)},qa=(e,o,t,i,s)=>{let a=new Map;return e.forEach(l=>{let n=be(l[o],"Unassigned"),u=a.get(n)||{report:0,billable:0};u.report+=ye(l[t]),u.billable+=ye(l[i]),a.set(n,u);}),Array.from(a.entries()).map(([l,n])=>({name:l,value:n.report>0?n.billable/n.report*100:0})).sort((l,n)=>l.value-n.value).slice(0,s)},Xa=(e,o)=>{let t=e.length;if(t===0)return [];let i=new Map;return e.forEach(s=>{let a=be(s[o],"Unassigned");i.set(a,(i.get(a)||0)+1);}),Array.from(i.entries()).map(([s,a])=>({name:s,value:a,percent:a/t*100}))},Xo=({rows:e,config:o})=>{let t=bo.useMemo(()=>{let u=o?.fieldMapping;return {primaryDimension:Te(e,u?.primaryDimension,Se.primaryDimension,"Category"),secondaryDimension:Te(e,u?.secondaryDimension,Se.secondaryDimension,"Owner"),status:Te(e,u?.status,Se.status,"Status"),date:Te(e,u?.date,Se.date,"Date"),description:Te(e,u?.description,Se.description,"Description"),reportHours:Te(e,u?.reportHours,Se.reportHours,"ReportHours"),billableHours:Te(e,u?.billableHours,Se.billableHours,"BillableHours"),amount:Te(e,u?.amount,Se.amount,"Amount")}},[e,o?.fieldMapping]),i=bo.useMemo(()=>e.map((u,v)=>{let w=ye(u[t.reportHours]),S=ye(u[t.billableHours]),x=ye(u[t.amount]),P=w>0?S/w*100:0;return {id:`graph-row-${v}`,Date:be(u[t.date],""),Primary:be(u[t.primaryDimension],"Unassigned"),Secondary:be(u[t.secondaryDimension],"Unassigned"),Description:be(u[t.description],""),ReportHours:w,BillableHours:S,Amount:x,Efficiency:P,Status:be(u[t.status],"Unassigned")}}),[e,t]),s=bo.useMemo(()=>{let u=i.length,v=i.reduce((m,g)=>m+ye(g.ReportHours),0),w=i.reduce((m,g)=>m+ye(g.BillableHours),0),S=i.reduce((m,g)=>m+ye(g.Amount),0),x=v>0?w/v*100:0,P=o?.statusFlagValues||["flag","flagged","warning","risk"],k=i.filter(m=>P.includes(be(m.Status,"").toLowerCase())).length;return {totalRecords:u,totalReportHours:v,totalBillableHours:w,efficiency:x,totalAmount:S,flaggedCount:k}},[i,o?.statusFlagValues]),a=o?.topN||Ka,l=bo.useMemo(()=>({billableByPrimary:Ya(i,"Primary","BillableHours",a),efficiencyBySecondary:qa(i,"Secondary","ReportHours","BillableHours",a),statusDistribution:Xa(i,"Status")}),[i,a]),n=bo.useMemo(()=>({title:o?.title||"Graphic Report",kpis:s,charts:l,table:{columns:[{id:"Date",label:t.date},{id:"Primary",label:t.primaryDimension},{id:"Secondary",label:t.secondaryDimension},{id:"Description",label:t.description},{id:"ReportHours",label:"Report Hours",align:"right"},{id:"BillableHours",label:"Billable Hours",align:"right"},{id:"Amount",label:"Amount",align:"right"},{id:"Efficiency",label:"Efficiency",align:"right"},{id:"Status",label:t.status}],rows:i}}),[l,o?.title,t,s,i]);return {fieldMapping:t,model:n}};var bt=({variants:e,currentVariantId:o,onLoad:t,onSave:i,onDelete:s,onSetDefault:a})=>{let l="0.75rem",[n,u]=bo.useState(false),[v,w]=bo.useState(""),[S,x]=bo.useState(false),[P,k]=bo.useState(false),m=e.find(d=>d.id===o);return jsxRuntime.jsxs(material.Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsxRuntime.jsx(material.Typography,{variant:"body2",sx:{fontWeight:"bold",minWidth:"fit-content",fontSize:l},children:"Variant:"}),jsxRuntime.jsx(material.Autocomplete,{size:"small",sx:{width:200,"& .MuiInputBase-root":{fontSize:l},"& .MuiInputBase-input":{fontSize:l},"& .MuiAutocomplete-noOptions":{fontSize:l}},noOptionsText:jsxRuntime.jsx(material.Typography,{sx:{fontSize:l},children:"No options"}),options:e,getOptionLabel:d=>d.name+(d.isDefault?" (Default)":""),value:m||null,onChange:(d,I)=>{I&&t(I);},renderInput:d=>jsxRuntime.jsx(material.TextField,{...d,variant:"outlined",size:"small",InputProps:{...d.InputProps,sx:{fontSize:l}},placeholder:"Select Variant"}),renderOption:(d,I)=>jsxRuntime.jsx("li",{...d,children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsxRuntime.jsx(material.Typography,{sx:{flex:1,fontSize:l},children:I.name}),I.isDefault&&jsxRuntime.jsx(rr__default.default,{fontSize:"small",color:"action"})]})})}),jsxRuntime.jsx(material.Tooltip,{title:"Save View",children:jsxRuntime.jsx(material.IconButton,{onClick:()=>{w(m?.name||"New Variant"),x(m?.isDefault||false),k(m?.isPublic||false),u(true);},size:"small",color:"primary",children:jsxRuntime.jsx(yn__default.default,{})})}),jsxRuntime.jsxs(material.Dialog,{open:n,onClose:()=>u(false),children:[jsxRuntime.jsx(material.DialogTitle,{children:"Save View"}),jsxRuntime.jsxs(material.DialogContent,{children:[jsxRuntime.jsx(material.TextField,{autoFocus:true,margin:"dense",label:"View Name",fullWidth:true,variant:"outlined",value:v,onChange:d=>w(d.target.value)}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:S,onChange:d=>x(d.target.checked)}),label:"Set as Default"}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:P,onChange:d=>k(d.target.checked)}),label:"Public (All Users)"})]}),jsxRuntime.jsxs(material.DialogActions,{children:[jsxRuntime.jsx(material.Button,{onClick:()=>u(false),children:"Cancel"}),jsxRuntime.jsx(material.Button,{onClick:()=>{i({name:v,isDefault:S,isPublic:P,description:""}),u(false);},variant:"contained",children:"Save"})]})]})]})};var sr="http://127.0.0.1:8515",nn=({appId:e,tableKey:o="default",currentFilters:t,currentLayoutId:i,layoutRefs:s,onLoad:a,serviceUrl:l=sr,onError:n,onSuccess:u,currentVariantId:v,onVariantChange:w})=>{let[S,x]=bo.useState([]),[P,k]=bo.useState(""),m=v!==void 0?v:P,g=c=>{v===void 0&&k(c),w&&w(c);},y=bo.useCallback(async()=>{if(!e)return [];try{let c=await fetch(`${l}/api/variants?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!c.ok)throw new Error("Failed to fetch variants");let C=await c.json();x(C);let M=C.find(T=>T.isDefault);return M&&!m&&(g(M.id),a(M)),C}catch(c){return console.error("Error fetching variants",c),n&&n("Failed to load variants"),[]}},[e,o,l,n,m,a]);return bo.useEffect(()=>{y();},[e,o]),jsxRuntime.jsx(bt,{variants:S,currentVariantId:m,onLoad:c=>{g(c.id),a(c);},onSave:async c=>{try{let C=S.find(A=>A.name===c.name),M=C?C.id:Date.now().toString(),T=[];if(C&&(Array.isArray(C.filters)?T=[...C.filters]:C.filters&&(T=[{scope:"default",filters:C.filters}])),c.scope==="Search"||c.scope==="Both"){let A=(Array.isArray(t),t);if(A)if(Array.isArray(A)&&A.length>0&&A[0].scope)A.forEach(V=>{let B=T.findIndex(H=>H.scope===V.scope);B>=0?T[B]=V:T.push(V);});else {let V={scope:o,filters:A},B=T.findIndex(H=>H.scope===o);B>=0?T[B]=V:T.push(V);}}let p=C?.layout||{},D=[];if(C&&Array.isArray(C.layoutRefs)&&(D=[...C.layoutRefs]),c.scope==="Layout"||c.scope==="Both")if(s&&s.length>0)s.forEach(A=>{let V=D.findIndex(B=>B.tableKey===A.tableKey);V>=0?D[V]=A:D.push(A);});else {let A={tableKey:o,layoutId:i||null},V=D.findIndex(B=>B.tableKey===o);V>=0?D[V]=A:D.push(A);}let f={appId:e,tableKey:o,...c,id:M,createdAt:new Date().toISOString(),filters:T,layout:p,layoutRefs:D};if(!(await fetch(`${l}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(f)})).ok)throw new Error("Failed to save variant");u&&u("Variant saved successfully"),await y(),g(M),a(f);}catch(C){console.error("Error saving variant",C),n&&n("Failed to save variant");}},onDelete:async c=>{try{if(!(await fetch(`${l}/api/variants/${c}`,{method:"DELETE"})).ok)throw new Error("Failed to delete variant");m===c&&g(""),y(),u&&u("Variant deleted successfully");}catch(C){console.error("Error deleting variant",C),n&&n("Failed to delete variant");}},onSetDefault:async c=>{try{let C=S.find(p=>p.id===c);if(!C)return;let M={appId:e,tableKey:o,...C,isDefault:!0};if(!(await fetch(`${l}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(M)})).ok)throw new Error("Failed to set default variant");await y(),u&&u("Default variant updated");}catch(C){console.error("Error setting default variant",C),n&&n("Failed to update default variant");}}})};De__default.default.extend(Tr__default.default);var wr=[null,null],io="0.75rem",Ir=material.styled(PickersDay.PickersDay,{shouldForwardProp:e=>e!=="isInRange"&&e!=="isStart"&&e!=="isEnd"&&e!=="isHovered"})(({theme:e,isInRange:o,isStart:t,isEnd:i,isHovered:s})=>({...o&&{borderRadius:0,backgroundColor:e.palette.primary.light,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.main}},...s&&!o&&!t&&!i&&{borderRadius:0,backgroundColor:e.palette.action.hover,border:`1px dashed ${e.palette.primary.main}`},...t&&{borderRadius:"50% 0 0 50%",backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.dark}},...i&&{borderRadius:"0 50% 50% 0",backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.dark}},...t&&i&&{borderRadius:"50%"}})),ln=({label:e="Date Range",value:o=wr,onChange:t})=>{let[i,s]=bo.useState(null),[a,l]=bo.useState(o),[n,u]=bo.useState("start"),[v,w]=bo.useState(null),[S,x]=bo.useState(o[0]||De__default.default()),P=bo__namespace.default.useRef(o);bo.useEffect(()=>{let[M,T]=o,[p,D]=P.current,f=V=>V&&typeof V.isSame=="function",W=!(M===null&&p===null||f(M)&&f(p)&&M.isSame(p,"day")),A=!(T===null&&D===null||f(T)&&f(D)&&T.isSame(D,"day"));(W||A)&&(l(o),o[0]&&f(o[0])&&x(o[0])),P.current=o;},[o]);let k=M=>{s(M.currentTarget);},m=()=>{s(null),u("start"),w(null);},g=!!i,y=M=>{if(!M)return;let T=[...a];if(n==="start")T=[M,null],u("end");else {let p=T[0];p&&M.isBefore(p)?(T=[M,null],u("end")):(T=[p,M],u("start"));}l(T);},d=M=>{let T=De__default.default(),p=[null,null];switch(M){case "today":p=[T,T];break;case "week":p=[T.startOf("week"),T.endOf("week")];break;case "month":p=[T.startOf("month"),T.endOf("month")];break}l(p),u("start"),x(T);},I=()=>{l([null,null]),u("start"),x(De__default.default());},r=()=>{t&&t(a),m();},b=()=>{l(o),u("start"),m();},c=bo.useCallback(M=>{let{day:T,...p}=M,[D,f]=a,W=D?T.isSame(D,"day"):false,A=f?T.isSame(f,"day"):false,V=D&&f?T.isBetween(D,f,"day","()"):false,B=false;return n==="end"&&D&&!f&&v&&T.isAfter(D,"day")&&T.isBefore(v.add(1,"day"),"day")&&(B=true),jsxRuntime.jsx(Ir,{...p,day:T,disableMargin:true,isStart:W,isEnd:A,isInRange:V||B,onMouseEnter:()=>w(T)})},[a,n,v]),C=M=>M?M.format("YYYY-MM-DD"):"";return jsxRuntime.jsxs(material.Box,{children:[jsxRuntime.jsx(material.TextField,{label:e,value:a[0]?`${C(a[0])} - ${C(a[1])}`:"",onClick:k,fullWidth:true,size:"small",InputLabelProps:{sx:{fontSize:io}},InputProps:{readOnly:true,sx:{fontSize:io,"& .MuiOutlinedInput-input":{fontSize:io},paddingRight:"4px"},endAdornment:jsxRuntime.jsxs(material.InputAdornment,{position:"end",sx:{ml:0},children:[(a[0]||a[1])&&jsxRuntime.jsx(material.IconButton,{size:"small",onClick:M=>{M.stopPropagation(),I();},edge:"end",sx:{mr:.5,padding:"2px"},children:jsxRuntime.jsx(vr__default.default,{sx:{fontSize:"1rem"}})}),jsxRuntime.jsx(material.IconButton,{size:"small",edge:"end",onClick:k,sx:{padding:"2px"},children:jsxRuntime.jsx(Cr__default.default,{sx:{fontSize:"1rem"},color:"action"})})]})}}),jsxRuntime.jsxs(material.Popover,{open:g,anchorEl:i,onClose:m,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},slotProps:{paper:{sx:{display:"flex",flexDirection:"column",p:0,minWidth:320}}},children:[jsxRuntime.jsx(material.Box,{sx:{p:2,bgcolor:"background.default",borderBottom:1,borderColor:"divider"},children:jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:2,justifyContent:"space-between",children:[jsxRuntime.jsxs(material.Box,{sx:{p:1,border:1,borderColor:n==="start"?"primary.main":"divider",borderRadius:1,bgcolor:n==="start"?"action.hover":"transparent",flex:1,cursor:"pointer"},onClick:()=>u("start"),children:[jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",display:"block",children:"Start Date"}),jsxRuntime.jsx(material.Typography,{variant:"body2",fontWeight:500,children:a[0]?a[0].format("MMM DD, YYYY"):"Select..."})]}),jsxRuntime.jsx(Sr__default.default,{color:"action",fontSize:"small"}),jsxRuntime.jsxs(material.Box,{sx:{p:1,border:1,borderColor:n==="end"?"primary.main":"divider",borderRadius:1,bgcolor:n==="end"?"action.hover":"transparent",flex:1,cursor:"pointer"},onClick:()=>{a[0]&&u("end");},children:[jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",display:"block",children:"End Date"}),jsxRuntime.jsx(material.Typography,{variant:"body2",fontWeight:500,children:a[1]?a[1].format("MMM DD, YYYY"):"Select..."})]})]})}),jsxRuntime.jsx(material.Box,{sx:{p:2,pb:0},children:jsxRuntime.jsxs(material.Stack,{direction:"row",spacing:1,justifyContent:"center",children:[jsxRuntime.jsx(material.Chip,{label:"Today",onClick:()=>d("today"),clickable:true,size:"small",variant:"outlined"}),jsxRuntime.jsx(material.Chip,{label:"This Week",onClick:()=>d("week"),clickable:true,size:"small",variant:"outlined"}),jsxRuntime.jsx(material.Chip,{label:"This Month",onClick:()=>d("month"),clickable:true,size:"small",variant:"outlined"})]})}),jsxRuntime.jsx(DateCalendar.DateCalendar,{value:null,referenceDate:S,onMonthChange:x,onYearChange:x,onChange:y,slots:{day:c},views:["day"],showDaysOutsideCurrentMonth:true,sx:{m:0}}),jsxRuntime.jsx(material.Divider,{}),jsxRuntime.jsxs(material.Stack,{direction:"row",justifyContent:"flex-end",spacing:1,sx:{p:2},children:[jsxRuntime.jsx(material.Button,{size:"small",onClick:b,color:"inherit",children:"Cancel"}),jsxRuntime.jsx(material.Button,{size:"small",variant:"contained",onClick:r,children:"Done"})]})]})]})};var St={equals:"=",contains:"\u2287",notContains:"\u2285",wildcard:"*","=":"=","!=":"!=",">":">","<":"<",">=":"\u2265","<=":"\u2264",between:"\u2194"},Vr={equals:"Equals",contains:"Contains",notContains:"Does Not Contain",wildcard:"Wildcard Search","=":"Equals","!=":"Not Equals",">":"Greater Than","<":"Less Than",">=":"Greater Than or Equal","<=":"Less Than or Equal",between:"Between"},Nr=["equals","contains","notContains","wildcard"],dn=["=","!=",">","<",">=","<=","between"],Z="0.75rem",Hr=({field:e,value:o,onChange:t})=>{let[i,s]=bo.useState(null),[a,l]=bo.useState(null),[n,u]=bo.useState(""),[v,w]=bo.useState(""),[S,x]=bo.useState(false),[P,k]=bo.useState(""),[m,g]=bo.useState("");bo.useEffect(()=>{let p=setTimeout(()=>{g(P);},1e3);return ()=>clearTimeout(p)},[P]);let y=o?.operator||(e.type==="number"?"=":"equals"),d=o?.value,I=p=>Vr[p]||p,r=p=>{s(p.currentTarget);},b=p=>{t({...o,operator:p,value:d}),s(null);},c={size:"small",fullWidth:true,variant:"outlined",InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}},SelectProps:{MenuProps:{PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,paddingTop:"4px",paddingBottom:"4px",minHeight:"auto"}}}}}},C=e.type||"text";if(C==="date"){let D=(f=>{if(!f)return [null,null];if(Array.isArray(f)&&f.length===2){let W=f[0]?De__default.default.isDayjs(f[0])?f[0]:De__default.default(f[0]):null,A=f[1]?De__default.default.isDayjs(f[1])?f[1]:De__default.default(f[1]):null;return [W,A]}return De__default.default.isDayjs(f)||typeof f=="string"?[De__default.default.isDayjs(f)?f:De__default.default(f),null]:[null,null]})(d);return jsxRuntime.jsx(ln,{label:e.label,value:D,onChange:f=>t({value:f,operator:"between"})})}if(C==="number"&&y==="between"){let p=()=>{t({value:[n,v],operator:"between"}),l(null);},D=Array.isArray(d)?`${d[0]||""} - ${d[1]||""}`:"";return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(material.TextField,{...c,label:e.label,value:D,placeholder:"Min - Max",InputProps:{...c.InputProps,startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(material.Tooltip,{title:I("between"),children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:r,sx:{width:24,height:24,fontSize:Z},children:St.between})})}),readOnly:true},onClick:f=>l(f.currentTarget)}),jsxRuntime.jsx(material.Menu,{anchorEl:i,open:!!i,onClose:()=>s(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,minHeight:"auto",py:.5}}},children:dn.map(f=>jsxRuntime.jsxs(material.MenuItem,{selected:f===y,onClick:()=>b(f),children:[jsxRuntime.jsx(material.Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:St[f]}),jsxRuntime.jsx(material.ListItemText,{primary:I(f),primaryTypographyProps:{fontSize:Z}})]},f))}),jsxRuntime.jsx(material.Popover,{open:!!a,anchorEl:a,onClose:()=>l(null),anchorOrigin:{vertical:"bottom",horizontal:"left"},children:jsxRuntime.jsxs(material.Box,{sx:{p:2,display:"flex",gap:1,alignItems:"center"},children:[jsxRuntime.jsx(material.TextField,{size:"small",label:"Min",type:"number",value:n,onChange:f=>u(f.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}}}),jsxRuntime.jsx(Fr__default.default,{color:"action"}),jsxRuntime.jsx(material.TextField,{size:"small",label:"Max",type:"number",value:v,onChange:f=>w(f.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}}}),jsxRuntime.jsx(material.Button,{variant:"contained",size:"small",onClick:p,children:"OK"})]})})]})}if(C==="select")return jsxRuntime.jsxs(material.TextField,{...c,select:true,label:e.label,value:d||"",onChange:p=>t({...o,value:p.target.value,operator:"equals"}),children:[jsxRuntime.jsx(material.MenuItem,{value:"",children:jsxRuntime.jsx("em",{children:"None"})}),e.options?.map(p=>jsxRuntime.jsx(material.MenuItem,{value:p.value,children:p.label},p.value))]});if(C==="multi-select"){let p=Array.isArray(d)?d:[],D=e.options?.filter(f=>f.label.toLowerCase().includes(m.toLowerCase()))||[];return jsxRuntime.jsxs(material.TextField,{...c,select:true,label:e.label,value:p,onChange:f=>t({...o,value:f.target.value,operator:"anyOf"}),SelectProps:{...c.SelectProps,multiple:true,onClose:()=>{k(""),g("");},renderValue:f=>{if(!Array.isArray(f)||f.length===0)return jsxRuntime.jsx("em",{children:"None"});let W=V=>e.options?.find(B=>B.value===V)?.label||V,A=f.map(W);return A.length>2?`${A.slice(0,2).join(", ")} +${A.length-2}`:A.join(", ")}},children:[jsxRuntime.jsx(material.ListSubheader,{children:jsxRuntime.jsx(material.TextField,{size:"small",autoFocus:true,placeholder:"Search...",fullWidth:true,InputProps:{startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(cn__default.default,{fontSize:"small"})}),sx:{fontSize:Z}},value:P,onChange:f=>k(f.target.value),onKeyDown:f=>{f.key!=="Escape"&&f.stopPropagation();},onClick:f=>f.stopPropagation()})}),D.length>0?D.map(f=>jsxRuntime.jsxs(material.MenuItem,{value:f.value,children:[jsxRuntime.jsx(material.Checkbox,{checked:p.indexOf(f.value)>-1,size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:f.label,primaryTypographyProps:{fontSize:Z}})]},f.value)):jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.ListItemText,{primary:"No options found",primaryTypographyProps:{fontSize:Z}})})]})}let M=C==="number"?dn:Nr,T=S||d!==void 0&&d!==""&&d!==null||!!i;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(material.TextField,{...c,label:e.label,sx:{minWidth:"120px"},value:d||"",type:C==="number"?"number":"text",onChange:p=>t({...o,value:p.target.value,operator:y}),onFocus:()=>x(true),onBlur:()=>x(false),InputProps:{...c.InputProps,startAdornment:T?jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(material.Tooltip,{title:I(y),children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:r,onMouseDown:p=>p.preventDefault(),sx:{width:24,height:24,fontSize:Z,fontWeight:"bold",color:"primary.main",bgcolor:"action.hover"},children:St[y]})})}):null,endAdornment:e.hasSearchIcon?jsxRuntime.jsx(material.InputAdornment,{position:"end",children:jsxRuntime.jsx(cn__default.default,{color:"action"})}):void 0}}),jsxRuntime.jsx(material.Menu,{anchorEl:i,open:!!i,onClose:()=>s(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,minHeight:"auto",py:.5}}},children:M.map(p=>jsxRuntime.jsxs(material.MenuItem,{selected:p===y,onClick:()=>b(p),children:[jsxRuntime.jsx(material.Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:St[p]}),jsxRuntime.jsx(material.ListItemText,{primary:I(p),primaryTypographyProps:{fontSize:Z}})]},p))})]})},qe=({fields:e,filters:o,onFilterChange:t,variants:i=[],currentVariantId:s,onVariantLoad:a,onVariantSave:l,onVariantDelete:n,onVariantSetDefault:u,onSearch:v,loading:w=false,appId:S,tableKey:x,currentLayout:P,currentLayoutId:k,layoutRefs:m,variantService:g})=>{let[y,d]=bo.useState(true),[I,r]=bo.useState(null),[b,c]=bo.useState(e.filter(p=>!p.hidden).map(p=>p.id)),C=(p,D)=>{t({...o,[p]:D});},M=p=>{b.includes(p)?c(b.filter(D=>D!==p)):c([...b,p]);};return jsxRuntime.jsxs(material.Paper,{sx:{mb:0,display:"flex",flexDirection:"column",overflow:"visible",position:"relative"},children:[jsxRuntime.jsxs(material.Box,{sx:{p:2,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[S?jsxRuntime.jsx(nn,{appId:S,tableKey:x,currentFilters:{values:o,visibleFields:b},currentLayout:P,currentLayoutId:k,layoutRefs:m,onLoad:p=>{if(!p.filters)return;let D=null;if(Array.isArray(p.filters)){let f=x||"default",W=p.filters.find(A=>A.scope===f);D=W?W.filters:null;}else D=p.filters;D&&(D.values||D.visibleFields?(D.visibleFields&&Array.isArray(D.visibleFields)&&c(D.visibleFields),D.values&&t(D.values)):t(D)),a&&a(p);},variantService:g,currentVariantId:s}):jsxRuntime.jsx(bt,{variants:i,currentVariantId:s,onLoad:a,onSave:p=>{l&&l({...p,filters:{values:o,visibleFields:b}});},onDelete:n,onSetDefault:u}),jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsxRuntime.jsx(material.Tooltip,{title:"Add Filters",children:jsxRuntime.jsx(material.Button,{onClick:p=>r(p.currentTarget),size:"small",color:"primary",startIcon:jsxRuntime.jsx(Br__default.default,{fontSize:"small"}),sx:{textTransform:"none",fontSize:Z},children:"Adapt Filters"})}),jsxRuntime.jsx(material.Button,{variant:"contained",size:"small",onClick:v,disabled:w,sx:{minWidth:"40px",fontWeight:"bold"},children:w?"...":"Go"}),jsxRuntime.jsxs(material.Menu,{anchorEl:I,open:!!I,onClose:()=>r(null),slotProps:{paper:{style:{maxHeight:400,width:"25ch"}}},children:[jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.ListItemText,{primary:"Visible Filters"})}),jsxRuntime.jsx(material.Divider,{}),e.map(p=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>M(p.id),children:[jsxRuntime.jsx(material.Checkbox,{checked:b.includes(p.id),size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:p.label})]},p.id))]})]})]}),jsxRuntime.jsx(material.Collapse,{in:y,children:jsxRuntime.jsx(material.Box,{sx:{px:2,pb:2},children:jsxRuntime.jsx(material.Grid,{container:true,spacing:2,columns:{xs:2,sm:3,md:4,lg:6},children:e.filter(p=>b.includes(p.id)).map(p=>jsxRuntime.jsx(material.Grid,{size:1,children:jsxRuntime.jsx(Hr,{field:p,value:o[p.id]||{value:"",operator:p.type==="number"?"=":"equals"},onChange:D=>C(p.id,D)})},p.id))})})}),jsxRuntime.jsx(material.Box,{sx:{position:"absolute",bottom:0,left:"50%",transform:"translate(-50%, 50%)",zIndex:10},children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:()=>d(!y),sx:{bgcolor:"background.paper",boxShadow:2,border:"1px solid",borderColor:"divider",width:20,height:20,minHeight:0,p:0,"&:hover":{bgcolor:"background.paper"}},children:y?jsxRuntime.jsx(Lr__default.default,{sx:{fontSize:16},color:"action"}):jsxRuntime.jsx(va__default.default,{sx:{fontSize:16},color:"action"})})})]})};var bn=({layouts:e,currentLayoutId:o,onLoad:t,onSave:i,onDelete:s,onSetDefault:a})=>{let[l,n]=bo.useState(null),[u,v]=bo.useState(false),[w,S]=bo.useState(""),[x,P]=bo.useState(""),[k,m]=bo.useState({isDefault:false,isPublic:false}),g=e.find(c=>c.id===o),y=c=>{n(c.currentTarget);},d=()=>{n(null);},I=c=>{t(c),d();},r=()=>{S(""),P(""),m({isDefault:false,isPublic:false}),v(true),d();},b=()=>{w.trim()&&(i({name:w,description:x,...k}),v(false));};return jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsxRuntime.jsx(material.Tooltip,{title:"Save Layout",children:jsxRuntime.jsx(material.IconButton,{onClick:r,color:"primary",size:"small",children:jsxRuntime.jsx(yn__default.default,{})})}),jsxRuntime.jsx(material.Tooltip,{title:"Layout Options",children:jsxRuntime.jsx(material.IconButton,{onClick:y,color:g?"primary":"default",children:jsxRuntime.jsx(Xr__default.default,{})})}),jsxRuntime.jsxs(material.Menu,{anchorEl:l,open:!!l,onClose:d,PaperProps:{sx:{width:320,maxHeight:400}},children:[jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.Typography,{variant:"caption",children:"Select Layout"})}),jsxRuntime.jsxs(material.MenuItem,{onClick:r,children:[jsxRuntime.jsx(material.ListItemIcon,{children:jsxRuntime.jsx(yn__default.default,{fontSize:"small"})}),jsxRuntime.jsx(material.ListItemText,{children:"Save Current Layout..."})]}),jsxRuntime.jsx(material.Divider,{}),e.length===0&&jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.Typography,{variant:"body2",color:"text.secondary",children:"No saved layouts"})}),e.map((c,C)=>jsxRuntime.jsx(material.MenuItem,{onClick:()=>I(c),selected:c.id===o,children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",width:"100%",justifyContent:"space-between"},children:[jsxRuntime.jsxs(material.Box,{sx:{display:"flex",flexDirection:"column",overflow:"hidden",mr:1},children:[jsxRuntime.jsx(material.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:jsxRuntime.jsx(material.Typography,{variant:"body2",fontWeight:c.id===o?"bold":"normal",noWrap:true,children:c.name})}),c.description&&jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",noWrap:true,children:c.description})]}),jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center"},onClick:M=>M.stopPropagation(),children:[jsxRuntime.jsx(material.Tooltip,{title:c.isDefault?"Remove Default":"Set as Default",children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:M=>{M.stopPropagation(),a(c.id);},children:c.isDefault?jsxRuntime.jsx(rr__default.default,{fontSize:"small",color:"warning"}):jsxRuntime.jsx(qr__default.default,{fontSize:"small"})})}),jsxRuntime.jsx(material.Tooltip,{title:"Delete",children:jsxRuntime.jsx(material.IconButton,{size:"small",color:"error",onClick:M=>{M.stopPropagation(),s(c.id);},children:jsxRuntime.jsx(Kr__default.default,{fontSize:"small"})})})]})]})},c.id||C))]}),jsxRuntime.jsxs(material.Dialog,{open:u,onClose:()=>v(false),maxWidth:"xs",fullWidth:true,children:[jsxRuntime.jsx(material.DialogTitle,{children:"Save Layout"}),jsxRuntime.jsx(material.DialogContent,{children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[jsxRuntime.jsx(material.TextField,{label:"Layout Name",value:w,onChange:c=>S(c.target.value),fullWidth:true,autoFocus:true,size:"small",helperText:"e.g., 'Compact View'"}),e.some(c=>c.name===w)&&jsxRuntime.jsx(material.Typography,{variant:"caption",color:"warning.main",sx:{ml:1},children:"Warning: Existing layout will be overwritten"}),jsxRuntime.jsx(material.TextField,{label:"Description",value:x,onChange:c=>P(c.target.value),fullWidth:true,size:"small"}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:k.isDefault,onChange:c=>m({...k,isDefault:c.target.checked})}),label:"Use as Default Layout"}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:k.isPublic,onChange:c=>m({...k,isPublic:c.target.checked})}),label:"Public (Visible to all users)"})]})}),jsxRuntime.jsxs(material.DialogActions,{children:[jsxRuntime.jsx(material.Button,{onClick:()=>v(false),children:"Cancel"}),jsxRuntime.jsx(material.Button,{onClick:b,variant:"contained",disabled:!w,children:"Save"})]})]})]})};var Zr="http://127.0.0.1:8515",Cn=({appId:e,tableKey:o="default",currentLayoutData:t,onLayoutLoad:i,targetLayoutId:s,activeLayoutId:a,serviceUrl:l=Zr,onError:n,onSuccess:u})=>{let[v,w]=bo.useState([]),[S,x]=bo.useState(""),P=r=>({id:r.layoutId,name:r.name,description:r.description??"",isDefault:!!r.isDefault,isPublic:!!r.isPublic,createdAt:r.createdAt??new Date().toISOString(),layoutData:r.layout??{}}),k=r=>({appId:e,tableKey:o,layoutId:r.id,name:r.name,description:r.description??"",isDefault:!!r.isDefault,isPublic:!!r.isPublic,createdAt:r.createdAt,layout:r.layoutData});bo.useEffect(()=>{a!==void 0&&x(a);},[a]),bo.useEffect(()=>{if(s&&v.length>0){let r=v.find(b=>b.id===s);r&&(x(r.id),i(r));}},[s,v,i]);let m=bo.useCallback(async()=>{if(e)try{let r=await fetch(`${l}/api/layouts?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!r.ok)throw new Error("Failed to fetch layouts");let c=(await r.json()).map(P);w(c);let C=c.find(M=>M.isDefault);C&&!S&&!s&&(x(C.id),i(C));}catch(r){console.error("Error fetching layouts",r),n&&n("Failed to load layouts");}},[e,o,l,n,S,i,s]);return bo.useEffect(()=>{m();},[e,o]),jsxRuntime.jsx(bn,{layouts:v,currentLayoutId:S,onLoad:r=>{x(r.id),i(r);},onSave:async r=>{try{let b=v.find(T=>T.name===r.name),c=b?b.id:Date.now().toString(),C={id:c,...r,createdAt:new Date().toISOString(),layoutData:t,isDefault:r.isDefault??!1,isPublic:r.isPublic??!1};if(!(await fetch(`${l}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k(C))})).ok)throw new Error("Failed to save layout");u&&u("Layout saved successfully"),await m(),x(c),i(C);}catch(b){console.error("Error saving layout",b),n&&n("Failed to save layout");}},onDelete:async r=>{try{if(!(await fetch(`${l}/api/layouts/${encodeURIComponent(r)}`,{method:"DELETE"})).ok)throw new Error("Failed to delete layout");S===r&&x(""),u&&u("Layout deleted successfully"),await m();}catch(b){console.error("Error deleting layout",b),n&&n("Failed to delete layout");}},onSetDefault:async r=>{try{let b=v.find(C=>C.id===r);if(!b)return;if(!(await fetch(`${l}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k({...b,isDefault:!0}))})).ok)throw new Error("Failed to set default layout");u&&u("Default layout set"),await m();}catch(b){console.error("Error setting default",b),n&&n("Failed to set default layout");}}})};function Sn(e,o,t){return o[t]<e[t]?-1:o[t]>e[t]?1:0}function ei(e,o){return e==="desc"?(t,i)=>Sn(t,i,o):(t,i)=>-Sn(t,i,o)}function ti(e,o){let t=e.map((i,s)=>[i,s]);return t.sort((i,s)=>{let a=o(i[0],s[0]);return a!==0?a:i[1]-s[1]}),t.map(i=>i[0])}var Tn=e=>{let o=bo.useCallback(h=>{let L=String(h?.label??h?.id??"").length*9+64,ee=typeof h?.minWidth=="number"?h.minWidth:0;return Math.max(100,ee,L)},[]),[t,i]=bo.useState(""),[s,a]=bo.useState(e.order||"asc"),[l,n]=bo.useState(e.orderBy||""),[u,v]=bo.useState(e.page||0),[w,S]=bo.useState(e.rowsPerPage||20),[x,P]=bo.useState(e.selected||[]),[k,m]=bo.useState(e.columns?e.columns.map(h=>h.id):[]),[g,y]=bo.useState(e.showSummary||false),[d,I]=bo.useState([]),[r,b]=bo.useState(new Set),[c,C]=bo.useState(()=>{let h={};return (e.columns||[]).forEach(E=>{h[E.id]=o(E);}),h}),[M,T]=bo.useState(null),[p,D]=bo.useState(null),[f,W]=bo.useState(null),[A,V]=bo.useState(null),[B,H]=bo.useState(false);bo.useEffect(()=>{e.order!==void 0&&a(e.order),e.orderBy!==void 0&&n(e.orderBy);},[e.order,e.orderBy]),bo.useEffect(()=>{e.selected!==void 0&&P(e.selected);},[e.selected]),bo.useEffect(()=>{e.page!==void 0&&v(e.page);},[e.page]),bo.useEffect(()=>{C(h=>{let E={...h};return (e.columns||[]).forEach(L=>{E[L.id]===void 0&&(E[L.id]=o(L));}),E});},[e.columns,o]);let z=bo.useMemo(()=>{let h=e.rows||[];return t&&(h=h.filter(E=>Object.keys(E).some(L=>String(E[L]).toLowerCase().includes(t.toLowerCase())))),h},[e.rows,t]),ke=bo.useMemo(()=>e.onSortChange||!l?z:ti(z,ei(s,l)),[z,s,l,e.onSortChange]),Me=bo.useCallback(h=>{if(d.length===0)return h.map(Y=>({type:"row",data:Y,id:Y[e.rowKey||"id"]}));let E=[...h].sort((Y,J)=>{for(let U of d){if(Y[U]<J[U])return -1;if(Y[U]>J[U])return 1}return 0}),L=(Y,J=0)=>{if(J>=d.length)return Y;let U=d[J],$={},le=[];return Y.forEach(se=>{let Ee=se[U],pe=`${U}:${Ee}`;$[pe]||($[pe]={key:pe,field:U,value:Ee,children:[],count:0,level:J},le.push($[pe])),$[pe].children.push(se),$[pe].count++;}),le.forEach(se=>{se.children&&(se.children=L(se.children,J+1));}),le},ee=L(E),O=(Y,J="")=>{let U=[];return Y.forEach($=>{if($.children){let le=J?`${J}>${$.key}`:$.key,se=r.has(le);U.push({type:"group",id:le,field:$.field,value:$.value,level:$.level,count:$.count,isExpanded:se,childIds:(function Ee(pe){let Be=[];return pe.children.forEach(Le=>{Le.children?Be=Be.concat(Ee(Le)):Be.push(Le[e.rowKey||"id"]);}),Be})($)}),se&&(U=U.concat(O($.children,le)));}else U.push({type:"row",data:$,id:$[e.rowKey||"id"],level:d.length});}),U};return O(ee)},[d,r,e.rowKey]),ie=bo.useMemo(()=>Me(ke),[ke,Me]),oe=bo.useMemo(()=>w>0?ie.slice(u*w,u*w+w):ie,[ie,u,w]),Oe=h=>{let E=new Set(r);E.has(h)?E.delete(h):E.add(h),b(E);},Et=h=>{Oe(h);},Ge=h=>{let E=new Set(r);Array.from(E).forEach(L=>{L.startsWith(h)&&E.delete(L);}),b(E);},Bt=h=>{h||b(new Set);},Lt=h=>{let E=l===h&&s==="asc",L=l===h&&s==="desc";if(e.onSortChange){E?e.onSortChange(h,"desc"):L?e.onSortChange("","asc"):e.onSortChange(h,"asc");return}E?(a("desc"),n(h)):L?(a("asc"),n("")):(a("asc"),n(h));},We=(h,E)=>{C(L=>({...L,[h]:E}));},nt=h=>{if(h.target.checked){let E=z.map(L=>L[e.rowKey||"id"]);P(E),e.onSelectionChange&&e.onSelectionChange(E);return}P([]),e.onSelectionChange&&e.onSelectionChange([]);},At=(h,E)=>{let L=E[e.rowKey||"id"],ee=x.indexOf(L),O=[];ee===-1?O=O.concat(x,L):ee===0?O=O.concat(x.slice(1)):ee===x.length-1?O=O.concat(x.slice(0,-1)):ee>0&&(O=O.concat(x.slice(0,ee),x.slice(ee+1))),P(O),e.onSelectionChange&&e.onSelectionChange(O);},at=h=>{v(h),e.onPageChange&&e.onPageChange(h);},rt=h=>{S(h),v(0),e.onRowsPerPageChange&&e.onRowsPerPageChange(h);},Ft=h=>{let E=k.indexOf(h),L=[...k];E===-1?L.push(h):L.splice(E,1),m(L);},Vt=h=>{let E=d.indexOf(h),L=[...d];E===-1?L.push(h):L.splice(E,1),I(L);},it=h=>{e.onLayoutSave&&e.onLayoutSave({visibleColumns:k,order:s,orderBy:l,grouping:d,columnWidths:c});},lt=h=>{h.layout&&(h.layout.visibleColumns&&m(h.layout.visibleColumns),h.layout.order&&a(h.layout.order),h.layout.orderBy&&n(h.layout.orderBy),h.layout.grouping&&I(h.layout.grouping),h.layout.columnWidths&&C(h.layout.columnWidths));};bo.useEffect(()=>{e.layout&&lt({layout:e.layout});},[e.layout]);let Nt=h=>{h.preventDefault(),V(A===null?{mouseX:h.clientX+2,mouseY:h.clientY-6}:null);},Ht=()=>{V(null);},zt=bo.useMemo(()=>{if(!g)return {};let h={};e.columns.forEach(L=>{if(L.numeric){let ee=z.reduce((O,Y)=>{let J=parseFloat(Y[L.id]);return O+(isNaN(J)?0:J)},0);h[L.id]=ee.toFixed(2);}else h[L.id]="";});let E=e.columns.find(L=>k.includes(L.id));return E&&!E.numeric&&(h[E.id]="Total"),h},[z,e.columns,g,k]),Ot=()=>{if(!e.columns||!z)return;let h=e.columns.map(Y=>Y.label).join(","),E=z.map(Y=>e.columns.map(J=>{let U=Y[J.id];return `"${(U==null?"":String(U)).replace(/"/g,'""')}"`}).join(",")).join(`
2
- `),L=`data:text/csv;charset=utf-8,${h}
3
- ${E}`,ee=encodeURI(L),O=document.createElement("a");O.setAttribute("href",ee),O.setAttribute("download",`${e.title||"export"}.csv`),document.body.appendChild(O),O.click(),document.body.removeChild(O);},st=()=>{H(true);},Gt=()=>{H(false);};return {isMobile:false,columns:e.columns,order:s,orderBy:l,filterText:t,setFilterText:i,visibleColumns:k,setVisibleColumns:m,showSummary:g,setShowSummary:y,summaryColumns:[],grouping:d,setGrouping:I,expandedGroups:r,setExpandedGroups:b,groupAnchorEl:p,setGroupAnchorEl:D,summaryAnchorEl:f,setSummaryAnchorEl:W,columnWidths:c,setColumnWidths:C,anchorEl:M,setAnchorEl:T,contextMenu:A,setContextMenu:V,sensors:void 0,sortedAndFilteredRows:ke,visibleRows:oe,summaryRow:zt,page:u,setPage:at,rowsPerPage:w,setRowsPerPage:rt,selected:x,setSelected:P,isAllExpanded:false,handleColumnResize:We,handleRequestSort:Lt,handleSelectAllClick:nt,handleClick:At,toggleSummaryColumn:()=>{},handleDragEnd:()=>{},handleExport:Ot,handleContextMenu:Nt,handleCloseContextMenu:Ht,toggleColumnVisibility:Ft,toggleGroupExpand:Oe,toggleGroupField:Vt,handleToggleAll:Bt,handleExpandGroupRecursively:Et,handleCollapseGroupRecursively:Ge,handleLayoutLoad:()=>{},handleVariantLoad:lt,handleLayoutSave:it,effectiveAppId:e.appId||"",currentLayoutData:{visibleColumns:k,order:s,orderBy:l,grouping:d,columnWidths:c},currentLayoutId:"",layoutIdToLoad:"",onPageChange:at,onRowsPerPageChange:rt,graphReportOpen:B,handleOpenGraphReport:st,handleCloseGraphReport:Gt}};var Ec=e=>jsxRuntime.jsx(ai__default.default,{...e}),Bc=e=>jsxRuntime.jsx(Do__default.default,{...e}),Lc=e=>jsxRuntime.jsx(wn__default.default,{...e}),Ac=e=>jsxRuntime.jsx(pa__default.default,{...e}),Fc=e=>jsxRuntime.jsx(ma__default.default,{...e}),kt=e=>{let{title:o="Data Table",selectionMode:t,selected:i=[],onSelectionChange:s,actions:a,extraTools:l,fitContainer:n=false,fullWidth:u=false,maxHeight:v,loading:w=false,page:S=0,rowsPerPage:x=20,rowsPerPageOptions:P=[20,50,100,-1],count:k=0,onPageChange:m,onRowsPerPageChange:g,onLayoutSave:y,filterConfig:d,rowKey:I,tableKey:r="default",graphReport:b}=e,{isMobile:c,columns:C,order:M,orderBy:T,filterText:p,setFilterText:D,visibleColumns:f,showSummary:W,setShowSummary:A,summaryColumns:V,grouping:B,setGrouping:H,expandedGroups:z,groupAnchorEl:ke,setGroupAnchorEl:Me,summaryAnchorEl:ie,setSummaryAnchorEl:oe,columnWidths:Oe,anchorEl:Et,setAnchorEl:Ge,contextMenu:Bt,sensors:Lt,sortedAndFilteredRows:We,summaryRow:nt,visibleRows:At,isAllExpanded:at,handleColumnResize:rt,handleRequestSort:Ft,handleSelectAllClick:Vt,handleClick:it,toggleSummaryColumn:lt,handleDragEnd:Nt,handleExport:Ht,handleContextMenu:zt,handleCloseContextMenu:Ot,toggleColumnVisibility:st,toggleGroupExpand:Gt,toggleGroupField:h,handleToggleAll:E,handleExpandGroupRecursively:L,handleCollapseGroupRecursively:ee,handleLayoutLoad:O,handleVariantLoad:Y,handleLayoutSave:J,effectiveAppId:U,currentLayoutData:$,currentLayoutId:le,layoutIdToLoad:se,graphReportOpen:Ee,handleOpenGraphReport:pe,handleCloseGraphReport:Be}=Tn(e),Le=b?.enabled??false,{model:Wt}=Xo({rows:We,config:{...b,title:b?.title||`${o} Graphic Report`}}),Bn=Wt.table.columns.map(ct=>({id:ct.id,label:ct.label,align:ct.align||"left",minWidth:120,numeric:ct.align==="right"})),Ln=U?jsxRuntime.jsx(Cn,{appId:U,tableKey:r,currentLayoutData:$,onLayoutLoad:O,targetLayoutId:se,activeLayoutId:le,serviceUrl:(d?.variantService,void 0)}):null,ho=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Oo,{groupAnchorEl:ke,setGroupAnchorEl:Me,grouping:B,setGrouping:H,columns:C,toggleGroupField:h}),jsxRuntime.jsx(Go,{anchorEl:Et,setAnchorEl:Ge,columns:C,visibleColumns:f,toggleColumnVisibility:st}),jsxRuntime.jsx(Wo,{anchorEl:ie,setAnchorEl:oe,showSummary:W,setShowSummary:A,columns:C,summaryColumns:V,toggleSummaryColumn:lt}),jsxRuntime.jsx($o,{contextMenu:Bt,handleCloseContextMenu:Ot,columns:C,visibleColumns:f,toggleColumnVisibility:st})]});return c?jsxRuntime.jsxs(mo__default.default,{sx:{display:"flex",flexDirection:"column",gap:2,height:"100%"},children:[d&&jsxRuntime.jsx(qe,{fields:d.fields,filters:d.filters,onFilterChange:d.onFilterChange,onSearch:d.onSearch,variants:d.variants||[],currentVariantId:d.currentVariantId,onVariantLoad:d.onVariantLoad,onVariantSave:d.onVariantSave,onVariantDelete:d.onVariantDelete,onVariantSetDefault:d.onVariantSetDefault,appId:d.appId,tableKey:r,currentLayout:[{tableKey:r,layoutData:$}],variantService:d.variantService}),jsxRuntime.jsx(Ho,{title:o,loading:w,showSummary:W,setShowSummary:A,setAnchorEl:Ge,setSummaryAnchorEl:oe,filterText:p,setFilterText:D,sortedAndFilteredRows:We,selected:i,columns:C,visibleColumns:f,summaryRow:nt,handleClick:it,selectionMode:t}),ho]}):jsxRuntime.jsxs(mo__default.default,{sx:{width:u?"100%":"auto",mb:n?0:2,...n?{flex:1,display:"flex",flexDirection:"column",minHeight:0,height:"100%"}:{}},children:[d&&jsxRuntime.jsx(mo__default.default,{sx:{mb:2},children:jsxRuntime.jsx(qe,{fields:d.fields,filters:d.filters,onFilterChange:d.onFilterChange,onSearch:d.onSearch,variants:d.variants||[],currentVariantId:d.currentVariantId,onVariantLoad:Y,onVariantSave:d.onVariantSave,onVariantDelete:d.onVariantDelete,onVariantSetDefault:d.onVariantSetDefault,loading:w,appId:d.appId,tableKey:r,currentLayout:[{tableKey:r,layoutData:$}],currentLayoutId:le,layoutRefs:[{tableKey:r,layoutId:le}],variantService:d.variantService})}),jsxRuntime.jsxs(oi__default.default,{sx:{width:u?"100%":"auto",mb:n?0:2,display:"flex",flexDirection:"column",overflow:"hidden",...v?{height:v}:n?{flex:1,minHeight:0}:{}},children:[jsxRuntime.jsx(Ro,{filterText:p,setFilterText:D,onRowsPerPageChange:g,rowsPerPage:x,rowsPerPageOptions:P,page:S,count:k,onPageChange:m,actions:a,extraTools:l,grouping:B,setGroupAnchorEl:Me,showSummary:W,setShowSummary:A,setAnchorEl:Ge,setSummaryAnchorEl:oe,handleExport:Ht,onLayoutSave:y||d?.variantService&&d?.appId?J:void 0,loading:w,layoutManager:Ln,onOpenGraphReport:Le?pe:void 0}),jsxRuntime.jsx(wn__default.default,{sx:{flex:1,maxHeight:v||"calc(100vh - 320px)",overflowY:"auto",overflowX:"auto",position:"relative",minHeight:0},children:jsxRuntime.jsx(core.DndContext,{sensors:Lt,collisionDetection:core.closestCenter,onDragEnd:Nt,modifiers:[modifiers.restrictToHorizontalAxis],children:jsxRuntime.jsxs(ni__default.default,{sx:{minWidth:u?750:"auto",width:u?"100%":"auto",tableLayout:Object.keys(Oe).length>0?"fixed":"auto",borderCollapse:"separate",borderSpacing:0},"aria-labelledby":"tableTitle",size:"small",stickyHeader:true,children:[jsxRuntime.jsx(Bo,{columns:C,visibleColumns:f,order:M,orderBy:T,onRequestSort:Ft,onContextMenu:zt,selectionMode:t,grouping:B,isAllExpanded:at,handleToggleAll:E,rowCount:We.length,numSelected:i.length,onSelectAllClick:Vt,columnWidths:Oe,onColumnResize:rt}),jsxRuntime.jsx(Ao,{visibleRows:At,columns:C,visibleColumns:f,selectionMode:t,selected:i,orderBy:T,loading:w,expandedGroups:z,toggleGroupExpand:Gt,handleExpandGroupRecursively:L,handleCollapseGroupRecursively:ee,handleClick:it,onSelectionChange:s,grouping:B,rowKeyProp:I,page:S,rowsPerPage:x}),W&&jsxRuntime.jsx(Vo,{showSummary:W,columns:C,visibleColumns:f,summaryRow:nt,selectionMode:t?.toString(),orderBy:T,zIndex:3})]})})})]}),ho,Le&&jsxRuntime.jsx(Yo,{open:Ee,onClose:Be,model:Wt,tableContent:jsxRuntime.jsx(kt,{title:"Data Body",columns:Bn,rows:Wt.table.rows,rowKey:"id",fullWidth:true,maxHeight:"420px",rowsPerPage:20,rowsPerPageOptions:[20,50,100],graphReport:{enabled:false}})})]})},Vc=kt;var $c=({title:e,hideHeader:o=true,filterConfig:t,tableProps:i,children:s,spacing:a=1})=>jsxRuntime.jsxs(ko,{title:e,hideHeader:o,children:[jsxRuntime.jsxs(material.Stack,{spacing:a,sx:{height:"100%",overflow:"hidden"},children:[t&&jsxRuntime.jsx(material.Box,{sx:{flexShrink:0},children:jsxRuntime.jsx(qe,{...t})}),jsxRuntime.jsx(material.Box,{sx:{flex:1,minHeight:0,overflow:"hidden"},children:jsxRuntime.jsx(kt,{...i,fitContainer:true,filterConfig:void 0})})]}),s]});var Kc=({metadata:e,fetchData:o})=>{let[t,i]=bo.useState(false),[s,a]=bo.useState([]),[l,n]=bo.useState({}),[u,v]=bo.useState(e.variants||[]),[w,S]=bo.useState(e.layout||null),[x,P]=bo.useState(0),[k,m]=bo.useState(0),[g,y]=bo.useState(10),[d,I]=bo.useState([]),[r,b]=bo.useState("asc"),[c,C]=bo.useState("");bo.useEffect(()=>{let B={};e.filters.forEach(H=>{H.defaultValue!==void 0&&(B[H.id]=H.defaultValue);}),n(B);},[e.filters]);let M=bo.useCallback(async(B,H,z,ke,Me)=>{i(true);try{let ie={...B,page:H+1,limit:z,sort:Me,order:ke},oe;o?oe=await o(ie):typeof e.api=="function"?oe=await e.api(ie):e.api&&typeof e.api=="object"?(console.log("Fetching from URL:",e.api.url,ie),oe={rows:[],total:0}):(console.warn("No API configured for report"),oe={rows:[],total:0}),oe&&(a(oe.rows||[]),P(oe.total||0));}catch(ie){console.error("Failed to fetch report data",ie);}finally{i(false);}},[e.api,o]);bo.useEffect(()=>{M(l,k,g,r,c);},[M,k,g,r,c]);let T=()=>{m(0),M(l,0,g,r,c);},p=(B,H)=>{b(H),C(B);},D=B=>{n(B);},f=B=>{if(B.filters){let H=B.filters.find(z=>z.scope==="default"||z.scope===e.id);H&&(n(H.filters),M(H.filters,0,g));}B.layout&&S(B.layout);},W=B=>{let H={...B,id:Date.now().toString(),createdAt:new Date().toISOString()};v(z=>[...z,H]);},A=B=>{S(B);};return {pageProps:{title:e.title,filterConfig:{appId:e.id,fields:e.filters,filters:l,onFilterChange:D,onSearch:T,onVariantLoad:f,onVariantSave:W,onVariantDelete:B=>v(H=>H.filter(z=>z.id!==B)),onVariantSetDefault:B=>{v(H=>H.map(z=>({...z,isDefault:z.id===B})));},variants:u},tableProps:{appId:e.id,columns:e.columns,rows:s,loading:t,rowKey:"id",count:x,page:k,rowsPerPage:g,rowsPerPageOptions:[10,25,50,100],onPageChange:m,onRowsPerPageChange:y,selectionMode:"multiple",selected:d,onSelectionChange:I,onLayoutSave:A,layout:w,title:e.title,showSummary:true,order:r,orderBy:c,onSortChange:p,graphReport:e.graphReport||{enabled:true,title:`${e.title} Graphic Report`}}},filters:l,rows:s,loading:t,refresh:T}};var Rn=64,Mi="#E9EDF2",Ri="linear-gradient(90deg, #F5F7FA 0%, #E9EDF2 50%, #F5F7FA 100%)",Dn=({appTitle:e,logo:o,mode:t="dark",onToggleMode:i,localeLabel:s="EN",searchPlaceholder:a="Ask me...",onSearch:l,user:n,leftSlot:u,rightSlot:v})=>{let S=material.useTheme().palette.mode==="dark",[x,P]=bo.useState(""),k=y=>{y.preventDefault(),l&&l(x.trim());},m=t==="system"?jsxRuntime.jsx(wi__default.default,{fontSize:"small"}):t==="dark"?jsxRuntime.jsx(Ii__default.default,{fontSize:"small"}):jsxRuntime.jsx(ki__default.default,{fontSize:"small"}),g=t==="system"?"Theme: System":t==="dark"?"Theme: Dark":"Theme: Light";return jsxRuntime.jsx(material.AppBar,{position:"sticky",elevation:0,sx:y=>({top:0,zIndex:y.zIndex.drawer+10,height:Rn,backgroundColor:y.palette.mode==="dark"?"#0D0D0D":Mi,backgroundImage:y.palette.mode==="dark"?["radial-gradient(circle at 18% 22%, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0) 45%)","radial-gradient(circle at 78% 32%, rgba(144,202,249,0.14) 0%, rgba(144,202,249,0) 42%)","linear-gradient(90deg, #0A0A0A 0%, #151515 50%, #0A0A0A 100%)","linear-gradient(rgba(255,255,255,0.04) 1px, transparent 1px)","linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px)"].join(","):["radial-gradient(circle at 22% 22%, rgba(255,255,255,0.7) 0%, rgba(255,255,255,0) 48%)","radial-gradient(circle at 76% 24%, rgba(203,213,225,0.45) 0%, rgba(203,213,225,0) 42%)",Ri,"linear-gradient(rgba(15,23,42,0.05) 1px, transparent 1px)","linear-gradient(90deg, rgba(15,23,42,0.04) 1px, transparent 1px)"].join(","),backgroundSize:"auto, auto, auto, 24px 24px, 24px 24px",borderBottom:"1px solid",borderColor:y.palette.mode==="dark"?"rgba(255,255,255,0.12)":"rgba(15,23,42,0.12)"}),children:jsxRuntime.jsxs(material.Toolbar,{sx:{minHeight:`${Rn}px !important`,px:2,gap:2},children:[jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:1.5,sx:{minWidth:220},children:[o||jsxRuntime.jsx(material.Box,{component:"img",src:"/orbcafe.png",alt:"ORBCAFE Logo",sx:{width:44,height:44,display:"block",objectFit:"contain",flexShrink:0}}),e&&jsxRuntime.jsx(material.Typography,{variant:"h6",sx:{fontWeight:700,color:S?"common.white":"#111827"},children:e}),u]}),jsxRuntime.jsx(material.Box,{sx:{flex:1,display:"flex",justifyContent:"center",minWidth:0},children:jsxRuntime.jsx(material.Box,{component:"form",onSubmit:k,sx:{width:"100%",maxWidth:540},children:jsxRuntime.jsx(material.TextField,{size:"small",fullWidth:true,value:x,onChange:y=>P(y.target.value),placeholder:a,InputProps:{startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(cn__default.default,{sx:{color:S?"rgba(255,255,255,0.7)":"rgba(15,23,42,0.55)",fontSize:18}})}),sx:{color:S?"common.white":"rgba(17,24,39,0.9)",bgcolor:S?"rgba(255,255,255,0.08)":"#ffffff",borderRadius:999,"& .MuiOutlinedInput-notchedOutline":{borderColor:S?"rgba(255,255,255,0.15)":"rgba(15,23,42,0.2)"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:S?"rgba(255,255,255,0.35)":"rgba(15,23,42,0.35)"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:S?"rgba(255,255,255,0.5)":"rgba(15,23,42,0.55)"}}},inputProps:{style:{color:S?"white":"#111827"}}})})}),jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:1.5,children:[jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:.5,children:[jsxRuntime.jsx(Ti__default.default,{sx:{color:S?"common.white":"#111827",fontSize:18}}),jsxRuntime.jsx(material.Typography,{variant:"caption",sx:{color:S?"common.white":"#111827",fontWeight:500},children:s})]}),jsxRuntime.jsx(material.IconButton,{size:"small",sx:{color:S?"common.white":"#111827"},onClick:i,title:g,children:m}),n&&jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:1,children:[jsxRuntime.jsx(material.Box,{sx:{textAlign:"right"},children:jsxRuntime.jsx(material.Typography,{variant:"body2",sx:{color:S?"common.white":"#111827",fontWeight:600,lineHeight:1.2},children:n.name})}),jsxRuntime.jsx(material.Avatar,{src:n.avatarSrc,imgProps:{style:{objectFit:"cover"}},sx:{width:34,height:34,bgcolor:"grey.100",color:"grey.700",fontSize:"0.85rem"},children:n.avatarText||n.name.slice(0,1).toUpperCase()})]}),v]})]})})};var Pn=({menuData:e=[],initialNavigationCollapsed:o=false}={})=>{let{navigationIslandProps:t}=Io({initialCollapsed:o,content:e}),[i,s]=bo.useState(900);bo.useEffect(()=>{let l=()=>s(window.innerHeight);return l(),window.addEventListener("resize",l),()=>window.removeEventListener("resize",l)},[]);let a=bo.useMemo(()=>Math.max(280,i-100),[i]);return {navigationIslandProps:t,navigationMaxHeight:a}};var md=({appTitle:e,menuData:o=[],children:t,showNavigation:i=true,localeLabel:s,user:a,logo:l,onSearch:n,rightHeaderSlot:u,leftHeaderSlot:v,contentSx:w})=>{let[S,x]=bo.useState("system"),[P,k]=bo.useState("light"),[m,g]=bo.useState(false),y=S==="system"?m?P:"light":S;bo.useEffect(()=>{g(true);let b=window.matchMedia("(prefers-color-scheme: dark)"),c=()=>{k(b.matches?"dark":"light");};return c(),b.addEventListener("change",c),()=>b.removeEventListener("change",c)},[]);let d=bo.useMemo(()=>material.createTheme({palette:{mode:y}}),[y]),{navigationIslandProps:I,navigationMaxHeight:r}=Pn({menuData:o,initialNavigationCollapsed:false});return jsxRuntime.jsx(material.ThemeProvider,{theme:d,children:jsxRuntime.jsxs(material.Box,{sx:b=>({minHeight:"100vh",display:"flex",flexDirection:"column",background:b.palette.mode==="dark"?"linear-gradient(180deg, #0A0A0A 0%, #141414 55%, #1A1A1A 100%)":b.palette.background.default}),children:[jsxRuntime.jsx(Dn,{appTitle:e,logo:l,mode:S,onToggleMode:()=>x(b=>b==="system"?"dark":b==="dark"?"light":"system"),localeLabel:s,user:a,onSearch:n,leftSlot:v,rightSlot:u}),jsxRuntime.jsxs(material.Box,{sx:{flex:1,minHeight:0,display:"flex"},children:[i&&jsxRuntime.jsx(material.Box,{sx:{p:1.5,display:"flex",alignItems:"flex-start",flexShrink:0},children:jsxRuntime.jsx(To,{...I,maxHeight:r,colorMode:y})}),jsxRuntime.jsx(material.Box,{sx:{flex:1,minWidth:0,minHeight:0,overflow:"auto",p:1.5,...w},children:t})]})]})})};exports.Button=_t;exports.CAppHeader=Dn;exports.CAppPageLayout=md;exports.CLayoutManagement=bn;exports.CLayoutManager=Cn;exports.CPageLayout=ko;exports.CSmartFilter=qe;exports.CSmartTable=Vc;exports.CStandardPage=$c;exports.CTable=kt;exports.CTableBody=Ec;exports.CTableCell=Bc;exports.CTableContainer=Lc;exports.CTableHead=Ac;exports.CTableRow=Fc;exports.CVariantManagement=bt;exports.CVariantManager=nn;exports.NavigationIsland=To;exports.TreeMenu=Ut;exports.buttonVariants=Hn;exports.useNavigationIsland=Io;exports.usePageLayout=Pn;exports.useStandardReport=Kc;
1
+ 'use strict';var So=require('react'),navigation=require('next/navigation'),lucideReact=require('lucide-react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),reactSlot=require('@radix-ui/react-slot'),classVarianceAuthority=require('class-variance-authority'),jsxRuntime=require('react/jsx-runtime'),material=require('@mui/material'),bo=require('@mui/material/Box'),si=require('@mui/material/Paper'),ci=require('@mui/material/Table'),di=require('@mui/material/TableBody'),Bo=require('@mui/material/TableCell'),Rn=require('@mui/material/TableContainer'),xa=require('@mui/material/TableHead'),Ca=require('@mui/material/TableRow'),core=require('@dnd-kit/core'),modifiers=require('@dnd-kit/modifiers'),mn=require('@mui/icons-material/Search'),da=require('@mui/icons-material/ViewColumn'),vn=require('@mui/icons-material/Save'),pa=require('@mui/icons-material/Download'),ma=require('@mui/icons-material/AccountTree'),ga=require('@mui/icons-material/Functions'),fa=require('@mui/icons-material/Insights'),va=require('@mui/material/Checkbox'),Sa=require('@mui/material/TableSortLabel'),Ma=require('@mui/icons-material/KeyboardArrowRight'),Ra=require('@mui/icons-material/KeyboardArrowDown'),Oa=require('@mui/icons-material/Check'),Ga=require('@mui/icons-material/ClearAll'),Qa=require('@mui/icons-material/Close'),zr=require('@mui/icons-material/Settings'),Or=require('@mui/icons-material/KeyboardArrowUp'),Wr=require('@mui/icons-material/ArrowRightAlt'),pr=require('@mui/icons-material/Star'),DateCalendar=require('@mui/x-date-pickers/DateCalendar'),PickersDay=require('@mui/x-date-pickers/PickersDay'),Mr=require('@mui/icons-material/CalendarMonth'),Rr=require('@mui/icons-material/Clear'),Dr=require('@mui/icons-material/ArrowForward'),Ee=require('dayjs'),Pr=require('dayjs/plugin/isBetween'),ei=require('@mui/icons-material/Delete'),oi=require('@mui/icons-material/StarBorder'),ni=require('@mui/icons-material/ViewQuilt'),Ri=require('@mui/icons-material/Language'),Di=require('@mui/icons-material/DesktopWindows'),Pi=require('@mui/icons-material/DarkMode'),Ei=require('@mui/icons-material/LightMode'),Bi=require('@mui/icons-material/Logout');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var So__namespace=/*#__PURE__*/_interopNamespace(So);var bo__default=/*#__PURE__*/_interopDefault(bo);var si__default=/*#__PURE__*/_interopDefault(si);var ci__default=/*#__PURE__*/_interopDefault(ci);var di__default=/*#__PURE__*/_interopDefault(di);var Bo__default=/*#__PURE__*/_interopDefault(Bo);var Rn__default=/*#__PURE__*/_interopDefault(Rn);var xa__default=/*#__PURE__*/_interopDefault(xa);var Ca__default=/*#__PURE__*/_interopDefault(Ca);var mn__default=/*#__PURE__*/_interopDefault(mn);var da__default=/*#__PURE__*/_interopDefault(da);var vn__default=/*#__PURE__*/_interopDefault(vn);var pa__default=/*#__PURE__*/_interopDefault(pa);var ma__default=/*#__PURE__*/_interopDefault(ma);var ga__default=/*#__PURE__*/_interopDefault(ga);var fa__default=/*#__PURE__*/_interopDefault(fa);var va__default=/*#__PURE__*/_interopDefault(va);var Sa__default=/*#__PURE__*/_interopDefault(Sa);var Ma__default=/*#__PURE__*/_interopDefault(Ma);var Ra__default=/*#__PURE__*/_interopDefault(Ra);var Oa__default=/*#__PURE__*/_interopDefault(Oa);var Ga__default=/*#__PURE__*/_interopDefault(Ga);var Qa__default=/*#__PURE__*/_interopDefault(Qa);var zr__default=/*#__PURE__*/_interopDefault(zr);var Or__default=/*#__PURE__*/_interopDefault(Or);var Wr__default=/*#__PURE__*/_interopDefault(Wr);var pr__default=/*#__PURE__*/_interopDefault(pr);var Mr__default=/*#__PURE__*/_interopDefault(Mr);var Rr__default=/*#__PURE__*/_interopDefault(Rr);var Dr__default=/*#__PURE__*/_interopDefault(Dr);var Ee__default=/*#__PURE__*/_interopDefault(Ee);var Pr__default=/*#__PURE__*/_interopDefault(Pr);var ei__default=/*#__PURE__*/_interopDefault(ei);var oi__default=/*#__PURE__*/_interopDefault(oi);var ni__default=/*#__PURE__*/_interopDefault(ni);var Ri__default=/*#__PURE__*/_interopDefault(Ri);var Di__default=/*#__PURE__*/_interopDefault(Di);var Pi__default=/*#__PURE__*/_interopDefault(Pi);var Ei__default=/*#__PURE__*/_interopDefault(Ei);var Bi__default=/*#__PURE__*/_interopDefault(Bi);function le(...e){return tailwindMerge.twMerge(clsx.clsx(e))}var Kt={primary:"#000000",primaryHover:"#333333"},pt={primary:"bg-primary text-primary-foreground hover:bg-primary/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",ghost:"hover:bg-accent hover:text-accent-foreground"},_e={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",full:"rounded-full"},vo=()=>"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50";var Un=classVarianceAuthority.cva(vo(),{variants:{variant:{default:`${pt.primary} shadow-sm`,destructive:"bg-red-500 text-white hover:bg-red-600 active:bg-red-700 dark:bg-red-600 dark:hover:bg-red-500 dark:active:bg-red-700 shadow-sm",outline:`${pt.outline} shadow-sm`,secondary:"bg-gray-200 text-gray-700 hover:bg-gray-300 active:bg-gray-400 dark:bg-gray-700 dark:text-gray-200 dark:hover:bg-gray-600 dark:active:bg-gray-500 shadow-sm",ghost:pt.ghost,link:"text-blue-600 dark:text-blue-400 underline-offset-4 hover:underline hover:text-blue-700 dark:hover:text-blue-300 active:text-blue-800 dark:active:text-blue-200","chat-tool":"bg-[var(--orbai-surface-2)] border border-[var(--orbai-border-soft)] text-[var(--orbai-text-2)] hover:bg-[var(--orbai-surface-3)] hover:border-[var(--orbai-border-strong)] hover:text-[var(--orbai-text-1)] active:scale-95 transition-all duration-200","chat-send":`bg-[${Kt.primary}] hover:bg-[${Kt.primaryHover}] text-white border border-[var(--orbai-border-strong)] shadow-[var(--orbai-shadow-soft-sm)] hover:shadow-[var(--orbai-shadow-soft-md)] active:scale-95 transition-all duration-200`,"chat-stop":"bg-red-500 hover:bg-red-600 border border-[var(--orbai-border-strong)] shadow-[var(--orbai-shadow-soft-sm)] hover:shadow-[var(--orbai-shadow-soft-md)] active:scale-95 text-white transition-all duration-200","chat-disabled":"cursor-not-allowed opacity-50 bg-[var(--orbai-surface-2)] border border-[var(--orbai-border-soft)] text-[var(--orbai-muted)]"},size:{default:"h-10 px-4 py-2",sm:"h-9 px-3",lg:"h-11 px-8",icon:"h-10 w-10","chat-sm":"h-8 w-8 rounded-full","chat-md":"h-10 w-10 rounded-full","chat-lg":"h-12 w-12 rounded-full"},rounded:{none:_e.none,sm:_e.sm,md:_e.md,full:_e.full}},defaultVariants:{variant:"default",size:"default",rounded:"md"}}),Yt=So__namespace.forwardRef(({className:e,variant:o,size:t,asChild:r=false,...l},n)=>jsxRuntime.jsx(r?reactSlot.Slot:"button",{className:le(Un({variant:o,size:t,className:e})),ref:n,...l}));Yt.displayName="Button";function Xt({items:e,onItemClick:o,className:t="",level:r=0,expandedIds:l,onToggleExpand:n,colorMode:i="light"}){let a=i==="dark",d=navigation.usePathname(),[T,k]=So.useState(new Set),w=l!==void 0&&n!==void 0,C=w?l:T,E=m=>{if(w)n(m);else {let f=new Set(T);f.has(m)?f.delete(m):f.add(m),k(f);}},M=m=>{m.children&&m.children.length>0&&E(m.id),o&&o(m);};return !e||!Array.isArray(e)?jsxRuntime.jsx("div",{className:le("tree-menu",t),children:jsxRuntime.jsx("div",{className:"text-sm text-gray-500 p-2",children:"No items to display"})}):jsxRuntime.jsx("div",{className:le("tree-menu",t),children:e.map(m=>{let f=C.has(m.id)||m.isExpanded,S=m.children&&m.children.length>0,y=m.appurl||m.href,g=y?d===y:false;return jsxRuntime.jsxs("div",{className:"tree-menu-item relative",children:[g&&jsxRuntime.jsx("div",{className:le("absolute left-0 top-2 bottom-2 w-[3px] rounded-r-full z-10",a?"bg-[#90caf9]":"bg-[#1976d2]")}),jsxRuntime.jsxs(Yt,{variant:"ghost",className:le("w-full justify-start gap-2 h-auto py-2 relative overflow-hidden group",`ml-${r*4}`,g?a?"bg-transparent text-[#90caf9] hover:bg-gray-800/35":"bg-transparent text-[#1976d2] hover:bg-gray-100/60":a?"hover:bg-gray-800/50 text-gray-300":"hover:bg-gray-100/50 text-gray-700"),onClick:()=>M(m),children:[S&&jsxRuntime.jsx("div",{className:le("flex-shrink-0 transition-transform duration-200",f&&"rotate-90",g?a?"text-[#90caf9]":"text-[#1976d2]":a?"text-gray-500 group-hover:text-gray-300":"text-gray-400 group-hover:text-gray-600"),children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-4 w-4"})}),!S&&jsxRuntime.jsx("div",{className:"w-4 h-4 flex-shrink-0"}),m.icon&&jsxRuntime.jsx("div",{className:le("flex-shrink-0 transition-colors duration-200",g?a?"text-[#90caf9]":"text-[#1976d2]":a?"text-gray-500 group-hover:text-gray-300":"text-gray-400 group-hover:text-gray-600"),children:m.icon}),jsxRuntime.jsxs("div",{className:"flex-1 text-left overflow-hidden z-10",children:[jsxRuntime.jsx("div",{className:le("text-sm truncate transition-colors duration-200",g?"font-semibold":"font-medium"),children:m.title||m.label}),m.description&&jsxRuntime.jsx("div",{className:le("text-xs truncate transition-colors duration-200",g?a?"text-[#90caf9]/70":"text-[#1976d2]/75":a?"text-gray-400":"text-gray-500"),title:m.description,children:m.description})]})]}),S&&jsxRuntime.jsx("div",{className:le("grid transition-[grid-template-rows] duration-300 ease-in-out",f?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:jsxRuntime.jsx("div",{className:"overflow-hidden",children:jsxRuntime.jsx(Xt,{items:m.children,onItemClick:o,level:r+1,expandedIds:l,onToggleExpand:n,colorMode:i})})})]},m.id)})})}var Mo=({collapsed:e,onToggle:o,className:t="",maxHeight:r,menuData:l=[],colorMode:n="light"})=>{let i=n==="dark",a=navigation.useRouter(),[d,T]=So.useState(""),[k,w]=So.useState(new Set);So.useEffect(()=>{e&&w(new Set);},[e]);let C=So.useCallback(f=>{let S=[],y=g=>{g.forEach(p=>{S.push(p.id),p.children&&y(p.children);});};return y(f),S},[]),E=So.useMemo(()=>{if(!d.trim())return l;let f=S=>S.reduce((y,g)=>{let p=g.title?.toLowerCase().includes(d.toLowerCase())||g.description?.toLowerCase().includes(d.toLowerCase()),I=g.children?f(g.children):[];return (p||I.length>0)&&y.push({...g,children:I.length>0?I:g.children}),y},[]);return f(l)},[d,l]),M=So.useMemo(()=>d.trim()?new Set(C(l)):k,[d,l,k,C]),m=So.useCallback(async f=>{if(console.log("\u{1F5B1}\uFE0F \u5BFC\u822A\u83DC\u5355\u9879\u70B9\u51FB:",f),f.id==="chat"||f.appurl==="/chat"){console.log("\u{1F4AC} \u68C0\u6D4B\u5230chat\u83DC\u5355\u70B9\u51FB\uFF0C\u8DF3\u8F6C\u5230\u65B0\u7684\u804A\u5929\u89C6\u56FE");try{a.push("/chat?new=true");}catch(y){console.error("\u274C \u65E0\u6CD5\u8DF3\u8F6C\u5230\u65B0\u804A\u5929\u89C6\u56FE:",y),a.push("/chat");}return}let S=f.appurl||f.href;S&&(S.startsWith("http://")||S.startsWith("https://")?window.open(S,"_blank"):a.push(S));},[a]);return jsxRuntime.jsxs("div",{className:`flex flex-col backdrop-blur-xl border shadow-[0_4px_8px_0_rgba(31,38,135,0.1)] ${e?"w-14 rounded-full":"w-[234px] rounded-2xl"} relative ${t} ${i?"bg-[#111111] border-white/10":"bg-white/70 border-white/30"}`,style:{backdropFilter:"blur(16px) saturate(180%)",WebkitBackdropFilter:"blur(16px) saturate(180%)",transition:"width 400ms cubic-bezier(0.4, 0.0, 0.2, 1), border-radius 0ms cubic-bezier(0.4, 0.0, 0.2, 1), box-shadow 400ms ease-out",maxHeight:r?`${r}px`:void 0},children:[jsxRuntime.jsx("div",{className:`pt-4 pb-2 transition-all duration-500 ease-in-out ${e?"px-1":"px-2"}`,children:e?jsxRuntime.jsx("div",{className:"flex justify-center",children:jsxRuntime.jsx("button",{onClick:o,className:`w-10 h-10 flex items-center justify-center rounded-lg transition-colors duration-200 ${i?"text-gray-300 hover:bg-gray-800":"text-gray-500 hover:bg-gray-50"}`,title:"\u5C55\u5F00\u5BFC\u822A",children:jsxRuntime.jsx(lucideReact.Search,{className:"h-5 w-5"})})}):jsxRuntime.jsxs("div",{className:`relative transition-opacity duration-300 ${e?"opacity-0":"opacity-100 delay-200"}`,children:[jsxRuntime.jsx("input",{type:"text",placeholder:"\u641C\u7D22\u83DC\u5355...",value:d,onChange:f=>T(f.target.value),className:`w-full pl-10 pr-4 py-2 text-sm border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent ${i?"border-gray-700 bg-[#1A1A1A] text-white placeholder-gray-400":"border-gray-300 bg-white text-gray-900 placeholder-gray-500"}`}),jsxRuntime.jsx("div",{className:"absolute left-3 top-1/2 transform -translate-y-1/2 pointer-events-none",children:jsxRuntime.jsx(lucideReact.Search,{className:`h-4 w-4 ${i?"text-gray-500":"text-gray-400"}`})})]})}),jsxRuntime.jsx("nav",{className:`flex-1 pb-4 transition-all duration-500 ease-in-out overflow-y-auto min-h-0 ${e?"px-1":"px-2"}`,children:E.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-gray-500 text-sm",children:e?"\u{1F4C2}":d?"\u672A\u627E\u5230\u5339\u914D\u7684\u83DC\u5355\u9879":"\u6682\u65E0\u53EF\u8BBF\u95EE\u7684\u5E94\u7528"}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[!e&&jsxRuntime.jsx("div",{className:`transition-opacity duration-300 ${e?"opacity-0":"opacity-100 delay-200"}`,children:jsxRuntime.jsx(Xt,{items:E,onItemClick:m,className:"space-y-1",expandedIds:M,colorMode:n,onToggleExpand:f=>{let S=new Set(k);E.some(g=>g.id===f)?S.has(f)?S.delete(f):(E.forEach(g=>{g.id!==f&&S.has(g.id)&&S.delete(g.id);}),S.add(f)):S.has(f)?S.delete(f):S.add(f),w(S);}})}),e&&jsxRuntime.jsx("div",{className:"space-y-2",children:l.map(f=>jsxRuntime.jsx("div",{className:"space-y-1",children:jsxRuntime.jsx("button",{onClick:()=>{o();let S=new Set([f.id]);w(S);},className:`w-full flex items-center justify-center p-2 rounded-lg cursor-pointer transition-colors duration-200 ${i?"text-gray-400 hover:bg-gray-800":"text-gray-600 hover:bg-gray-50"}`,title:`\u5C55\u5F00\u67E5\u770B ${f.title}`,children:f.icon||jsxRuntime.jsx("div",{className:`w-6 h-6 rounded text-xs flex items-center justify-center font-medium ${i?"bg-[#90caf9] text-[#0b0b0b]":"bg-[#1976d2] text-white"}`,children:f.title?.charAt(0)||"?"})})},f.id))})]})}),!e&&jsxRuntime.jsx("button",{onClick:o,className:`absolute -bottom-1 -right-1 w-6 h-6 bg-transparent rounded-full flex items-center justify-center transition-all duration-300 ease-in-out z-20 ${i?"hover:bg-gray-800/50":"hover:bg-white/20"}`,title:"\u6298\u53E0\u5BFC\u822A",children:jsxRuntime.jsx("div",{className:"absolute",style:{bottom:"0px",right:"0px",width:"16px",height:"16px",overflow:"hidden"},children:jsxRuntime.jsx("div",{className:i?"border-yellow-400":"",style:{width:"32px",height:"32px",borderRadius:"16px",border:"3px solid #21BCFF",backgroundColor:"transparent",position:"absolute",top:"-16px",left:"-16px"}})})})]})};var Do=(e={})=>{let{initialCollapsed:o=false,content:t=[]}=e,[r,l]=So.useState(o),[n,i]=So.useState(t),a=So.useCallback(()=>{l(T=>!T);},[]),d=So.useMemo(()=>({collapsed:r,onToggle:a,menuData:n}),[r,a,n]);return {collapsed:r,setCollapsed:l,toggleCollapsed:a,menuData:n,setMenuData:i,navigationIslandProps:d}};var Po=({title:e,hideHeader:o,children:t})=>jsxRuntime.jsxs(material.Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[!o&&jsxRuntime.jsx(material.Box,{sx:{mb:2},children:jsxRuntime.jsx(material.Typography,{variant:"h4",children:e})}),jsxRuntime.jsx(material.Box,{sx:{flex:1,overflow:"hidden"},children:t})]});var Lo=e=>{let o="0.75rem",t=Array.isArray(e.actions)?e.actions:e.actions?[e.actions]:[],r=Array.isArray(e.extraTools)?e.extraTools:e.extraTools?[e.extraTools]:[],l=[...t,...r];return jsxRuntime.jsxs(material.Toolbar,{sx:{pl:{sm:2},pr:{xs:1,sm:1},alignItems:"center",gap:1},children:[jsxRuntime.jsx(material.TextField,{size:"small",placeholder:"Search...",value:e.filterText,onChange:n=>e.setFilterText(n.target.value),InputProps:{sx:{fontSize:o,"& .MuiInputBase-input":{fontSize:o},"& .MuiInputBase-input::placeholder":{fontSize:o,opacity:1}},startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(mn__default.default,{fontSize:"small"})})},sx:{width:300}}),jsxRuntime.jsx(material.Box,{sx:{flex:1}}),jsxRuntime.jsxs(material.Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsxRuntime.jsx(material.Box,{sx:{width:1,height:20,bgcolor:"divider",mr:.5}}),jsxRuntime.jsx(material.Tooltip,{title:"Group By",children:jsxRuntime.jsx(material.IconButton,{onClick:n=>e.setGroupAnchorEl(n.currentTarget),children:jsxRuntime.jsx(material.Badge,{badgeContent:e.grouping?.length,color:"primary",children:jsxRuntime.jsx(ma__default.default,{})})})}),jsxRuntime.jsx(material.Tooltip,{title:"Summary",children:jsxRuntime.jsx(material.IconButton,{onClick:n=>e.setSummaryAnchorEl(n.currentTarget),color:e.showSummary?"primary":"default",children:jsxRuntime.jsx(ga__default.default,{})})}),jsxRuntime.jsx(material.Tooltip,{title:"Columns",children:jsxRuntime.jsx(material.IconButton,{onClick:n=>e.setAnchorEl(n.currentTarget),children:jsxRuntime.jsx(da__default.default,{})})}),jsxRuntime.jsx(material.Tooltip,{title:"Export",children:jsxRuntime.jsx(material.IconButton,{onClick:e.handleExport,children:jsxRuntime.jsx(pa__default.default,{})})}),e.onOpenGraphReport&&jsxRuntime.jsx(material.Tooltip,{title:"Graphic Report",children:jsxRuntime.jsx(material.IconButton,{onClick:e.onOpenGraphReport,children:jsxRuntime.jsx(fa__default.default,{})})}),e.onLayoutSave&&!e.layoutManager&&jsxRuntime.jsx(material.Tooltip,{title:"Save Layout",children:jsxRuntime.jsx(material.IconButton,{onClick:n=>e.onLayoutSave(n),children:jsxRuntime.jsx(vn__default.default,{})})}),e.layoutManager,l.length>0&&jsxRuntime.jsx(material.Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:l.map((n,i)=>jsxRuntime.jsx(So__namespace.default.Fragment,{children:n},`toolbar-custom-${i}`))})]})]})};var Vo=e=>{let{onSelectAllClick:o,order:t,orderBy:r,numSelected:l=0,rowCount:n=0,onRequestSort:i,columns:a,visibleColumns:d,selectionMode:T,onColumnResize:k,columnWidths:w}=e,[C,E]=So.useState(null),M=So.useRef(null),m=p=>I=>{C||i(p);},f=(p,I,c)=>{p.preventDefault(),p.stopPropagation(),E(I),M.current={startX:p.clientX,startWidth:c,colId:I},document.addEventListener("mousemove",S),document.addEventListener("mouseup",y),document.body.style.cursor="col-resize";},S=p=>{if(!M.current)return;let{startX:I,startWidth:c,colId:u}=M.current,b=p.clientX-I,x=Math.max(50,c+b);k&&k(u,x);},y=()=>{E(null),M.current=null,document.removeEventListener("mousemove",S),document.removeEventListener("mouseup",y),document.body.style.cursor="";};return So.useEffect(()=>()=>{document.removeEventListener("mousemove",S),document.removeEventListener("mouseup",y);},[]),jsxRuntime.jsx(xa__default.default,{children:jsxRuntime.jsxs(Ca__default.default,{children:[(T==="multiple"||T==="single")&&jsxRuntime.jsx(Bo__default.default,{padding:"checkbox",sx:p=>({width:48,backgroundColor:p.palette.mode==="dark"?"#000000":"#f5f5f5",color:p.palette.mode==="dark"?"#ffffff":p.palette.text.primary}),children:jsxRuntime.jsx(va__default.default,{color:"primary",indeterminate:l>0&&l<n,checked:n>0&&l===n,onChange:o,disabled:T==="single"})}),a.filter(p=>d.includes(p.id)).map(p=>{let I=w?.[p.id]||p.minWidth||100;return jsxRuntime.jsxs(Bo__default.default,{align:"left",padding:p.disablePadding?"none":"normal",sortDirection:r===p.id?t:false,style:{width:I,minWidth:I,maxWidth:I},sx:c=>({position:"relative",backgroundColor:c.palette.mode==="dark"?"#000000":"#f5f5f5",color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary,fontWeight:"bold",userSelect:"none"}),children:[jsxRuntime.jsx(Sa__default.default,{active:r===p.id,direction:r===p.id?t:"asc",onClick:m(p.id),sx:c=>({"&.MuiTableSortLabel-root":{width:"100%"},"& .MuiTableSortLabel-icon":{color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary,opacity:r===p.id?1:0,transition:"opacity 0.2s"},"&:hover .MuiTableSortLabel-icon":{opacity:.5},"&.Mui-active .MuiTableSortLabel-icon":{opacity:1,color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary},fontWeight:"bold",color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary}),children:jsxRuntime.jsx(bo__default.default,{component:"span",sx:{overflow:"visible",textOverflow:"clip",whiteSpace:"normal",lineHeight:1.2,wordBreak:"break-word",pr:1},children:p.label})}),jsxRuntime.jsx(bo__default.default,{onMouseDown:c=>f(c,p.id,typeof I=="number"?I:100),onClick:c=>c.stopPropagation(),sx:{position:"absolute",right:0,top:0,bottom:0,width:5,cursor:"col-resize","&:hover":{backgroundColor:"primary.main",opacity:.5},zIndex:1}})]},p.id)})]})})};var Ho=e=>{let{visibleRows:o,visibleColumns:t,selected:r=[],handleClick:l,columns:n,toggleGroupExpand:i,expandedGroups:a=new Set,selectionMode:d}=e,T=C=>r.indexOf(C)!==-1,k=d==="multiple"||d==="single",w=t.length+(k?1:0);return jsxRuntime.jsxs(material.TableBody,{children:[o.map((C,E)=>{if(C.type==="group"){let M=a.has(C.id),m=C.childIds||[],f=m.filter(p=>T(p)).length,S=m.length>0&&f===m.length,y=f>0&&f<m.length,g=p=>{if(p.stopPropagation(),!!e.onSelectionChange)if(S){let I=r.filter(c=>!m.includes(c));e.onSelectionChange(I);}else {let I=Array.from(new Set([...r,...m]));e.onSelectionChange(I);}};return jsxRuntime.jsx(material.TableRow,{sx:p=>({backgroundColor:p.palette.mode==="dark"?"#111111":"#f5f5f5","& .MuiTableCell-root":{color:p.palette.text.primary,borderBottomColor:p.palette.divider},"& .MuiIconButton-root":{color:p.palette.text.primary},"& .MuiCheckbox-root":{color:p.palette.text.secondary},"& .MuiCheckbox-root.Mui-checked, & .MuiCheckbox-root.MuiCheckbox-indeterminate":{color:p.palette.primary.main}}),children:jsxRuntime.jsx(material.TableCell,{colSpan:w,sx:{py:1,pl:C.level*4+2},children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center"},children:[jsxRuntime.jsx(material.IconButton,{size:"small",onClick:()=>i&&i(C.id),sx:{mr:1},children:M?jsxRuntime.jsx(Ra__default.default,{}):jsxRuntime.jsx(Ma__default.default,{})}),k&&jsxRuntime.jsx(material.Checkbox,{size:"small",checked:S,indeterminate:y,onChange:g,onClick:p=>p.stopPropagation(),sx:{mr:1,p:.5}}),jsxRuntime.jsxs(material.Typography,{variant:"body2",fontWeight:"bold",color:"text.primary",children:[C.field,": ",C.value," (",C.count,")"]})]})})},C.id)}else {let M=C.data||C,m=C.id||M.id||E,f=T(m),S=`enhanced-table-checkbox-${E}`,g=(C.level!==void 0?C.level:0)*4;return jsxRuntime.jsxs(material.TableRow,{hover:true,onClick:p=>l&&l(p,M),role:"checkbox","aria-checked":f,tabIndex:-1,selected:f,sx:{cursor:"pointer"},children:[k&&jsxRuntime.jsx(material.TableCell,{padding:"checkbox",sx:{pl:g>0?g+1:void 0},children:jsxRuntime.jsx(material.Checkbox,{color:"primary",checked:f,inputProps:{"aria-labelledby":S}})}),n.filter(p=>t.includes(p.id)).map((p,I)=>{let u=!k&&I===0&&g>0?{pl:g+2}:{};return jsxRuntime.jsx(material.TableCell,{align:"left",sx:u,children:p.render?p.render(M[p.id],M):(function(){let x=M[p.id];if(p.numeric){if(typeof x=="number")return x.toLocaleString();if(typeof x=="string"&&x.trim()!==""&&!isNaN(Number(x)))return Number(x).toLocaleString()}return x})()},p.id)})]},m)}}),o.length===0&&jsxRuntime.jsx(material.TableRow,{children:jsxRuntime.jsx(material.TableCell,{colSpan:w,align:"center",children:"No data"})})]})};var Oo=e=>{let{visibleColumns:o,summaryRow:t,selectionMode:r}=e;if(!e.showSummary)return null;let l=r==="multiple"||r==="single";return jsxRuntime.jsx(material.TableFooter,{sx:{position:"sticky",bottom:0,zIndex:e.zIndex,bgcolor:"background.paper"},children:jsxRuntime.jsxs(material.TableRow,{children:[l&&jsxRuntime.jsx(material.TableCell,{padding:"checkbox",sx:{bgcolor:"background.paper"}}),o.map(n=>jsxRuntime.jsx(material.TableCell,{sx:{fontWeight:"bold",fontSize:"0.875rem",bgcolor:"background.paper",color:"text.primary"},children:(function(){let a=t[n];return a==null||a===""?"":typeof a=="number"?a.toLocaleString():typeof a=="string"&&a.trim()!==""&&!isNaN(Number(a))?Number(a).toLocaleString():a})()},n))]})})};var Wo=e=>jsxRuntime.jsx(material.Box,{sx:{p:2},children:jsxRuntime.jsx(material.Typography,{children:"Mobile View Not Implemented"})});var _o=({groupAnchorEl:e,setGroupAnchorEl:o,grouping:t,setGrouping:r,columns:l,toggleGroupField:n})=>jsxRuntime.jsxs(material.Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsxRuntime.jsxs(material.Box,{sx:{p:1,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[jsxRuntime.jsx(material.Typography,{variant:"subtitle2",sx:{px:1},children:"Group By"}),t.length>0&&jsxRuntime.jsx(material.Button,{size:"small",color:"error",onClick:()=>r([]),startIcon:jsxRuntime.jsx(Ga__default.default,{}),children:"Clear All"})]}),jsxRuntime.jsx(material.Divider,{}),l.map(i=>{let a=t.includes(i.id),d=t.indexOf(i.id)+1;return jsxRuntime.jsx(material.MenuItem,{onClick:()=>n(i.id),children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsxRuntime.jsx(material.Checkbox,{checked:a,size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:i.label}),a&&jsxRuntime.jsx(material.Badge,{badgeContent:d,color:"primary",sx:{mr:2}})]})},i.id)})]}),jo=({anchorEl:e,setAnchorEl:o,columns:t,visibleColumns:r,toggleColumnVisibility:l})=>jsxRuntime.jsxs(material.Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.ListItemText,{primary:"Visible Columns"})}),jsxRuntime.jsx(material.Divider,{}),t.map(n=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>l(n.id),children:[jsxRuntime.jsx(material.Checkbox,{checked:r.includes(n.id),size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:n.label})]},n.id))]}),Uo=({anchorEl:e,setAnchorEl:o,showSummary:t,setShowSummary:r,columns:l,summaryColumns:n,toggleSummaryColumn:i})=>jsxRuntime.jsxs(material.Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsxRuntime.jsx(material.MenuItem,{children:jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Switch,{checked:t,onChange:a=>r(a.target.checked),size:"small"}),label:"Show Summary Row"})}),jsxRuntime.jsx(material.Divider,{}),l.filter(a=>a.numeric).map(a=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>i(a.id),disabled:!t,children:[jsxRuntime.jsx(material.Checkbox,{checked:n.includes(a.id),size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:a.label})]},a.id)),l.filter(a=>a.numeric).length===0&&jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.ListItemText,{primary:"No numeric columns"})})]}),Ko=({contextMenu:e,handleCloseContextMenu:o,columns:t,visibleColumns:r,toggleColumnVisibility:l})=>jsxRuntime.jsxs(material.Menu,{open:e!==null,onClose:o,anchorReference:"anchorPosition",anchorPosition:e!==null?{top:e.mouseY,left:e.mouseX}:void 0,children:[jsxRuntime.jsx(material.MenuItem,{onClick:o,children:"Copy"}),jsxRuntime.jsx(material.Divider,{}),jsxRuntime.jsx(material.MenuItem,{disabled:true,children:"Visible Columns"}),t.map(n=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>l(n.id),children:[jsxRuntime.jsx(material.ListItemIcon,{children:r.includes(n.id)&&jsxRuntime.jsx(Oa__default.default,{fontSize:"small"})}),jsxRuntime.jsx(material.ListItemText,{children:n.label})]},n.id))]});var je=(e,o=2)=>e.toLocaleString(void 0,{maximumFractionDigits:o}),qo=({kpis:e})=>{let o=[{label:"Total Records",value:je(e.totalRecords,0),color:"text.primary"},{label:"Total Report",value:je(e.totalReportHours),color:"text.primary"},{label:"Total Billable",value:je(e.totalBillableHours),color:"success.main"},{label:"Efficiency",value:`${e.efficiency.toFixed(2)}%`,color:"warning.main"},{label:"Amount",value:je(e.totalAmount),color:"info.main"},{label:"Flagged",value:je(e.flaggedCount,0),color:"error.main"}];return jsxRuntime.jsx(material.Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"repeat(2, minmax(0, 1fr))",lg:"repeat(6, minmax(0, 1fr))"},gap:1.5},children:o.map(t=>jsxRuntime.jsxs(material.Paper,{variant:"outlined",sx:{p:1.5,borderRadius:2,minHeight:96,display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",children:t.label}),jsxRuntime.jsx(material.Typography,{variant:"h4",fontWeight:800,sx:{color:t.color},children:t.value})]},t.label))})};var bt=["#1E88E5","#1ABC9C","#FBC02D","#EF5350","#7E57C2","#78909C"],Ua=({data:e})=>{let o=Math.max(...e.map(t=>t.value),1);return jsxRuntime.jsx(material.Stack,{spacing:1,children:e.map(t=>jsxRuntime.jsxs(material.Box,{sx:{display:"grid",gridTemplateColumns:"140px 1fr 64px",gap:1},children:[jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",noWrap:true,title:t.name,children:t.name}),jsxRuntime.jsx(material.Box,{sx:{alignSelf:"center",bgcolor:"action.hover",height:10,borderRadius:999,overflow:"hidden"},children:jsxRuntime.jsx(material.Box,{sx:{width:`${t.value/o*100}%`,height:"100%",bgcolor:"primary.main"}})}),jsxRuntime.jsx(material.Typography,{variant:"caption",sx:{textAlign:"right",fontWeight:600},children:t.value.toFixed(1)})]},t.name))})},Ka=({data:e})=>{let o=Math.max(...e.map(t=>t.value),1);return jsxRuntime.jsx(material.Box,{sx:{display:"flex",gap:1,alignItems:"flex-end",minHeight:210},children:e.map(t=>jsxRuntime.jsxs(material.Box,{sx:{flex:1,minWidth:0},children:[jsxRuntime.jsx(material.Box,{sx:{height:`${Math.max(t.value/o*180,6)}px`,bgcolor:"primary.main",borderRadius:"8px 8px 0 0"}}),jsxRuntime.jsx(material.Typography,{variant:"caption",noWrap:true,title:t.name,sx:{display:"block",mt:.5},children:t.name}),jsxRuntime.jsxs(material.Typography,{variant:"caption",color:"text.secondary",children:[t.value.toFixed(1),"%"]})]},t.name))})},Ya=({data:e})=>{if(e.length===0)return jsxRuntime.jsx(material.Typography,{variant:"body2",color:"text.secondary",children:"No data"});let o=0,r=`conic-gradient(${e.map((l,n)=>{let i=o;return o+=l.percent,`${bt[n%bt.length]} ${i}% ${o}%`}).join(", ")})`;return jsxRuntime.jsxs(material.Stack,{direction:{xs:"column",sm:"row"},spacing:2,alignItems:"center",children:[jsxRuntime.jsx(material.Box,{sx:{width:180,height:180,borderRadius:"50%",background:r,position:"relative"},children:jsxRuntime.jsx(material.Box,{sx:{position:"absolute",inset:30,bgcolor:"background.paper",borderRadius:"50%"}})}),jsxRuntime.jsx(material.Stack,{spacing:1,sx:{minWidth:180},children:e.map((l,n)=>jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsxRuntime.jsx(material.Box,{sx:{width:10,height:10,borderRadius:"50%",bgcolor:bt[n%bt.length]}}),jsxRuntime.jsx(material.Typography,{variant:"caption",sx:{flex:1},children:l.name}),jsxRuntime.jsxs(material.Typography,{variant:"caption",sx:{fontWeight:700},children:[l.percent.toFixed(0),"%"]})]},l.name))})]})},ao=({title:e,subtitle:o,children:t})=>jsxRuntime.jsxs(material.Paper,{variant:"outlined",sx:{p:2,borderRadius:2},children:[jsxRuntime.jsx(material.Typography,{variant:"subtitle1",fontWeight:700,children:e}),jsxRuntime.jsx(material.Typography,{variant:"body2",color:"text.secondary",sx:{mb:2},children:o}),t]}),Xo=({billableByPrimary:e,efficiencyBySecondary:o,statusDistribution:t})=>jsxRuntime.jsxs(material.Box,{sx:{display:"grid",gap:1.5,gridTemplateColumns:{xs:"1fr",lg:"1.2fr 1.2fr 1fr"}},children:[jsxRuntime.jsx(ao,{title:"Billable by Dimension",subtitle:"Top values by billable hours",children:jsxRuntime.jsx(Ua,{data:e})}),jsxRuntime.jsx(ao,{title:"Efficiency by Person",subtitle:"Lowest efficiency first",children:jsxRuntime.jsx(Ka,{data:o})}),jsxRuntime.jsx(ao,{title:"Status Distribution",subtitle:"Record ratio by status",children:jsxRuntime.jsx(Ya,{data:t})})]});var Zo=({open:e,onClose:o,model:t,tableContent:r})=>jsxRuntime.jsx(material.Dialog,{open:e,onClose:o,fullScreen:true,children:jsxRuntime.jsxs(material.Box,{sx:{height:"100%",display:"flex",flexDirection:"column",bgcolor:"background.default"},children:[jsxRuntime.jsx(material.Box,{sx:{p:2,borderBottom:1,borderColor:"divider"},children:jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",justifyContent:"space-between",spacing:2,children:[jsxRuntime.jsxs(material.Stack,{direction:"row",spacing:1.5,alignItems:"center",children:[jsxRuntime.jsx(material.Typography,{variant:"h5",fontWeight:800,children:t.title}),jsxRuntime.jsx(material.Chip,{size:"small",label:`${t.kpis.totalRecords} records`})]}),jsxRuntime.jsx(material.IconButton,{onClick:o,children:jsxRuntime.jsx(Qa__default.default,{})})]})}),jsxRuntime.jsxs(material.Box,{sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,overflow:"auto",minHeight:0},children:[jsxRuntime.jsx(qo,{kpis:t.kpis}),jsxRuntime.jsx(Xo,{billableByPrimary:t.charts.billableByPrimary,efficiencyBySecondary:t.charts.efficiencyBySecondary,statusDistribution:t.charts.statusDistribution}),r]})]})});var Ie={primaryDimension:["Client","Customer","Category","Project"],secondaryDimension:["Person","Consultant","Owner","Name"],status:["Status","state"],date:["Date","WorkDate","CreatedAt"],description:["Description","Task","Title","Memo"],reportHours:["Report_Hour","Report Hours","Hours","ReportHours"],billableHours:["Billable_Hour","Billable Hours","BillableHours"],amount:["Amount","Billable_Amount","Total_Amount","Value"]},er=5,Qo=e=>e.toLowerCase().replace(/[\s_-]/g,""),ke=(e,o,t,r)=>{if(o)return o;if(e.length===0)return r;let l=Object.keys(e[0]),n=new Map(l.map(i=>[Qo(i),i]));for(let i of t){let a=n.get(Qo(i));if(a)return a}return l[0]||r},xe=e=>{if(typeof e=="number")return Number.isFinite(e)?e:0;if(typeof e=="string"){let o=Number(e.replace(/,/g,"").trim());return Number.isFinite(o)?o:0}return 0},Ce=(e,o)=>e==null||e===""?o:String(e),tr=(e,o,t,r)=>{let l=new Map;return e.forEach(n=>{let i=Ce(n[o],"Unassigned");l.set(i,(l.get(i)||0)+xe(n[t]));}),Array.from(l.entries()).map(([n,i])=>({name:n,value:i})).sort((n,i)=>i.value-n.value).slice(0,r)},or=(e,o,t,r,l)=>{let n=new Map;return e.forEach(i=>{let a=Ce(i[o],"Unassigned"),d=n.get(a)||{report:0,billable:0};d.report+=xe(i[t]),d.billable+=xe(i[r]),n.set(a,d);}),Array.from(n.entries()).map(([i,a])=>({name:i,value:a.report>0?a.billable/a.report*100:0})).sort((i,a)=>i.value-a.value).slice(0,l)},nr=(e,o)=>{let t=e.length;if(t===0)return [];let r=new Map;return e.forEach(l=>{let n=Ce(l[o],"Unassigned");r.set(n,(r.get(n)||0)+1);}),Array.from(r.entries()).map(([l,n])=>({name:l,value:n,percent:n/t*100}))},en=({rows:e,config:o})=>{let t=So.useMemo(()=>{let d=o?.fieldMapping;return {primaryDimension:ke(e,d?.primaryDimension,Ie.primaryDimension,"Category"),secondaryDimension:ke(e,d?.secondaryDimension,Ie.secondaryDimension,"Owner"),status:ke(e,d?.status,Ie.status,"Status"),date:ke(e,d?.date,Ie.date,"Date"),description:ke(e,d?.description,Ie.description,"Description"),reportHours:ke(e,d?.reportHours,Ie.reportHours,"ReportHours"),billableHours:ke(e,d?.billableHours,Ie.billableHours,"BillableHours"),amount:ke(e,d?.amount,Ie.amount,"Amount")}},[e,o?.fieldMapping]),r=So.useMemo(()=>e.map((d,T)=>{let k=xe(d[t.reportHours]),w=xe(d[t.billableHours]),C=xe(d[t.amount]),E=k>0?w/k*100:0;return {id:`graph-row-${T}`,Date:Ce(d[t.date],""),Primary:Ce(d[t.primaryDimension],"Unassigned"),Secondary:Ce(d[t.secondaryDimension],"Unassigned"),Description:Ce(d[t.description],""),ReportHours:k,BillableHours:w,Amount:C,Efficiency:E,Status:Ce(d[t.status],"Unassigned")}}),[e,t]),l=So.useMemo(()=>{let d=r.length,T=r.reduce((m,f)=>m+xe(f.ReportHours),0),k=r.reduce((m,f)=>m+xe(f.BillableHours),0),w=r.reduce((m,f)=>m+xe(f.Amount),0),C=T>0?k/T*100:0,E=o?.statusFlagValues||["flag","flagged","warning","risk"],M=r.filter(m=>E.includes(Ce(m.Status,"").toLowerCase())).length;return {totalRecords:d,totalReportHours:T,totalBillableHours:k,efficiency:C,totalAmount:w,flaggedCount:M}},[r,o?.statusFlagValues]),n=o?.topN||er,i=So.useMemo(()=>({billableByPrimary:tr(r,"Primary","BillableHours",n),efficiencyBySecondary:or(r,"Secondary","ReportHours","BillableHours",n),statusDistribution:nr(r,"Status")}),[r,n]),a=So.useMemo(()=>({title:o?.title||"Graphic Report",kpis:l,charts:i,table:{columns:[{id:"Date",label:t.date},{id:"Primary",label:t.primaryDimension},{id:"Secondary",label:t.secondaryDimension},{id:"Description",label:t.description},{id:"ReportHours",label:"Report Hours",align:"right"},{id:"BillableHours",label:"Billable Hours",align:"right"},{id:"Amount",label:"Amount",align:"right"},{id:"Efficiency",label:"Efficiency",align:"right"},{id:"Status",label:t.status}],rows:r}}),[i,o?.title,t,l,r]);return {fieldMapping:t,model:a}};var vt=({variants:e,currentVariantId:o,onLoad:t,onSave:r,onDelete:l,onSetDefault:n})=>{let i="0.75rem",[a,d]=So.useState(false),[T,k]=So.useState(""),[w,C]=So.useState(false),[E,M]=So.useState(false),m=e.find(y=>y.id===o);return jsxRuntime.jsxs(material.Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsxRuntime.jsx(material.Typography,{variant:"body2",sx:{fontWeight:"bold",minWidth:"fit-content",fontSize:i},children:"Variant:"}),jsxRuntime.jsx(material.Autocomplete,{size:"small",sx:{width:200,"& .MuiInputBase-root":{fontSize:i},"& .MuiInputBase-input":{fontSize:i},"& .MuiAutocomplete-noOptions":{fontSize:i}},noOptionsText:jsxRuntime.jsx(material.Typography,{sx:{fontSize:i},children:"No options"}),options:e,getOptionLabel:y=>y.name+(y.isDefault?" (Default)":""),value:m||null,onChange:(y,g)=>{g&&t(g);},renderInput:y=>jsxRuntime.jsx(material.TextField,{...y,variant:"outlined",size:"small",InputProps:{...y.InputProps,sx:{fontSize:i}},placeholder:"Select Variant"}),renderOption:(y,g)=>jsxRuntime.jsx("li",{...y,children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsxRuntime.jsx(material.Typography,{sx:{flex:1,fontSize:i},children:g.name}),g.isDefault&&jsxRuntime.jsx(pr__default.default,{fontSize:"small",color:"action"})]})})}),jsxRuntime.jsx(material.Tooltip,{title:"Save View",children:jsxRuntime.jsx(material.IconButton,{onClick:()=>{k(m?.name||"New Variant"),C(m?.isDefault||false),M(m?.isPublic||false),d(true);},size:"small",color:"primary",children:jsxRuntime.jsx(vn__default.default,{})})}),jsxRuntime.jsxs(material.Dialog,{open:a,onClose:()=>d(false),children:[jsxRuntime.jsx(material.DialogTitle,{children:"Save View"}),jsxRuntime.jsxs(material.DialogContent,{children:[jsxRuntime.jsx(material.TextField,{autoFocus:true,margin:"dense",label:"View Name",fullWidth:true,variant:"outlined",value:T,onChange:y=>k(y.target.value)}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:w,onChange:y=>C(y.target.checked)}),label:"Set as Default"}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:E,onChange:y=>M(y.target.checked)}),label:"Public (All Users)"})]}),jsxRuntime.jsxs(material.DialogActions,{children:[jsxRuntime.jsx(material.Button,{onClick:()=>d(false),children:"Cancel"}),jsxRuntime.jsx(material.Button,{onClick:()=>{r({name:T,isDefault:w,isPublic:E,description:""}),d(false);},variant:"contained",children:"Save"})]})]})]})};var fr="http://127.0.0.1:8515",sn=({appId:e,tableKey:o="default",currentFilters:t,currentLayoutId:r,layoutRefs:l,onLoad:n,serviceUrl:i=fr,onError:a,onSuccess:d,currentVariantId:T,onVariantChange:k})=>{let[w,C]=So.useState([]),[E,M]=So.useState(""),m=T!==void 0?T:E,f=c=>{T===void 0&&M(c),k&&k(c);},S=So.useCallback(async()=>{if(!e)return [];try{let c=await fetch(`${i}/api/variants?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!c.ok)throw new Error("Failed to fetch variants");let u=await c.json();C(u);let b=u.find(x=>x.isDefault);return b&&!m&&(f(b.id),n(b)),u}catch(c){return console.error("Error fetching variants",c),a&&a("Failed to load variants"),[]}},[e,o,i,a,m,n]);return So.useEffect(()=>{S();},[e,o]),jsxRuntime.jsx(vt,{variants:w,currentVariantId:m,onLoad:c=>{f(c.id),n(c);},onSave:async c=>{try{let u=w.find(L=>L.name===c.name),b=u?u.id:Date.now().toString(),x=[];if(u&&(Array.isArray(u.filters)?x=[...u.filters]:u.filters&&(x=[{scope:"default",filters:u.filters}])),c.scope==="Search"||c.scope==="Both"){let L=(Array.isArray(t),t);if(L)if(Array.isArray(L)&&L.length>0&&L[0].scope)L.forEach(V=>{let A=x.findIndex(N=>N.scope===V.scope);A>=0?x[A]=V:x.push(V);});else {let V={scope:o,filters:L},A=x.findIndex(N=>N.scope===o);A>=0?x[A]=V:x.push(V);}}let s=u?.layout||{},R=[];if(u&&Array.isArray(u.layoutRefs)&&(R=[...u.layoutRefs]),c.scope==="Layout"||c.scope==="Both")if(l&&l.length>0)l.forEach(L=>{let V=R.findIndex(A=>A.tableKey===L.tableKey);V>=0?R[V]=L:R.push(L);});else {let L={tableKey:o,layoutId:r||null},V=R.findIndex(A=>A.tableKey===o);V>=0?R[V]=L:R.push(L);}let v={appId:e,tableKey:o,...c,id:b,createdAt:new Date().toISOString(),filters:x,layout:s,layoutRefs:R};if(!(await fetch(`${i}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(v)})).ok)throw new Error("Failed to save variant");d&&d("Variant saved successfully"),await S(),f(b),n(v);}catch(u){console.error("Error saving variant",u),a&&a("Failed to save variant");}},onDelete:async c=>{try{if(!(await fetch(`${i}/api/variants/${c}`,{method:"DELETE"})).ok)throw new Error("Failed to delete variant");m===c&&f(""),S(),d&&d("Variant deleted successfully");}catch(u){console.error("Error deleting variant",u),a&&a("Failed to delete variant");}},onSetDefault:async c=>{try{let u=w.find(s=>s.id===c);if(!u)return;let b={appId:e,tableKey:o,...u,isDefault:!0};if(!(await fetch(`${i}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)})).ok)throw new Error("Failed to set default variant");await S(),d&&d("Default variant updated");}catch(u){console.error("Error setting default variant",u),a&&a("Failed to update default variant");}}})};Ee__default.default.extend(Pr__default.default);var Er=[null,null],uo="0.75rem",Lr=material.styled(PickersDay.PickersDay,{shouldForwardProp:e=>e!=="isInRange"&&e!=="isStart"&&e!=="isEnd"&&e!=="isHovered"})(({theme:e,isInRange:o,isStart:t,isEnd:r,isHovered:l})=>({...o&&{borderRadius:0,backgroundColor:e.palette.primary.light,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.main}},...l&&!o&&!t&&!r&&{borderRadius:0,backgroundColor:e.palette.action.hover,border:`1px dashed ${e.palette.primary.main}`},...t&&{borderRadius:"50% 0 0 50%",backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.dark}},...r&&{borderRadius:"0 50% 50% 0",backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.dark}},...t&&r&&{borderRadius:"50%"}})),un=({label:e="Date Range",value:o=Er,onChange:t})=>{let[r,l]=So.useState(null),[n,i]=So.useState(o),[a,d]=So.useState("start"),[T,k]=So.useState(null),[w,C]=So.useState(o[0]||Ee__default.default()),E=So__namespace.default.useRef(o);So.useEffect(()=>{let[b,x]=o,[s,R]=E.current,v=V=>V&&typeof V.isSame=="function",z=!(b===null&&s===null||v(b)&&v(s)&&b.isSame(s,"day")),L=!(x===null&&R===null||v(x)&&v(R)&&x.isSame(R,"day"));(z||L)&&(i(o),o[0]&&v(o[0])&&C(o[0])),E.current=o;},[o]);let M=b=>{l(b.currentTarget);},m=()=>{l(null),d("start"),k(null);},f=!!r,S=b=>{if(!b)return;let x=[...n];if(a==="start")x=[b,null],d("end");else {let s=x[0];s&&b.isBefore(s)?(x=[b,null],d("end")):(x=[s,b],d("start"));}i(x);},y=b=>{let x=Ee__default.default(),s=[null,null];switch(b){case "today":s=[x,x];break;case "week":s=[x.startOf("week"),x.endOf("week")];break;case "month":s=[x.startOf("month"),x.endOf("month")];break}i(s),d("start"),C(x);},g=()=>{i([null,null]),d("start"),C(Ee__default.default());},p=()=>{t&&t(n),m();},I=()=>{i(o),d("start"),m();},c=So.useCallback(b=>{let{day:x,...s}=b,[R,v]=n,z=R?x.isSame(R,"day"):false,L=v?x.isSame(v,"day"):false,V=R&&v?x.isBetween(R,v,"day","()"):false,A=false;return a==="end"&&R&&!v&&T&&x.isAfter(R,"day")&&x.isBefore(T.add(1,"day"),"day")&&(A=true),jsxRuntime.jsx(Lr,{...s,day:x,disableMargin:true,isStart:z,isEnd:L,isInRange:V||A,onMouseEnter:()=>k(x)})},[n,a,T]),u=b=>b?b.format("YYYY-MM-DD"):"";return jsxRuntime.jsxs(material.Box,{children:[jsxRuntime.jsx(material.TextField,{label:e,value:n[0]?`${u(n[0])} - ${u(n[1])}`:"",onClick:M,fullWidth:true,size:"small",InputLabelProps:{sx:{fontSize:uo}},InputProps:{readOnly:true,sx:{fontSize:uo,"& .MuiOutlinedInput-input":{fontSize:uo},paddingRight:"4px"},endAdornment:jsxRuntime.jsxs(material.InputAdornment,{position:"end",sx:{ml:0},children:[(n[0]||n[1])&&jsxRuntime.jsx(material.IconButton,{size:"small",onClick:b=>{b.stopPropagation(),g();},edge:"end",sx:{mr:.5,padding:"2px"},children:jsxRuntime.jsx(Rr__default.default,{sx:{fontSize:"1rem"}})}),jsxRuntime.jsx(material.IconButton,{size:"small",edge:"end",onClick:M,sx:{padding:"2px"},children:jsxRuntime.jsx(Mr__default.default,{sx:{fontSize:"1rem"},color:"action"})})]})}}),jsxRuntime.jsxs(material.Popover,{open:f,anchorEl:r,onClose:m,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},slotProps:{paper:{sx:{display:"flex",flexDirection:"column",p:0,minWidth:320}}},children:[jsxRuntime.jsx(material.Box,{sx:{p:2,bgcolor:"background.default",borderBottom:1,borderColor:"divider"},children:jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:2,justifyContent:"space-between",children:[jsxRuntime.jsxs(material.Box,{sx:{p:1,border:1,borderColor:a==="start"?"primary.main":"divider",borderRadius:1,bgcolor:a==="start"?"action.hover":"transparent",flex:1,cursor:"pointer"},onClick:()=>d("start"),children:[jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",display:"block",children:"Start Date"}),jsxRuntime.jsx(material.Typography,{variant:"body2",fontWeight:500,children:n[0]?n[0].format("MMM DD, YYYY"):"Select..."})]}),jsxRuntime.jsx(Dr__default.default,{color:"action",fontSize:"small"}),jsxRuntime.jsxs(material.Box,{sx:{p:1,border:1,borderColor:a==="end"?"primary.main":"divider",borderRadius:1,bgcolor:a==="end"?"action.hover":"transparent",flex:1,cursor:"pointer"},onClick:()=>{n[0]&&d("end");},children:[jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",display:"block",children:"End Date"}),jsxRuntime.jsx(material.Typography,{variant:"body2",fontWeight:500,children:n[1]?n[1].format("MMM DD, YYYY"):"Select..."})]})]})}),jsxRuntime.jsx(material.Box,{sx:{p:2,pb:0},children:jsxRuntime.jsxs(material.Stack,{direction:"row",spacing:1,justifyContent:"center",children:[jsxRuntime.jsx(material.Chip,{label:"Today",onClick:()=>y("today"),clickable:true,size:"small",variant:"outlined"}),jsxRuntime.jsx(material.Chip,{label:"This Week",onClick:()=>y("week"),clickable:true,size:"small",variant:"outlined"}),jsxRuntime.jsx(material.Chip,{label:"This Month",onClick:()=>y("month"),clickable:true,size:"small",variant:"outlined"})]})}),jsxRuntime.jsx(DateCalendar.DateCalendar,{value:null,referenceDate:w,onMonthChange:C,onYearChange:C,onChange:S,slots:{day:c},views:["day"],showDaysOutsideCurrentMonth:true,sx:{m:0}}),jsxRuntime.jsx(material.Divider,{}),jsxRuntime.jsxs(material.Stack,{direction:"row",justifyContent:"flex-end",spacing:1,sx:{p:2},children:[jsxRuntime.jsx(material.Button,{size:"small",onClick:I,color:"inherit",children:"Cancel"}),jsxRuntime.jsx(material.Button,{size:"small",variant:"contained",onClick:p,children:"Done"})]})]})]})};var It={equals:"=",contains:"\u2287",notContains:"\u2285",wildcard:"*","=":"=","!=":"!=",">":">","<":"<",">=":"\u2265","<=":"\u2264",between:"\u2194"},$r={equals:"Equals",contains:"Contains",notContains:"Does Not Contain",wildcard:"Wildcard Search","=":"Equals","!=":"Not Equals",">":"Greater Than","<":"Less Than",">=":"Greater Than or Equal","<=":"Less Than or Equal",between:"Between"},_r=["equals","contains","notContains","wildcard"],gn=["=","!=",">","<",">=","<=","between"],Z="0.75rem",jr=({field:e,value:o,onChange:t})=>{let[r,l]=So.useState(null),[n,i]=So.useState(null),[a,d]=So.useState(""),[T,k]=So.useState(""),[w,C]=So.useState(false),[E,M]=So.useState(""),[m,f]=So.useState("");So.useEffect(()=>{let s=setTimeout(()=>{f(E);},1e3);return ()=>clearTimeout(s)},[E]);let S=o?.operator||(e.type==="number"?"=":"equals"),y=o?.value,g=s=>$r[s]||s,p=s=>{l(s.currentTarget);},I=s=>{t({...o,operator:s,value:y}),l(null);},c={size:"small",fullWidth:true,variant:"outlined",InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}},SelectProps:{MenuProps:{PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,paddingTop:"4px",paddingBottom:"4px",minHeight:"auto"}}}}}},u=e.type||"text";if(u==="date"){let R=(v=>{if(!v)return [null,null];if(Array.isArray(v)&&v.length===2){let z=v[0]?Ee__default.default.isDayjs(v[0])?v[0]:Ee__default.default(v[0]):null,L=v[1]?Ee__default.default.isDayjs(v[1])?v[1]:Ee__default.default(v[1]):null;return [z,L]}return Ee__default.default.isDayjs(v)||typeof v=="string"?[Ee__default.default.isDayjs(v)?v:Ee__default.default(v),null]:[null,null]})(y);return jsxRuntime.jsx(un,{label:e.label,value:R,onChange:v=>t({value:v,operator:"between"})})}if(u==="number"&&S==="between"){let s=()=>{t({value:[a,T],operator:"between"}),i(null);},R=Array.isArray(y)?`${y[0]||""} - ${y[1]||""}`:"";return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(material.TextField,{...c,label:e.label,value:R,placeholder:"Min - Max",InputProps:{...c.InputProps,startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(material.Tooltip,{title:g("between"),children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:p,sx:{width:24,height:24,fontSize:Z},children:It.between})})}),readOnly:true},onClick:v=>i(v.currentTarget)}),jsxRuntime.jsx(material.Menu,{anchorEl:r,open:!!r,onClose:()=>l(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,minHeight:"auto",py:.5}}},children:gn.map(v=>jsxRuntime.jsxs(material.MenuItem,{selected:v===S,onClick:()=>I(v),children:[jsxRuntime.jsx(material.Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:It[v]}),jsxRuntime.jsx(material.ListItemText,{primary:g(v),primaryTypographyProps:{fontSize:Z}})]},v))}),jsxRuntime.jsx(material.Popover,{open:!!n,anchorEl:n,onClose:()=>i(null),anchorOrigin:{vertical:"bottom",horizontal:"left"},children:jsxRuntime.jsxs(material.Box,{sx:{p:2,display:"flex",gap:1,alignItems:"center"},children:[jsxRuntime.jsx(material.TextField,{size:"small",label:"Min",type:"number",value:a,onChange:v=>d(v.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}}}),jsxRuntime.jsx(Wr__default.default,{color:"action"}),jsxRuntime.jsx(material.TextField,{size:"small",label:"Max",type:"number",value:T,onChange:v=>k(v.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}}}),jsxRuntime.jsx(material.Button,{variant:"contained",size:"small",onClick:s,children:"OK"})]})})]})}if(u==="select")return jsxRuntime.jsxs(material.TextField,{...c,select:true,label:e.label,value:y||"",onChange:s=>t({...o,value:s.target.value,operator:"equals"}),children:[jsxRuntime.jsx(material.MenuItem,{value:"",children:jsxRuntime.jsx("em",{children:"None"})}),e.options?.map(s=>jsxRuntime.jsx(material.MenuItem,{value:s.value,children:s.label},s.value))]});if(u==="multi-select"){let s=Array.isArray(y)?y:[],R=e.options?.filter(v=>v.label.toLowerCase().includes(m.toLowerCase()))||[];return jsxRuntime.jsxs(material.TextField,{...c,select:true,label:e.label,value:s,onChange:v=>t({...o,value:v.target.value,operator:"anyOf"}),SelectProps:{...c.SelectProps,multiple:true,onClose:()=>{M(""),f("");},renderValue:v=>{if(!Array.isArray(v)||v.length===0)return jsxRuntime.jsx("em",{children:"None"});let z=V=>e.options?.find(A=>A.value===V)?.label||V,L=v.map(z);return L.length>2?`${L.slice(0,2).join(", ")} +${L.length-2}`:L.join(", ")}},children:[jsxRuntime.jsx(material.ListSubheader,{children:jsxRuntime.jsx(material.TextField,{size:"small",autoFocus:true,placeholder:"Search...",fullWidth:true,InputProps:{startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(mn__default.default,{fontSize:"small"})}),sx:{fontSize:Z}},value:E,onChange:v=>M(v.target.value),onKeyDown:v=>{v.key!=="Escape"&&v.stopPropagation();},onClick:v=>v.stopPropagation()})}),R.length>0?R.map(v=>jsxRuntime.jsxs(material.MenuItem,{value:v.value,children:[jsxRuntime.jsx(material.Checkbox,{checked:s.indexOf(v.value)>-1,size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:v.label,primaryTypographyProps:{fontSize:Z}})]},v.value)):jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.ListItemText,{primary:"No options found",primaryTypographyProps:{fontSize:Z}})})]})}let b=u==="number"?gn:_r,x=w||y!==void 0&&y!==""&&y!==null||!!r;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(material.TextField,{...c,label:e.label,sx:{minWidth:"120px"},value:y||"",type:u==="number"?"number":"text",onChange:s=>t({...o,value:s.target.value,operator:S}),onFocus:()=>C(true),onBlur:()=>C(false),InputProps:{...c.InputProps,startAdornment:x?jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(material.Tooltip,{title:g(S),children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:p,onMouseDown:s=>s.preventDefault(),sx:{width:24,height:24,fontSize:Z,fontWeight:"bold",color:"primary.main",bgcolor:"action.hover"},children:It[S]})})}):null,endAdornment:e.hasSearchIcon?jsxRuntime.jsx(material.InputAdornment,{position:"end",children:jsxRuntime.jsx(mn__default.default,{color:"action"})}):void 0}}),jsxRuntime.jsx(material.Menu,{anchorEl:r,open:!!r,onClose:()=>l(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,minHeight:"auto",py:.5}}},children:b.map(s=>jsxRuntime.jsxs(material.MenuItem,{selected:s===S,onClick:()=>I(s),children:[jsxRuntime.jsx(material.Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:It[s]}),jsxRuntime.jsx(material.ListItemText,{primary:g(s),primaryTypographyProps:{fontSize:Z}})]},s))})]})},Xe=({fields:e,filters:o,onFilterChange:t,variants:r=[],currentVariantId:l,onVariantLoad:n,onVariantSave:i,onVariantDelete:a,onVariantSetDefault:d,onSearch:T,loading:k=false,appId:w,tableKey:C,currentLayout:E,currentLayoutId:M,layoutRefs:m,variantService:f})=>{let[S,y]=So.useState(true),[g,p]=So.useState(null),[I,c]=So.useState(e.filter(s=>!s.hidden).map(s=>s.id)),u=(s,R)=>{t({...o,[s]:R});},b=s=>{I.includes(s)?c(I.filter(R=>R!==s)):c([...I,s]);};return jsxRuntime.jsxs(material.Paper,{sx:{mb:0,display:"flex",flexDirection:"column",overflow:"visible",position:"relative"},children:[jsxRuntime.jsxs(material.Box,{sx:{p:2,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[w?jsxRuntime.jsx(sn,{appId:w,tableKey:C,currentFilters:{values:o,visibleFields:I},currentLayout:E,currentLayoutId:M,layoutRefs:m,onLoad:s=>{if(!s.filters)return;let R=null;if(Array.isArray(s.filters)){let v=C||"default",z=s.filters.find(L=>L.scope===v);R=z?z.filters:null;}else R=s.filters;R&&(R.values||R.visibleFields?(R.visibleFields&&Array.isArray(R.visibleFields)&&c(R.visibleFields),R.values&&t(R.values)):t(R)),n&&n(s);},variantService:f,currentVariantId:l}):jsxRuntime.jsx(vt,{variants:r,currentVariantId:l,onLoad:n,onSave:s=>{i&&i({...s,filters:{values:o,visibleFields:I}});},onDelete:a,onSetDefault:d}),jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsxRuntime.jsx(material.Tooltip,{title:"Add Filters",children:jsxRuntime.jsx(material.Button,{onClick:s=>p(s.currentTarget),size:"small",color:"primary",startIcon:jsxRuntime.jsx(zr__default.default,{fontSize:"small"}),sx:{textTransform:"none",fontSize:Z},children:"Adapt Filters"})}),jsxRuntime.jsx(material.Button,{variant:"contained",size:"small",onClick:T,disabled:k,sx:{minWidth:"40px",fontWeight:"bold"},children:k?"...":"Go"}),jsxRuntime.jsxs(material.Menu,{anchorEl:g,open:!!g,onClose:()=>p(null),slotProps:{paper:{style:{maxHeight:400,width:"25ch"}}},children:[jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.ListItemText,{primary:"Visible Filters"})}),jsxRuntime.jsx(material.Divider,{}),e.map(s=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>b(s.id),children:[jsxRuntime.jsx(material.Checkbox,{checked:I.includes(s.id),size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:s.label})]},s.id))]})]})]}),jsxRuntime.jsx(material.Collapse,{in:S,children:jsxRuntime.jsx(material.Box,{sx:{px:2,pb:2},children:jsxRuntime.jsx(material.Grid,{container:true,spacing:2,columns:{xs:2,sm:3,md:4,lg:6},children:e.filter(s=>I.includes(s.id)).map(s=>jsxRuntime.jsx(material.Grid,{size:1,children:jsxRuntime.jsx(jr,{field:s,value:o[s.id]||{value:"",operator:s.type==="number"?"=":"equals"},onChange:R=>u(s.id,R)})},s.id))})})}),jsxRuntime.jsx(material.Box,{sx:{position:"absolute",bottom:0,left:"50%",transform:"translate(-50%, 50%)",zIndex:10},children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:()=>y(!S),sx:{bgcolor:"background.paper",boxShadow:2,border:"1px solid",borderColor:"divider",width:20,height:20,minHeight:0,p:0,"&:hover":{bgcolor:"background.paper"}},children:S?jsxRuntime.jsx(Or__default.default,{sx:{fontSize:16},color:"action"}):jsxRuntime.jsx(Ra__default.default,{sx:{fontSize:16},color:"action"})})})]})};var Sn=({layouts:e,currentLayoutId:o,onLoad:t,onSave:r,onDelete:l,onSetDefault:n})=>{let[i,a]=So.useState(null),[d,T]=So.useState(false),[k,w]=So.useState(""),[C,E]=So.useState(""),[M,m]=So.useState({isDefault:false,isPublic:false}),f=e.find(c=>c.id===o),S=c=>{a(c.currentTarget);},y=()=>{a(null);},g=c=>{t(c),y();},p=()=>{w(""),E(""),m({isDefault:false,isPublic:false}),T(true),y();},I=()=>{k.trim()&&(r({name:k,description:C,...M}),T(false));};return jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsxRuntime.jsx(material.Tooltip,{title:"Save Layout",children:jsxRuntime.jsx(material.IconButton,{onClick:p,color:"primary",size:"small",children:jsxRuntime.jsx(vn__default.default,{})})}),jsxRuntime.jsx(material.Tooltip,{title:"Layout Options",children:jsxRuntime.jsx(material.IconButton,{onClick:S,color:f?"primary":"default",children:jsxRuntime.jsx(ni__default.default,{})})}),jsxRuntime.jsxs(material.Menu,{anchorEl:i,open:!!i,onClose:y,PaperProps:{sx:{width:320,maxHeight:400}},children:[jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.Typography,{variant:"caption",children:"Select Layout"})}),jsxRuntime.jsxs(material.MenuItem,{onClick:p,children:[jsxRuntime.jsx(material.ListItemIcon,{children:jsxRuntime.jsx(vn__default.default,{fontSize:"small"})}),jsxRuntime.jsx(material.ListItemText,{children:"Save Current Layout..."})]}),jsxRuntime.jsx(material.Divider,{}),e.length===0&&jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.Typography,{variant:"body2",color:"text.secondary",children:"No saved layouts"})}),e.map((c,u)=>jsxRuntime.jsx(material.MenuItem,{onClick:()=>g(c),selected:c.id===o,children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",width:"100%",justifyContent:"space-between"},children:[jsxRuntime.jsxs(material.Box,{sx:{display:"flex",flexDirection:"column",overflow:"hidden",mr:1},children:[jsxRuntime.jsx(material.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:jsxRuntime.jsx(material.Typography,{variant:"body2",fontWeight:c.id===o?"bold":"normal",noWrap:true,children:c.name})}),c.description&&jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",noWrap:true,children:c.description})]}),jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center"},onClick:b=>b.stopPropagation(),children:[jsxRuntime.jsx(material.Tooltip,{title:c.isDefault?"Remove Default":"Set as Default",children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:b=>{b.stopPropagation(),n(c.id);},children:c.isDefault?jsxRuntime.jsx(pr__default.default,{fontSize:"small",color:"warning"}):jsxRuntime.jsx(oi__default.default,{fontSize:"small"})})}),jsxRuntime.jsx(material.Tooltip,{title:"Delete",children:jsxRuntime.jsx(material.IconButton,{size:"small",color:"error",onClick:b=>{b.stopPropagation(),l(c.id);},children:jsxRuntime.jsx(ei__default.default,{fontSize:"small"})})})]})]})},c.id||u))]}),jsxRuntime.jsxs(material.Dialog,{open:d,onClose:()=>T(false),maxWidth:"xs",fullWidth:true,children:[jsxRuntime.jsx(material.DialogTitle,{children:"Save Layout"}),jsxRuntime.jsx(material.DialogContent,{children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[jsxRuntime.jsx(material.TextField,{label:"Layout Name",value:k,onChange:c=>w(c.target.value),fullWidth:true,autoFocus:true,size:"small",helperText:"e.g., 'Compact View'"}),e.some(c=>c.name===k)&&jsxRuntime.jsx(material.Typography,{variant:"caption",color:"warning.main",sx:{ml:1},children:"Warning: Existing layout will be overwritten"}),jsxRuntime.jsx(material.TextField,{label:"Description",value:C,onChange:c=>E(c.target.value),fullWidth:true,size:"small"}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:M.isDefault,onChange:c=>m({...M,isDefault:c.target.checked})}),label:"Use as Default Layout"}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:M.isPublic,onChange:c=>m({...M,isPublic:c.target.checked})}),label:"Public (Visible to all users)"})]})}),jsxRuntime.jsxs(material.DialogActions,{children:[jsxRuntime.jsx(material.Button,{onClick:()=>T(false),children:"Cancel"}),jsxRuntime.jsx(material.Button,{onClick:I,variant:"contained",disabled:!k,children:"Save"})]})]})]})};var ai="http://127.0.0.1:8515",wn=({appId:e,tableKey:o="default",currentLayoutData:t,onLayoutLoad:r,targetLayoutId:l,activeLayoutId:n,serviceUrl:i=ai,onError:a,onSuccess:d})=>{let[T,k]=So.useState([]),[w,C]=So.useState(""),E=`orbcafe.layouts.${e}.${o}`,M=u=>({id:u.layoutId,name:u.name,description:u.description??"",isDefault:!!u.isDefault,isPublic:!!u.isPublic,createdAt:u.createdAt??new Date().toISOString(),layoutData:u.layout??{}}),m=u=>({appId:e,tableKey:o,layoutId:u.id,name:u.name,description:u.description??"",isDefault:!!u.isDefault,isPublic:!!u.isPublic,createdAt:u.createdAt,layout:u.layoutData}),f=So.useCallback(()=>{try{let u=localStorage.getItem(E);if(!u)return [];let b=JSON.parse(u);return Array.isArray(b)?b:[]}catch{return []}},[E]),S=So.useCallback(u=>{try{localStorage.setItem(E,JSON.stringify(u));}catch{}},[E]);So.useEffect(()=>{n!==void 0&&C(n);},[n]),So.useEffect(()=>{if(l&&T.length>0){let u=T.find(b=>b.id===l);u&&(C(u.id),r(u));}},[l,T,r]);let y=So.useCallback(async()=>{if(e)try{let u=await fetch(`${i}/api/layouts?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!u.ok)throw new Error("Failed to fetch layouts");let x=(await u.json()).map(M);k(x);let s=x.find(R=>R.isDefault);s&&!w&&!l&&(C(s.id),r(s));}catch(u){console.error("Error fetching layouts",u);let b=f();k(b);let x=b.find(s=>s.isDefault);x&&!w&&!l&&(C(x.id),r(x)),a&&a("Failed to load layouts from backend, fallback to local storage");}},[e,o,i,a,w,r,l,f]);return So.useEffect(()=>{y();},[e,o]),jsxRuntime.jsx(Sn,{layouts:T,currentLayoutId:w,onLoad:u=>{C(u.id),r(u);},onSave:async u=>{let b=T.find(R=>R.name===u.name),x=b?b.id:Date.now().toString(),s={id:x,...u,createdAt:new Date().toISOString(),layoutData:t,isDefault:u.isDefault??false,isPublic:u.isPublic??false};try{if(!(await fetch(`${i}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(m(s))})).ok)throw new Error("Failed to save layout");d&&d("Layout saved successfully"),await y(),C(x),r(s);}catch(R){console.error("Error saving layout",R);let z=T.some(L=>L.id===x)?T.map(L=>L.id===x?s:L):[...T,s];k(z),S(z),C(x),r(s),d&&d("Layout saved to local storage"),a&&a("Backend unavailable, saved to local storage");}},onDelete:async u=>{try{if(!(await fetch(`${i}/api/layouts/${encodeURIComponent(u)}`,{method:"DELETE"})).ok)throw new Error("Failed to delete layout");w===u&&C(""),d&&d("Layout deleted successfully"),await y();}catch(b){console.error("Error deleting layout",b);let x=T.filter(s=>s.id!==u);k(x),S(x),w===u&&C(""),d&&d("Layout deleted from local storage"),a&&a("Backend unavailable, deleted from local storage");}},onSetDefault:async u=>{try{let b=T.find(s=>s.id===u);if(!b)return;if(!(await fetch(`${i}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(m({...b,isDefault:!0}))})).ok)throw new Error("Failed to set default layout");d&&d("Default layout set"),await y();}catch(b){console.error("Error setting default",b);let x=T.map(s=>({...s,isDefault:s.id===u}));k(x),S(x),d&&d("Default layout set in local storage"),a&&a("Backend unavailable, default saved to local storage");}}})};function kn(e,o,t){return o[t]<e[t]?-1:o[t]>e[t]?1:0}function ii(e,o){return e==="desc"?(t,r)=>kn(t,r,o):(t,r)=>-kn(t,r,o)}function li(e,o){let t=e.map((r,l)=>[r,l]);return t.sort((r,l)=>{let n=o(r[0],l[0]);return n!==0?n:r[1]-l[1]}),t.map(r=>r[0])}var Mn=e=>{let o=So.useCallback(h=>{let B=String(h?.label??h?.id??"").length*9+64,ee=typeof h?.minWidth=="number"?h.minWidth:0;return Math.max(100,ee,B)},[]),[t,r]=So.useState(""),[l,n]=So.useState(e.order||"asc"),[i,a]=So.useState(e.orderBy||""),[d,T]=So.useState(e.page||0),[k,w]=So.useState(e.rowsPerPage||20),[C,E]=So.useState(e.selected||[]),[M,m]=So.useState(e.columns?e.columns.map(h=>h.id):[]),[f,S]=So.useState(e.showSummary||false),[y,g]=So.useState([]),[p,I]=So.useState(new Set),[c,u]=So.useState(()=>{let h={};return (e.columns||[]).forEach(D=>{h[D.id]=o(D);}),h}),[b,x]=So.useState(null),[s,R]=So.useState(null),[v,z]=So.useState(null),[L,V]=So.useState(null),[A,N]=So.useState(false),[te,Oe]=So.useState("");So.useEffect(()=>{e.order!==void 0&&n(e.order),e.orderBy!==void 0&&a(e.orderBy);},[e.order,e.orderBy]),So.useEffect(()=>{e.selected!==void 0&&E(e.selected);},[e.selected]),So.useEffect(()=>{e.page!==void 0&&T(e.page);},[e.page]),So.useEffect(()=>{u(h=>{let D={...h};return (e.columns||[]).forEach(B=>{D[B.id]===void 0&&(D[B.id]=o(B));}),D});},[e.columns,o]);let oe=So.useMemo(()=>{let h=e.rows||[];return t&&(h=h.filter(D=>Object.keys(D).some(B=>String(D[B]).toLowerCase().includes(t.toLowerCase())))),h},[e.rows,t]),re=So.useMemo(()=>e.onSortChange||!i?oe:li(oe,ii(l,i)),[oe,l,i,e.onSortChange]),ie=So.useCallback(h=>{if(y.length===0)return h.map(Y=>({type:"row",data:Y,id:Y[e.rowKey||"id"]}));let D=[...h].sort((Y,q)=>{for(let $ of y){if(Y[$]<q[$])return -1;if(Y[$]>q[$])return 1}return 0}),B=(Y,q=0)=>{if(q>=y.length)return Y;let $=y[q],U={},fe=[];return Y.forEach(se=>{let Be=se[$],ce=`${$}:${Be}`;U[ce]||(U[ce]={key:ce,field:$,value:Be,children:[],count:0,level:q},fe.push(U[ce])),U[ce].children.push(se),U[ce].count++;}),fe.forEach(se=>{se.children&&(se.children=B(se.children,q+1));}),fe},ee=B(D),G=(Y,q="")=>{let $=[];return Y.forEach(U=>{if(U.children){let fe=q?`${q}>${U.key}`:U.key,se=p.has(fe);$.push({type:"group",id:fe,field:U.field,value:U.value,level:U.level,count:U.count,isExpanded:se,childIds:(function Be(ce){let Se=[];return ce.children.forEach($e=>{$e.children?Se=Se.concat(Be($e)):Se.push($e[e.rowKey||"id"]);}),Se})(U)}),se&&($=$.concat(G(U.children,fe)));}else $.push({type:"row",data:U,id:U[e.rowKey||"id"],level:y.length});}),$};return G(ee)},[y,p,e.rowKey]),De=So.useMemo(()=>ie(re),[re,ie]),nt=So.useMemo(()=>k>0?De.slice(d*k,d*k+k):De,[De,d,k]),at=h=>{let D=new Set(p);D.has(h)?D.delete(h):D.add(h),I(D);},Ge=h=>{at(h);},Ft=h=>{let D=new Set(p);Array.from(D).forEach(B=>{B.startsWith(h)&&D.delete(B);}),I(D);},Vt=h=>{h||I(new Set);},We=h=>{let D=i===h&&l==="asc",B=i===h&&l==="desc";if(e.onSortChange){D?e.onSortChange(h,"desc"):B?e.onSortChange("","asc"):e.onSortChange(h,"asc");return}D?(n("desc"),a(h)):B?(n("asc"),a("")):(n("asc"),a(h));},rt=(h,D)=>{u(B=>({...B,[h]:D}));},Nt=h=>{if(h.target.checked){let D=oe.map(B=>B[e.rowKey||"id"]);E(D),e.onSelectionChange&&e.onSelectionChange(D);return}E([]),e.onSelectionChange&&e.onSelectionChange([]);},Ht=(h,D)=>{let B=D[e.rowKey||"id"],ee=C.indexOf(B),G=[];ee===-1?G=G.concat(C,B):ee===0?G=G.concat(C.slice(1)):ee===C.length-1?G=G.concat(C.slice(0,-1)):ee>0&&(G=G.concat(C.slice(0,ee),C.slice(ee+1))),E(G),e.onSelectionChange&&e.onSelectionChange(G);},it=h=>{T(h),e.onPageChange&&e.onPageChange(h);},lt=h=>{w(h),T(0),e.onRowsPerPageChange&&e.onRowsPerPageChange(h);},zt=h=>{let D=M.indexOf(h),B=[...M];D===-1?B.push(h):B.splice(D,1),m(B);},st=h=>{let D=y.indexOf(h),B=[...y];D===-1?B.push(h):B.splice(D,1),g(B);},Ot=h=>{e.onLayoutSave&&e.onLayoutSave({visibleColumns:M,order:l,orderBy:i,grouping:y,columnWidths:c});},ct=h=>{h.layout&&(h.layout.visibleColumns&&m(h.layout.visibleColumns),h.layout.order&&n(h.layout.order),h.layout.orderBy&&a(h.layout.orderBy),h.layout.grouping&&g(h.layout.grouping),h.layout.columnWidths&&u(h.layout.columnWidths));},Gt=h=>{let D=h?.layoutData||h?.layout||h||{};D.visibleColumns&&m(D.visibleColumns),D.order&&n(D.order),D.orderBy!==void 0&&a(D.orderBy),D.grouping&&g(D.grouping),D.columnWidths&&u(D.columnWidths),D.showSummary!==void 0&&S(!!D.showSummary),I(new Set),T(0),h?.id&&Oe(h.id);};So.useEffect(()=>{e.layout&&ct({layout:e.layout});},[e.layout]);let Wt=h=>{h.preventDefault(),V(L===null?{mouseX:h.clientX+2,mouseY:h.clientY-6}:null);},$t=()=>{V(null);},dt=So.useMemo(()=>{if(!f)return {};let h={};e.columns.forEach(B=>{if(B.numeric){let ee=oe.reduce((G,Y)=>{let q=parseFloat(Y[B.id]);return G+(isNaN(q)?0:q)},0);h[B.id]=ee.toFixed(2);}else h[B.id]="";});let D=e.columns.find(B=>M.includes(B.id));return D&&!D.numeric&&(h[D.id]="Total"),h},[oe,e.columns,f,M]),_t=()=>{if(!e.columns||!oe)return;let h=e.columns.map(Y=>Y.label).join(","),D=oe.map(Y=>e.columns.map(q=>{let $=Y[q.id];return `"${($==null?"":String($)).replace(/"/g,'""')}"`}).join(",")).join(`
2
+ `),B=`data:text/csv;charset=utf-8,${h}
3
+ ${D}`,ee=encodeURI(B),G=document.createElement("a");G.setAttribute("href",ee),G.setAttribute("download",`${e.title||"export"}.csv`),document.body.appendChild(G),G.click(),document.body.removeChild(G);},jt=()=>{N(true);},Ut=()=>{N(false);};return {isMobile:false,columns:e.columns,order:l,orderBy:i,filterText:t,setFilterText:r,visibleColumns:M,setVisibleColumns:m,showSummary:f,setShowSummary:S,summaryColumns:[],grouping:y,setGrouping:g,expandedGroups:p,setExpandedGroups:I,groupAnchorEl:s,setGroupAnchorEl:R,summaryAnchorEl:v,setSummaryAnchorEl:z,columnWidths:c,setColumnWidths:u,anchorEl:b,setAnchorEl:x,contextMenu:L,setContextMenu:V,sensors:void 0,sortedAndFilteredRows:re,visibleRows:nt,summaryRow:dt,page:d,setPage:it,rowsPerPage:k,setRowsPerPage:lt,selected:C,setSelected:E,isAllExpanded:false,handleColumnResize:rt,handleRequestSort:We,handleSelectAllClick:Nt,handleClick:Ht,toggleSummaryColumn:()=>{},handleDragEnd:()=>{},handleExport:_t,handleContextMenu:Wt,handleCloseContextMenu:$t,toggleColumnVisibility:zt,toggleGroupExpand:at,toggleGroupField:st,handleToggleAll:Vt,handleExpandGroupRecursively:Ge,handleCollapseGroupRecursively:Ft,handleLayoutLoad:Gt,handleVariantLoad:ct,handleLayoutSave:Ot,effectiveAppId:e.appId||"",currentLayoutData:{visibleColumns:M,order:l,orderBy:i,grouping:y,columnWidths:c},currentLayoutId:te,layoutIdToLoad:"",onPageChange:it,onRowsPerPageChange:lt,graphReportOpen:A,handleOpenGraphReport:jt,handleCloseGraphReport:Ut}};var zc=e=>jsxRuntime.jsx(di__default.default,{...e}),Oc=e=>jsxRuntime.jsx(Bo__default.default,{...e}),Gc=e=>jsxRuntime.jsx(Rn__default.default,{...e}),Wc=e=>jsxRuntime.jsx(xa__default.default,{...e}),$c=e=>jsxRuntime.jsx(Ca__default.default,{...e}),Dt=e=>{let{title:o="Data Table",showToolbar:t=true,selectionMode:r,selected:l=[],onSelectionChange:n,actions:i,extraTools:a,fitContainer:d=false,fullWidth:T=false,maxHeight:k,loading:w=false,page:C=0,rowsPerPage:E=20,rowsPerPageOptions:M=[20,50,100,-1],count:m=0,onPageChange:f,onRowsPerPageChange:S,onLayoutSave:y,filterConfig:g,rowKey:p,tableKey:I="default",graphReport:c}=e,{isMobile:u,columns:b,order:x,orderBy:s,filterText:R,setFilterText:v,visibleColumns:z,showSummary:L,setShowSummary:V,summaryColumns:A,grouping:N,setGrouping:te,expandedGroups:Oe,groupAnchorEl:oe,setGroupAnchorEl:re,summaryAnchorEl:ie,setSummaryAnchorEl:De,columnWidths:nt,anchorEl:at,setAnchorEl:Ge,contextMenu:Ft,sensors:Vt,sortedAndFilteredRows:We,summaryRow:rt,visibleRows:Nt,isAllExpanded:Ht,handleColumnResize:it,handleRequestSort:lt,handleSelectAllClick:zt,handleClick:st,toggleSummaryColumn:Ot,handleDragEnd:ct,handleExport:Gt,handleContextMenu:Wt,handleCloseContextMenu:$t,toggleColumnVisibility:dt,toggleGroupExpand:_t,toggleGroupField:jt,handleToggleAll:Ut,handleExpandGroupRecursively:h,handleCollapseGroupRecursively:D,handleLayoutLoad:B,handleVariantLoad:ee,handleLayoutSave:G,effectiveAppId:Y,currentLayoutData:q,currentLayoutId:$,layoutIdToLoad:U,graphReportOpen:fe,handleOpenGraphReport:se,handleCloseGraphReport:Be}=Mn(e),ce=c?.enabled??false,{model:Se}=en({rows:We,config:{...c,title:c?.title||`${o} Graphic Report`}}),$e=Se.table.columns.map(ut=>({id:ut.id,label:ut.label,align:ut.align||"left",minWidth:120,numeric:ut.align==="right"})),Gn=Y?jsxRuntime.jsx(wn,{appId:Y,tableKey:I,currentLayoutData:q,onLayoutLoad:B,targetLayoutId:U,activeLayoutId:$,serviceUrl:(g?.variantService,void 0)}):null,Co=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(_o,{groupAnchorEl:oe,setGroupAnchorEl:re,grouping:N,setGrouping:te,columns:b,toggleGroupField:jt}),jsxRuntime.jsx(jo,{anchorEl:at,setAnchorEl:Ge,columns:b,visibleColumns:z,toggleColumnVisibility:dt}),jsxRuntime.jsx(Uo,{anchorEl:ie,setAnchorEl:De,showSummary:L,setShowSummary:V,columns:b,summaryColumns:A,toggleSummaryColumn:Ot}),jsxRuntime.jsx(Ko,{contextMenu:Ft,handleCloseContextMenu:$t,columns:b,visibleColumns:z,toggleColumnVisibility:dt})]});return u?jsxRuntime.jsxs(bo__default.default,{sx:{display:"flex",flexDirection:"column",gap:2,height:"100%"},children:[g&&jsxRuntime.jsx(Xe,{fields:g.fields,filters:g.filters,onFilterChange:g.onFilterChange,onSearch:g.onSearch,variants:g.variants||[],currentVariantId:g.currentVariantId,onVariantLoad:g.onVariantLoad,onVariantSave:g.onVariantSave,onVariantDelete:g.onVariantDelete,onVariantSetDefault:g.onVariantSetDefault,appId:g.appId,tableKey:I,currentLayout:[{tableKey:I,layoutData:q}],variantService:g.variantService}),jsxRuntime.jsx(Wo,{title:o,loading:w,showSummary:L,setShowSummary:V,setAnchorEl:Ge,setSummaryAnchorEl:De,filterText:R,setFilterText:v,sortedAndFilteredRows:We,selected:l,columns:b,visibleColumns:z,summaryRow:rt,handleClick:st,selectionMode:r}),Co]}):jsxRuntime.jsxs(bo__default.default,{sx:{width:T?"100%":"auto",mb:d?0:2,...d?{flex:1,display:"flex",flexDirection:"column",minHeight:0,height:"100%"}:{}},children:[g&&jsxRuntime.jsx(bo__default.default,{sx:{mb:2},children:jsxRuntime.jsx(Xe,{fields:g.fields,filters:g.filters,onFilterChange:g.onFilterChange,onSearch:g.onSearch,variants:g.variants||[],currentVariantId:g.currentVariantId,onVariantLoad:ee,onVariantSave:g.onVariantSave,onVariantDelete:g.onVariantDelete,onVariantSetDefault:g.onVariantSetDefault,loading:w,appId:g.appId,tableKey:I,currentLayout:[{tableKey:I,layoutData:q}],currentLayoutId:$,layoutRefs:[{tableKey:I,layoutId:$}],variantService:g.variantService})}),jsxRuntime.jsxs(si__default.default,{sx:{width:T?"100%":"auto",mb:d?0:2,display:"flex",flexDirection:"column",overflow:"hidden",...k?{height:k}:d?{flex:1,minHeight:0}:{}},children:[t&&jsxRuntime.jsx(Lo,{filterText:R,setFilterText:v,onRowsPerPageChange:S,rowsPerPage:E,rowsPerPageOptions:M,page:C,count:m,onPageChange:f,actions:i,extraTools:a,grouping:N,setGroupAnchorEl:re,showSummary:L,setShowSummary:V,setAnchorEl:Ge,setSummaryAnchorEl:De,handleExport:Gt,onLayoutSave:y||g?.variantService&&g?.appId?G:void 0,loading:w,layoutManager:Gn,onOpenGraphReport:ce?se:void 0}),jsxRuntime.jsx(Rn__default.default,{sx:{flex:1,maxHeight:k||"calc(100vh - 320px)",overflowY:"auto",overflowX:"auto",position:"relative",minHeight:0},children:jsxRuntime.jsx(core.DndContext,{sensors:Vt,collisionDetection:core.closestCenter,onDragEnd:ct,modifiers:[modifiers.restrictToHorizontalAxis],children:jsxRuntime.jsxs(ci__default.default,{sx:{minWidth:T?750:"auto",width:T?"100%":"auto",tableLayout:Object.keys(nt).length>0?"fixed":"auto",borderCollapse:"separate",borderSpacing:0},"aria-labelledby":"tableTitle",size:"small",stickyHeader:true,children:[jsxRuntime.jsx(Vo,{columns:b,visibleColumns:z,order:x,orderBy:s,onRequestSort:lt,onContextMenu:Wt,selectionMode:r,grouping:N,isAllExpanded:Ht,handleToggleAll:Ut,rowCount:We.length,numSelected:l.length,onSelectAllClick:zt,columnWidths:nt,onColumnResize:it}),jsxRuntime.jsx(Ho,{visibleRows:Nt,columns:b,visibleColumns:z,selectionMode:r,selected:l,orderBy:s,loading:w,expandedGroups:Oe,toggleGroupExpand:_t,handleExpandGroupRecursively:h,handleCollapseGroupRecursively:D,handleClick:st,onSelectionChange:n,grouping:N,rowKeyProp:p,page:C,rowsPerPage:E}),L&&jsxRuntime.jsx(Oo,{showSummary:L,columns:b,visibleColumns:z,summaryRow:rt,selectionMode:r?.toString(),orderBy:s,zIndex:3})]})})})]}),Co,ce&&jsxRuntime.jsx(Zo,{open:fe,onClose:Be,model:Se,tableContent:jsxRuntime.jsx(Dt,{title:"Data Body",columns:$e,rows:Se.table.rows,rowKey:"id",fullWidth:true,maxHeight:"420px",rowsPerPage:20,rowsPerPageOptions:[20,50,100],graphReport:{enabled:false}})})]})},_c=Dt;var Jc=({title:e,hideHeader:o=true,filterConfig:t,tableProps:r,children:l,spacing:n=1})=>jsxRuntime.jsxs(Po,{title:e,hideHeader:o,children:[jsxRuntime.jsxs(material.Stack,{spacing:n,sx:{height:"100%",overflow:"hidden"},children:[t&&jsxRuntime.jsx(material.Box,{sx:{flexShrink:0},children:jsxRuntime.jsx(Xe,{...t})}),jsxRuntime.jsx(material.Box,{sx:{flex:1,minHeight:0,overflow:"hidden"},children:jsxRuntime.jsx(Dt,{...r,fitContainer:true,filterConfig:void 0})})]}),l]});var td=({metadata:e,fetchData:o})=>{let[t,r]=So.useState(false),[l,n]=So.useState([]),[i,a]=So.useState({}),[d,T]=So.useState(e.variants||[]),[k,w]=So.useState(e.layout||null),[C,E]=So.useState(0),[M,m]=So.useState(0),[f,S]=So.useState(10),[y,g]=So.useState([]),[p,I]=So.useState("asc"),[c,u]=So.useState("");So.useEffect(()=>{let A={};e.filters.forEach(N=>{N.defaultValue!==void 0&&(A[N.id]=N.defaultValue);}),a(A);},[e.filters]);let b=So.useCallback(async(A,N,te,Oe,oe)=>{r(true);try{let re={...A,page:N+1,limit:te,sort:oe,order:Oe},ie;o?ie=await o(re):typeof e.api=="function"?ie=await e.api(re):e.api&&typeof e.api=="object"?(console.log("Fetching from URL:",e.api.url,re),ie={rows:[],total:0}):(console.warn("No API configured for report"),ie={rows:[],total:0}),ie&&(n(ie.rows||[]),E(ie.total||0));}catch(re){console.error("Failed to fetch report data",re);}finally{r(false);}},[e.api,o]);So.useEffect(()=>{b(i,M,f,p,c);},[b,M,f,p,c]);let x=()=>{m(0),b(i,0,f,p,c);},s=(A,N)=>{I(N),u(A);},R=A=>{a(A);},v=A=>{if(A.filters){let N=A.filters.find(te=>te.scope==="default"||te.scope===e.id);N&&(a(N.filters),b(N.filters,0,f));}A.layout&&w(A.layout);},z=A=>{let N={...A,id:Date.now().toString(),createdAt:new Date().toISOString()};T(te=>[...te,N]);},L=A=>{w(A);};return {pageProps:{title:e.title,filterConfig:{appId:e.id,fields:e.filters,filters:i,onFilterChange:R,onSearch:x,onVariantLoad:v,onVariantSave:z,onVariantDelete:A=>T(N=>N.filter(te=>te.id!==A)),onVariantSetDefault:A=>{T(N=>N.map(te=>({...te,isDefault:te.id===A})));},variants:d},tableProps:{appId:e.id,columns:e.columns,rows:l,loading:t,rowKey:"id",count:C,page:M,rowsPerPage:f,rowsPerPageOptions:[10,25,50,100],onPageChange:m,onRowsPerPageChange:S,selectionMode:"multiple",selected:y,onSelectionChange:g,onLayoutSave:L,layout:k,title:e.title,showSummary:true,order:p,orderBy:c,onSortChange:s,graphReport:e.graphReport||{enabled:true,title:`${e.title} Graphic Report`}}},filters:i,rows:l,loading:t,refresh:x}};var Nn=64,Ai="#E9EDF2",Fi="linear-gradient(90deg, #F5F7FA 0%, #E9EDF2 50%, #F5F7FA 100%)",Hn=({appTitle:e,logo:o,mode:t="dark",onToggleMode:r,localeLabel:l="EN",searchPlaceholder:n="Ask me...",onSearch:i,user:a,leftSlot:d,rightSlot:T})=>{let w=material.useTheme().palette.mode==="dark",[C,E]=So.useState(""),[M,m]=So.useState(null),f=p=>{p.preventDefault(),i&&i(C.trim());},S=t==="system"?jsxRuntime.jsx(Di__default.default,{fontSize:"small"}):t==="dark"?jsxRuntime.jsx(Pi__default.default,{fontSize:"small"}):jsxRuntime.jsx(Ei__default.default,{fontSize:"small"}),y=t==="system"?"Theme: System":t==="dark"?"Theme: Dark":"Theme: Light",g=!!M;return jsxRuntime.jsxs(material.AppBar,{position:"sticky",elevation:0,sx:p=>({top:0,zIndex:p.zIndex.drawer+10,height:Nn,backgroundColor:p.palette.mode==="dark"?"#0D0D0D":Ai,backgroundImage:p.palette.mode==="dark"?["radial-gradient(circle at 18% 22%, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0) 45%)","radial-gradient(circle at 78% 32%, rgba(144,202,249,0.14) 0%, rgba(144,202,249,0) 42%)","linear-gradient(90deg, #0A0A0A 0%, #151515 50%, #0A0A0A 100%)","linear-gradient(rgba(255,255,255,0.04) 1px, transparent 1px)","linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px)"].join(","):["radial-gradient(circle at 22% 22%, rgba(255,255,255,0.7) 0%, rgba(255,255,255,0) 48%)","radial-gradient(circle at 76% 24%, rgba(203,213,225,0.45) 0%, rgba(203,213,225,0) 42%)",Fi,"linear-gradient(rgba(15,23,42,0.05) 1px, transparent 1px)","linear-gradient(90deg, rgba(15,23,42,0.04) 1px, transparent 1px)"].join(","),backgroundSize:"auto, auto, auto, 24px 24px, 24px 24px",borderBottom:"1px solid",borderColor:p.palette.mode==="dark"?"rgba(255,255,255,0.12)":"rgba(15,23,42,0.12)"}),children:[jsxRuntime.jsxs(material.Toolbar,{sx:{minHeight:`${Nn}px !important`,px:2,gap:2},children:[jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:1.5,sx:{minWidth:220},children:[o||jsxRuntime.jsx(material.Box,{component:"img",src:"/orbcafe.png",alt:"ORBCAFE Logo",sx:{width:44,height:44,display:"block",objectFit:"contain",flexShrink:0}}),e&&jsxRuntime.jsx(material.Typography,{variant:"h6",sx:{fontWeight:700,color:w?"common.white":"#111827"},children:e}),d]}),jsxRuntime.jsx(material.Box,{sx:{flex:1,display:"flex",justifyContent:"center",minWidth:0},children:jsxRuntime.jsx(material.Box,{component:"form",onSubmit:f,sx:{width:"100%",maxWidth:540},children:jsxRuntime.jsx(material.TextField,{size:"small",fullWidth:true,value:C,onChange:p=>E(p.target.value),placeholder:n,InputProps:{startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(mn__default.default,{sx:{color:w?"rgba(255,255,255,0.7)":"rgba(15,23,42,0.55)",fontSize:18}})}),sx:{color:w?"common.white":"rgba(17,24,39,0.9)",bgcolor:w?"rgba(255,255,255,0.08)":"#ffffff",borderRadius:999,"& .MuiOutlinedInput-notchedOutline":{borderColor:w?"rgba(255,255,255,0.15)":"rgba(15,23,42,0.2)"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:w?"rgba(255,255,255,0.35)":"rgba(15,23,42,0.35)"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:w?"rgba(255,255,255,0.5)":"rgba(15,23,42,0.55)"}}},inputProps:{style:{color:w?"white":"#111827"}}})})}),jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:1.5,children:[jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:.5,children:[jsxRuntime.jsx(Ri__default.default,{sx:{color:w?"common.white":"#111827",fontSize:18}}),jsxRuntime.jsx(material.Typography,{variant:"caption",sx:{color:w?"common.white":"#111827",fontWeight:500},children:l})]}),jsxRuntime.jsx(material.IconButton,{size:"small",sx:{color:w?"common.white":"#111827"},onClick:r,title:y,children:S}),a&&jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:1,children:[jsxRuntime.jsxs(material.Box,{sx:{textAlign:"right",minWidth:0},children:[jsxRuntime.jsx(material.Typography,{variant:"body2",sx:{color:w?"common.white":"#111827",fontWeight:700,lineHeight:1.15},children:a.name}),a.subtitle&&jsxRuntime.jsx(material.Typography,{variant:"caption",sx:{display:"block",mt:.25,color:w?"rgba(255,255,255,0.72)":"rgba(17,24,39,0.62)",fontSize:"0.72rem",lineHeight:1.1,letterSpacing:"0.01em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:220},title:a.subtitle,children:a.subtitle})]}),jsxRuntime.jsx(material.IconButton,{size:"small",onClick:p=>m(p.currentTarget),sx:{p:0},children:jsxRuntime.jsx(material.Avatar,{src:a.avatarSrc,imgProps:{style:{objectFit:"cover"}},sx:{width:34,height:34,bgcolor:"grey.100",color:"grey.700",fontSize:"0.85rem"},children:a.avatarText||a.name.slice(0,1).toUpperCase()})})]}),T]})]}),jsxRuntime.jsxs(material.Menu,{anchorEl:M,open:g,onClose:()=>m(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},slotProps:{paper:{sx:{minWidth:160,"& .MuiMenuItem-root":{minHeight:34,py:.5,px:1.25}}}},children:[jsxRuntime.jsxs(material.MenuItem,{onClick:()=>m(null),children:[jsxRuntime.jsx(material.ListItemIcon,{children:jsxRuntime.jsx(zr__default.default,{sx:{fontSize:18}})}),jsxRuntime.jsx(material.ListItemText,{primary:"Setting",slotProps:{primary:{sx:{fontSize:"0.86rem",fontWeight:500}}}})]}),jsxRuntime.jsxs(material.MenuItem,{onClick:()=>m(null),children:[jsxRuntime.jsx(material.ListItemIcon,{children:jsxRuntime.jsx(Bi__default.default,{sx:{fontSize:18}})}),jsxRuntime.jsx(material.ListItemText,{primary:"Logout",slotProps:{primary:{sx:{fontSize:"0.86rem",fontWeight:500}}}})]})]})]})};var zn=({menuData:e=[],initialNavigationCollapsed:o=false}={})=>{let{navigationIslandProps:t}=Do({initialCollapsed:o,content:e}),[r,l]=So.useState(900);So.useEffect(()=>{let i=()=>l(window.innerHeight);return i(),window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)},[]);let n=So.useMemo(()=>Math.max(280,r-100),[r]);return {navigationIslandProps:t,navigationMaxHeight:n}};var Td=({appTitle:e,menuData:o=[],children:t,showNavigation:r=true,localeLabel:l,user:n,logo:i,onSearch:a,rightHeaderSlot:d,leftHeaderSlot:T,contentSx:k})=>{let[w,C]=So.useState("system"),[E,M]=So.useState("light"),[m,f]=So.useState(false),S=w==="system"?m?E:"light":w;So.useEffect(()=>{f(true);let I=window.matchMedia("(prefers-color-scheme: dark)"),c=()=>{M(I.matches?"dark":"light");};return c(),I.addEventListener("change",c),()=>I.removeEventListener("change",c)},[]);let y=So.useMemo(()=>material.createTheme({palette:{mode:S}}),[S]),{navigationIslandProps:g,navigationMaxHeight:p}=zn({menuData:o,initialNavigationCollapsed:false});return jsxRuntime.jsx(material.ThemeProvider,{theme:y,children:jsxRuntime.jsxs(material.Box,{sx:I=>({minHeight:"100vh",display:"flex",flexDirection:"column",background:I.palette.mode==="dark"?"linear-gradient(180deg, #0A0A0A 0%, #141414 55%, #1A1A1A 100%)":I.palette.background.default}),children:[jsxRuntime.jsx(Hn,{appTitle:e,logo:i,mode:w,onToggleMode:()=>C(I=>I==="system"?"dark":I==="dark"?"light":"system"),localeLabel:l,user:n,onSearch:a,leftSlot:T,rightSlot:d}),jsxRuntime.jsxs(material.Box,{sx:{flex:1,minHeight:0,display:"flex"},children:[r&&jsxRuntime.jsx(material.Box,{sx:{p:1.5,display:"flex",alignItems:"flex-start",flexShrink:0},children:jsxRuntime.jsx(Mo,{...g,maxHeight:p,colorMode:S})}),jsxRuntime.jsx(material.Box,{sx:{flex:1,minWidth:0,minHeight:0,overflow:"auto",p:1.5,...k},children:t})]})]})})};exports.Button=Yt;exports.CAppHeader=Hn;exports.CAppPageLayout=Td;exports.CLayoutManagement=Sn;exports.CLayoutManager=wn;exports.CPageLayout=Po;exports.CSmartFilter=Xe;exports.CSmartTable=_c;exports.CStandardPage=Jc;exports.CTable=Dt;exports.CTableBody=zc;exports.CTableCell=Oc;exports.CTableContainer=Gc;exports.CTableHead=Wc;exports.CTableRow=$c;exports.CVariantManagement=vt;exports.CVariantManager=sn;exports.NavigationIsland=Mo;exports.TreeMenu=Xt;exports.buttonVariants=Un;exports.useNavigationIsland=Do;exports.usePageLayout=zn;exports.useStandardReport=td;
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import*as bo from'react';import bo__default,{useState,useEffect,useCallback,useMemo,useRef}from'react';import {usePathname,useRouter}from'next/navigation';import {ChevronRight,Search}from'lucide-react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {Slot}from'@radix-ui/react-slot';import {cva}from'class-variance-authority';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {styled,Box,Typography,Autocomplete,TextField,Tooltip,IconButton,Dialog,DialogTitle,DialogContent,FormControlLabel,Checkbox,DialogActions,Button,Paper,Menu,MenuItem,ListItemText,Divider,Collapse,Grid,ListItemIcon,Stack,useTheme,AppBar,Toolbar,InputAdornment,Avatar,createTheme,ThemeProvider,Popover,ListSubheader,Badge,Switch,TableBody,TableRow,TableCell,TableFooter,Chip}from'@mui/material';import mo from'@mui/material/Box';import oi from'@mui/material/Paper';import ni from'@mui/material/Table';import ai from'@mui/material/TableBody';import Do from'@mui/material/TableCell';import wn from'@mui/material/TableContainer';import pa from'@mui/material/TableHead';import ma from'@mui/material/TableRow';import {DndContext,closestCenter}from'@dnd-kit/core';import {restrictToHorizontalAxis}from'@dnd-kit/modifiers';import cn from'@mui/icons-material/Search';import na from'@mui/icons-material/ViewColumn';import yn from'@mui/icons-material/Save';import ra from'@mui/icons-material/Download';import ia from'@mui/icons-material/AccountTree';import la from'@mui/icons-material/Functions';import sa from'@mui/icons-material/Insights';import ga from'@mui/material/Checkbox';import fa from'@mui/material/TableSortLabel';import Ca from'@mui/icons-material/KeyboardArrowRight';import va from'@mui/icons-material/KeyboardArrowDown';import La from'@mui/icons-material/Check';import Aa from'@mui/icons-material/ClearAll';import Ua from'@mui/icons-material/Close';import Br from'@mui/icons-material/Settings';import Lr from'@mui/icons-material/KeyboardArrowUp';import Fr from'@mui/icons-material/ArrowRightAlt';import rr from'@mui/icons-material/Star';import {DateCalendar}from'@mui/x-date-pickers/DateCalendar';import {PickersDay}from'@mui/x-date-pickers/PickersDay';import Cr from'@mui/icons-material/CalendarMonth';import vr from'@mui/icons-material/Clear';import Sr from'@mui/icons-material/ArrowForward';import De from'dayjs';import Tr from'dayjs/plugin/isBetween';import Kr from'@mui/icons-material/Delete';import qr from'@mui/icons-material/StarBorder';import Xr from'@mui/icons-material/ViewQuilt';import Ti from'@mui/icons-material/Language';import wi from'@mui/icons-material/DesktopWindows';import Ii from'@mui/icons-material/DarkMode';import ki from'@mui/icons-material/LightMode';function re(...e){return twMerge(clsx(e))}var $t={primary:"#000000",primaryHover:"#333333"},dt={primary:"bg-primary text-primary-foreground hover:bg-primary/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",ghost:"hover:bg-accent hover:text-accent-foreground"},$e={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",full:"rounded-full"},yo=()=>"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50";var Hn=cva(yo(),{variants:{variant:{default:`${dt.primary} shadow-sm`,destructive:"bg-red-500 text-white hover:bg-red-600 active:bg-red-700 dark:bg-red-600 dark:hover:bg-red-500 dark:active:bg-red-700 shadow-sm",outline:`${dt.outline} shadow-sm`,secondary:"bg-gray-200 text-gray-700 hover:bg-gray-300 active:bg-gray-400 dark:bg-gray-700 dark:text-gray-200 dark:hover:bg-gray-600 dark:active:bg-gray-500 shadow-sm",ghost:dt.ghost,link:"text-blue-600 dark:text-blue-400 underline-offset-4 hover:underline hover:text-blue-700 dark:hover:text-blue-300 active:text-blue-800 dark:active:text-blue-200","chat-tool":"bg-[var(--orbai-surface-2)] border border-[var(--orbai-border-soft)] text-[var(--orbai-text-2)] hover:bg-[var(--orbai-surface-3)] hover:border-[var(--orbai-border-strong)] hover:text-[var(--orbai-text-1)] active:scale-95 transition-all duration-200","chat-send":`bg-[${$t.primary}] hover:bg-[${$t.primaryHover}] text-white border border-[var(--orbai-border-strong)] shadow-[var(--orbai-shadow-soft-sm)] hover:shadow-[var(--orbai-shadow-soft-md)] active:scale-95 transition-all duration-200`,"chat-stop":"bg-red-500 hover:bg-red-600 border border-[var(--orbai-border-strong)] shadow-[var(--orbai-shadow-soft-sm)] hover:shadow-[var(--orbai-shadow-soft-md)] active:scale-95 text-white transition-all duration-200","chat-disabled":"cursor-not-allowed opacity-50 bg-[var(--orbai-surface-2)] border border-[var(--orbai-border-soft)] text-[var(--orbai-muted)]"},size:{default:"h-10 px-4 py-2",sm:"h-9 px-3",lg:"h-11 px-8",icon:"h-10 w-10","chat-sm":"h-8 w-8 rounded-full","chat-md":"h-10 w-10 rounded-full","chat-lg":"h-12 w-12 rounded-full"},rounded:{none:$e.none,sm:$e.sm,md:$e.md,full:$e.full}},defaultVariants:{variant:"default",size:"default",rounded:"md"}}),_t=bo.forwardRef(({className:e,variant:o,size:t,asChild:i=false,...s},a)=>jsx(i?Slot:"button",{className:re(Hn({variant:o,size:t,className:e})),ref:a,...s}));_t.displayName="Button";function Ut({items:e,onItemClick:o,className:t="",level:i=0,expandedIds:s,onToggleExpand:a,colorMode:l="light"}){let n=l==="dark",u=usePathname(),[v,w]=useState(new Set),S=s!==void 0&&a!==void 0,x=S?s:v,P=m=>{if(S)a(m);else {let g=new Set(v);g.has(m)?g.delete(m):g.add(m),w(g);}},k=m=>{m.children&&m.children.length>0&&P(m.id),o&&o(m);};return !e||!Array.isArray(e)?jsx("div",{className:re("tree-menu",t),children:jsx("div",{className:"text-sm text-gray-500 p-2",children:"No items to display"})}):jsx("div",{className:re("tree-menu",t),children:e.map(m=>{let g=x.has(m.id)||m.isExpanded,y=m.children&&m.children.length>0,d=m.appurl||m.href,I=d?u===d:false;return jsxs("div",{className:"tree-menu-item relative",children:[I&&jsx("div",{className:re("absolute left-0 top-2 bottom-2 w-[3px] rounded-r-full z-10",n?"bg-[#90caf9]":"bg-[#1976d2]")}),jsxs(_t,{variant:"ghost",className:re("w-full justify-start gap-2 h-auto py-2 relative overflow-hidden group",`ml-${i*4}`,I?n?"bg-transparent text-[#90caf9] hover:bg-gray-800/35":"bg-transparent text-[#1976d2] hover:bg-gray-100/60":n?"hover:bg-gray-800/50 text-gray-300":"hover:bg-gray-100/50 text-gray-700"),onClick:()=>k(m),children:[y&&jsx("div",{className:re("flex-shrink-0 transition-transform duration-200",g&&"rotate-90",I?n?"text-[#90caf9]":"text-[#1976d2]":n?"text-gray-500 group-hover:text-gray-300":"text-gray-400 group-hover:text-gray-600"),children:jsx(ChevronRight,{className:"h-4 w-4"})}),!y&&jsx("div",{className:"w-4 h-4 flex-shrink-0"}),m.icon&&jsx("div",{className:re("flex-shrink-0 transition-colors duration-200",I?n?"text-[#90caf9]":"text-[#1976d2]":n?"text-gray-500 group-hover:text-gray-300":"text-gray-400 group-hover:text-gray-600"),children:m.icon}),jsxs("div",{className:"flex-1 text-left overflow-hidden z-10",children:[jsx("div",{className:re("text-sm truncate transition-colors duration-200",I?"font-semibold":"font-medium"),children:m.title||m.label}),m.description&&jsx("div",{className:re("text-xs truncate transition-colors duration-200",I?n?"text-[#90caf9]/70":"text-[#1976d2]/75":n?"text-gray-400":"text-gray-500"),title:m.description,children:m.description})]})]}),y&&jsx("div",{className:re("grid transition-[grid-template-rows] duration-300 ease-in-out",g?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:jsx("div",{className:"overflow-hidden",children:jsx(Ut,{items:m.children,onItemClick:o,level:i+1,expandedIds:s,onToggleExpand:a,colorMode:l})})})]},m.id)})})}var To=({collapsed:e,onToggle:o,className:t="",maxHeight:i,menuData:s=[],colorMode:a="light"})=>{let l=a==="dark",n=useRouter(),[u,v]=useState(""),[w,S]=useState(new Set);useEffect(()=>{e&&S(new Set);},[e]);let x=useCallback(g=>{let y=[],d=I=>{I.forEach(r=>{y.push(r.id),r.children&&d(r.children);});};return d(g),y},[]),P=useMemo(()=>{if(!u.trim())return s;let g=y=>y.reduce((d,I)=>{let r=I.title?.toLowerCase().includes(u.toLowerCase())||I.description?.toLowerCase().includes(u.toLowerCase()),b=I.children?g(I.children):[];return (r||b.length>0)&&d.push({...I,children:b.length>0?b:I.children}),d},[]);return g(s)},[u,s]),k=useMemo(()=>u.trim()?new Set(x(s)):w,[u,s,w,x]),m=useCallback(async g=>{if(console.log("\u{1F5B1}\uFE0F \u5BFC\u822A\u83DC\u5355\u9879\u70B9\u51FB:",g),g.id==="chat"||g.appurl==="/chat"){console.log("\u{1F4AC} \u68C0\u6D4B\u5230chat\u83DC\u5355\u70B9\u51FB\uFF0C\u8DF3\u8F6C\u5230\u65B0\u7684\u804A\u5929\u89C6\u56FE");try{n.push("/chat?new=true");}catch(d){console.error("\u274C \u65E0\u6CD5\u8DF3\u8F6C\u5230\u65B0\u804A\u5929\u89C6\u56FE:",d),n.push("/chat");}return}let y=g.appurl||g.href;y&&(y.startsWith("http://")||y.startsWith("https://")?window.open(y,"_blank"):n.push(y));},[n]);return jsxs("div",{className:`flex flex-col backdrop-blur-xl border shadow-[0_4px_8px_0_rgba(31,38,135,0.1)] ${e?"w-14 rounded-full":"w-[234px] rounded-2xl"} relative ${t} ${l?"bg-[#111111] border-white/10":"bg-white/70 border-white/30"}`,style:{backdropFilter:"blur(16px) saturate(180%)",WebkitBackdropFilter:"blur(16px) saturate(180%)",transition:"width 400ms cubic-bezier(0.4, 0.0, 0.2, 1), border-radius 0ms cubic-bezier(0.4, 0.0, 0.2, 1), box-shadow 400ms ease-out",maxHeight:i?`${i}px`:void 0},children:[jsx("div",{className:`pt-4 pb-2 transition-all duration-500 ease-in-out ${e?"px-1":"px-2"}`,children:e?jsx("div",{className:"flex justify-center",children:jsx("button",{onClick:o,className:`w-10 h-10 flex items-center justify-center rounded-lg transition-colors duration-200 ${l?"text-gray-300 hover:bg-gray-800":"text-gray-500 hover:bg-gray-50"}`,title:"\u5C55\u5F00\u5BFC\u822A",children:jsx(Search,{className:"h-5 w-5"})})}):jsxs("div",{className:`relative transition-opacity duration-300 ${e?"opacity-0":"opacity-100 delay-200"}`,children:[jsx("input",{type:"text",placeholder:"\u641C\u7D22\u83DC\u5355...",value:u,onChange:g=>v(g.target.value),className:`w-full pl-10 pr-4 py-2 text-sm border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent ${l?"border-gray-700 bg-[#1A1A1A] text-white placeholder-gray-400":"border-gray-300 bg-white text-gray-900 placeholder-gray-500"}`}),jsx("div",{className:"absolute left-3 top-1/2 transform -translate-y-1/2 pointer-events-none",children:jsx(Search,{className:`h-4 w-4 ${l?"text-gray-500":"text-gray-400"}`})})]})}),jsx("nav",{className:`flex-1 pb-4 transition-all duration-500 ease-in-out overflow-y-auto min-h-0 ${e?"px-1":"px-2"}`,children:P.length===0?jsx("div",{className:"flex items-center justify-center py-8 text-gray-500 text-sm",children:e?"\u{1F4C2}":u?"\u672A\u627E\u5230\u5339\u914D\u7684\u83DC\u5355\u9879":"\u6682\u65E0\u53EF\u8BBF\u95EE\u7684\u5E94\u7528"}):jsxs(Fragment,{children:[!e&&jsx("div",{className:`transition-opacity duration-300 ${e?"opacity-0":"opacity-100 delay-200"}`,children:jsx(Ut,{items:P,onItemClick:m,className:"space-y-1",expandedIds:k,colorMode:a,onToggleExpand:g=>{let y=new Set(w);P.some(I=>I.id===g)?y.has(g)?y.delete(g):(P.forEach(I=>{I.id!==g&&y.has(I.id)&&y.delete(I.id);}),y.add(g)):y.has(g)?y.delete(g):y.add(g),S(y);}})}),e&&jsx("div",{className:"space-y-2",children:s.map(g=>jsx("div",{className:"space-y-1",children:jsx("button",{onClick:()=>{o();let y=new Set([g.id]);S(y);},className:`w-full flex items-center justify-center p-2 rounded-lg cursor-pointer transition-colors duration-200 ${l?"text-gray-400 hover:bg-gray-800":"text-gray-600 hover:bg-gray-50"}`,title:`\u5C55\u5F00\u67E5\u770B ${g.title}`,children:g.icon||jsx("div",{className:`w-6 h-6 rounded text-xs flex items-center justify-center font-medium ${l?"bg-[#90caf9] text-[#0b0b0b]":"bg-[#1976d2] text-white"}`,children:g.title?.charAt(0)||"?"})})},g.id))})]})}),!e&&jsx("button",{onClick:o,className:`absolute -bottom-1 -right-1 w-6 h-6 bg-transparent rounded-full flex items-center justify-center transition-all duration-300 ease-in-out z-20 ${l?"hover:bg-gray-800/50":"hover:bg-white/20"}`,title:"\u6298\u53E0\u5BFC\u822A",children:jsx("div",{className:"absolute",style:{bottom:"0px",right:"0px",width:"16px",height:"16px",overflow:"hidden"},children:jsx("div",{className:l?"border-yellow-400":"",style:{width:"32px",height:"32px",borderRadius:"16px",border:"3px solid #21BCFF",backgroundColor:"transparent",position:"absolute",top:"-16px",left:"-16px"}})})})]})};var Io=(e={})=>{let{initialCollapsed:o=false,content:t=[]}=e,[i,s]=useState(o),[a,l]=useState(t),n=useCallback(()=>{s(v=>!v);},[]),u=useMemo(()=>({collapsed:i,onToggle:n,menuData:a}),[i,n,a]);return {collapsed:i,setCollapsed:s,toggleCollapsed:n,menuData:a,setMenuData:l,navigationIslandProps:u}};var ko=({title:e,hideHeader:o,children:t})=>jsxs(Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[!o&&jsx(Box,{sx:{mb:2},children:jsx(Typography,{variant:"h4",children:e})}),jsx(Box,{sx:{flex:1,overflow:"hidden"},children:t})]});var Ro=e=>{let o="0.75rem";return jsxs(Toolbar,{sx:{pl:{sm:2},pr:{xs:1,sm:1},alignItems:"center"},children:[jsx(Typography,{sx:{flex:"1 1 100%",fontWeight:"bold"},variant:"h6",id:"tableTitle",component:"div",children:e.title||"Table"}),jsxs(Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsx(TextField,{size:"small",placeholder:"Search...",value:e.filterText,onChange:t=>e.setFilterText(t.target.value),InputProps:{sx:{fontSize:o,"& .MuiInputBase-input":{fontSize:o},"& .MuiInputBase-input::placeholder":{fontSize:o,opacity:1}},startAdornment:jsx(InputAdornment,{position:"start",children:jsx(cn,{fontSize:"small"})})},sx:{width:300}}),jsx(Tooltip,{title:"Group By",children:jsx(IconButton,{onClick:t=>e.setGroupAnchorEl(t.currentTarget),children:jsx(Badge,{badgeContent:e.grouping?.length,color:"primary",children:jsx(ia,{})})})}),jsx(Tooltip,{title:"Summary",children:jsx(IconButton,{onClick:t=>e.setSummaryAnchorEl(t.currentTarget),color:e.showSummary?"primary":"default",children:jsx(la,{})})}),jsx(Tooltip,{title:"Columns",children:jsx(IconButton,{onClick:t=>e.setAnchorEl(t.currentTarget),children:jsx(na,{})})}),jsx(Tooltip,{title:"Export",children:jsx(IconButton,{onClick:e.handleExport,children:jsx(ra,{})})}),e.onOpenGraphReport&&jsx(Tooltip,{title:"Graphic Report",children:jsx(IconButton,{onClick:e.onOpenGraphReport,children:jsx(sa,{})})}),e.onLayoutSave&&!e.layoutManager&&jsx(Tooltip,{title:"Save Layout",children:jsx(IconButton,{onClick:t=>e.onLayoutSave(t),children:jsx(yn,{})})}),e.layoutManager]})]})};var Bo=e=>{let{onSelectAllClick:o,order:t,orderBy:i,numSelected:s=0,rowCount:a=0,onRequestSort:l,columns:n,visibleColumns:u,selectionMode:v,onColumnResize:w,columnWidths:S}=e,[x,P]=useState(null),k=useRef(null),m=r=>b=>{x||l(r);},g=(r,b,c)=>{r.preventDefault(),r.stopPropagation(),P(b),k.current={startX:r.clientX,startWidth:c,colId:b},document.addEventListener("mousemove",y),document.addEventListener("mouseup",d),document.body.style.cursor="col-resize";},y=r=>{if(!k.current)return;let{startX:b,startWidth:c,colId:C}=k.current,M=r.clientX-b,T=Math.max(50,c+M);w&&w(C,T);},d=()=>{P(null),k.current=null,document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",d),document.body.style.cursor="";};return useEffect(()=>()=>{document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",d);},[]),jsx(pa,{children:jsxs(ma,{children:[(v==="multiple"||v==="single")&&jsx(Do,{padding:"checkbox",sx:r=>({width:48,backgroundColor:r.palette.mode==="dark"?"#000000":"#f5f5f5",color:r.palette.mode==="dark"?"#ffffff":r.palette.text.primary}),children:jsx(ga,{color:"primary",indeterminate:s>0&&s<a,checked:a>0&&s===a,onChange:o,disabled:v==="single"})}),n.filter(r=>u.includes(r.id)).map(r=>{let b=S?.[r.id]||r.minWidth||100;return jsxs(Do,{align:"left",padding:r.disablePadding?"none":"normal",sortDirection:i===r.id?t:false,style:{width:b,minWidth:b,maxWidth:b},sx:c=>({position:"relative",backgroundColor:c.palette.mode==="dark"?"#000000":"#f5f5f5",color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary,fontWeight:"bold",userSelect:"none"}),children:[jsx(fa,{active:i===r.id,direction:i===r.id?t:"asc",onClick:m(r.id),sx:c=>({"&.MuiTableSortLabel-root":{width:"100%"},"& .MuiTableSortLabel-icon":{color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary,opacity:i===r.id?1:0,transition:"opacity 0.2s"},"&:hover .MuiTableSortLabel-icon":{opacity:.5},"&.Mui-active .MuiTableSortLabel-icon":{opacity:1,color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary},fontWeight:"bold",color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary}),children:jsx(mo,{component:"span",sx:{overflow:"visible",textOverflow:"clip",whiteSpace:"normal",lineHeight:1.2,wordBreak:"break-word",pr:1},children:r.label})}),jsx(mo,{onMouseDown:c=>g(c,r.id,typeof b=="number"?b:100),onClick:c=>c.stopPropagation(),sx:{position:"absolute",right:0,top:0,bottom:0,width:5,cursor:"col-resize","&:hover":{backgroundColor:"primary.main",opacity:.5},zIndex:1}})]},r.id)})]})})};var Ao=e=>{let{visibleRows:o,visibleColumns:t,selected:i=[],handleClick:s,columns:a,toggleGroupExpand:l,expandedGroups:n=new Set,selectionMode:u}=e,v=x=>i.indexOf(x)!==-1,w=u==="multiple"||u==="single",S=t.length+(w?1:0);return jsxs(TableBody,{children:[o.map((x,P)=>{if(x.type==="group"){let k=n.has(x.id),m=x.childIds||[],g=m.filter(r=>v(r)).length,y=m.length>0&&g===m.length,d=g>0&&g<m.length,I=r=>{if(r.stopPropagation(),!!e.onSelectionChange)if(y){let b=i.filter(c=>!m.includes(c));e.onSelectionChange(b);}else {let b=Array.from(new Set([...i,...m]));e.onSelectionChange(b);}};return jsx(TableRow,{sx:{backgroundColor:"#f5f5f5"},children:jsx(TableCell,{colSpan:S,sx:{py:1,pl:x.level*4+2},children:jsxs(Box,{sx:{display:"flex",alignItems:"center"},children:[jsx(IconButton,{size:"small",onClick:()=>l&&l(x.id),sx:{mr:1},children:k?jsx(va,{}):jsx(Ca,{})}),w&&jsx(Checkbox,{size:"small",checked:y,indeterminate:d,onChange:I,onClick:r=>r.stopPropagation(),sx:{mr:1,p:.5}}),jsxs(Typography,{variant:"body2",fontWeight:"bold",children:[x.field,": ",x.value," (",x.count,")"]})]})})},x.id)}else {let k=x.data||x,m=x.id||k.id||P,g=v(m),y=`enhanced-table-checkbox-${P}`,I=(x.level!==void 0?x.level:0)*4;return jsxs(TableRow,{hover:true,onClick:r=>s&&s(r,k),role:"checkbox","aria-checked":g,tabIndex:-1,selected:g,sx:{cursor:"pointer"},children:[w&&jsx(TableCell,{padding:"checkbox",sx:{pl:I>0?I+1:void 0},children:jsx(Checkbox,{color:"primary",checked:g,inputProps:{"aria-labelledby":y}})}),a.filter(r=>t.includes(r.id)).map((r,b)=>{let C=!w&&b===0&&I>0?{pl:I+2}:{};return jsx(TableCell,{align:"left",sx:C,children:r.render?r.render(k[r.id],k):(function(){let T=k[r.id];if(r.numeric){if(typeof T=="number")return T.toLocaleString();if(typeof T=="string"&&T.trim()!==""&&!isNaN(Number(T)))return Number(T).toLocaleString()}return T})()},r.id)})]},m)}}),o.length===0&&jsx(TableRow,{children:jsx(TableCell,{colSpan:S,align:"center",children:"No data"})})]})};var Vo=e=>{let{visibleColumns:o,summaryRow:t,selectionMode:i}=e;if(!e.showSummary)return null;let s=i==="multiple"||i==="single";return jsx(TableFooter,{sx:{position:"sticky",bottom:0,zIndex:e.zIndex,bgcolor:"background.paper"},children:jsxs(TableRow,{children:[s&&jsx(TableCell,{padding:"checkbox",sx:{bgcolor:"background.paper"}}),o.map(a=>jsx(TableCell,{sx:{fontWeight:"bold",fontSize:"0.875rem",bgcolor:"background.paper",color:"text.primary"},children:(function(){let n=t[a];return n==null||n===""?"":typeof n=="number"?n.toLocaleString():typeof n=="string"&&n.trim()!==""&&!isNaN(Number(n))?Number(n).toLocaleString():n})()},a))]})})};var Ho=e=>jsx(Box,{sx:{p:2},children:jsx(Typography,{children:"Mobile View Not Implemented"})});var Oo=({groupAnchorEl:e,setGroupAnchorEl:o,grouping:t,setGrouping:i,columns:s,toggleGroupField:a})=>jsxs(Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsxs(Box,{sx:{p:1,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[jsx(Typography,{variant:"subtitle2",sx:{px:1},children:"Group By"}),t.length>0&&jsx(Button,{size:"small",color:"error",onClick:()=>i([]),startIcon:jsx(Aa,{}),children:"Clear All"})]}),jsx(Divider,{}),s.map(l=>{let n=t.includes(l.id),u=t.indexOf(l.id)+1;return jsx(MenuItem,{onClick:()=>a(l.id),children:jsxs(Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsx(Checkbox,{checked:n,size:"small"}),jsx(ListItemText,{primary:l.label}),n&&jsx(Badge,{badgeContent:u,color:"primary",sx:{mr:2}})]})},l.id)})]}),Go=({anchorEl:e,setAnchorEl:o,columns:t,visibleColumns:i,toggleColumnVisibility:s})=>jsxs(Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"Visible Columns"})}),jsx(Divider,{}),t.map(a=>jsxs(MenuItem,{onClick:()=>s(a.id),children:[jsx(Checkbox,{checked:i.includes(a.id),size:"small"}),jsx(ListItemText,{primary:a.label})]},a.id))]}),Wo=({anchorEl:e,setAnchorEl:o,showSummary:t,setShowSummary:i,columns:s,summaryColumns:a,toggleSummaryColumn:l})=>jsxs(Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsx(MenuItem,{children:jsx(FormControlLabel,{control:jsx(Switch,{checked:t,onChange:n=>i(n.target.checked),size:"small"}),label:"Show Summary Row"})}),jsx(Divider,{}),s.filter(n=>n.numeric).map(n=>jsxs(MenuItem,{onClick:()=>l(n.id),disabled:!t,children:[jsx(Checkbox,{checked:a.includes(n.id),size:"small"}),jsx(ListItemText,{primary:n.label})]},n.id)),s.filter(n=>n.numeric).length===0&&jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"No numeric columns"})})]}),$o=({contextMenu:e,handleCloseContextMenu:o,columns:t,visibleColumns:i,toggleColumnVisibility:s})=>jsxs(Menu,{open:e!==null,onClose:o,anchorReference:"anchorPosition",anchorPosition:e!==null?{top:e.mouseY,left:e.mouseX}:void 0,children:[jsx(MenuItem,{onClick:o,children:"Copy"}),jsx(Divider,{}),jsx(MenuItem,{disabled:true,children:"Visible Columns"}),t.map(a=>jsxs(MenuItem,{onClick:()=>s(a.id),children:[jsx(ListItemIcon,{children:i.includes(a.id)&&jsx(La,{fontSize:"small"})}),jsx(ListItemText,{children:a.label})]},a.id))]});var _e=(e,o=2)=>e.toLocaleString(void 0,{maximumFractionDigits:o}),jo=({kpis:e})=>{let o=[{label:"Total Records",value:_e(e.totalRecords,0),color:"text.primary"},{label:"Total Report",value:_e(e.totalReportHours),color:"text.primary"},{label:"Total Billable",value:_e(e.totalBillableHours),color:"success.main"},{label:"Efficiency",value:`${e.efficiency.toFixed(2)}%`,color:"warning.main"},{label:"Amount",value:_e(e.totalAmount),color:"info.main"},{label:"Flagged",value:_e(e.flaggedCount,0),color:"error.main"}];return jsx(Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"repeat(2, minmax(0, 1fr))",lg:"repeat(6, minmax(0, 1fr))"},gap:1.5},children:o.map(t=>jsxs(Paper,{variant:"outlined",sx:{p:1.5,borderRadius:2,minHeight:96,display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[jsx(Typography,{variant:"caption",color:"text.secondary",children:t.label}),jsx(Typography,{variant:"h4",fontWeight:800,sx:{color:t.color},children:t.value})]},t.label))})};var ft=["#1E88E5","#1ABC9C","#FBC02D","#EF5350","#7E57C2","#78909C"],za=({data:e})=>{let o=Math.max(...e.map(t=>t.value),1);return jsx(Stack,{spacing:1,children:e.map(t=>jsxs(Box,{sx:{display:"grid",gridTemplateColumns:"140px 1fr 64px",gap:1},children:[jsx(Typography,{variant:"caption",color:"text.secondary",noWrap:true,title:t.name,children:t.name}),jsx(Box,{sx:{alignSelf:"center",bgcolor:"action.hover",height:10,borderRadius:999,overflow:"hidden"},children:jsx(Box,{sx:{width:`${t.value/o*100}%`,height:"100%",bgcolor:"primary.main"}})}),jsx(Typography,{variant:"caption",sx:{textAlign:"right",fontWeight:600},children:t.value.toFixed(1)})]},t.name))})},Oa=({data:e})=>{let o=Math.max(...e.map(t=>t.value),1);return jsx(Box,{sx:{display:"flex",gap:1,alignItems:"flex-end",minHeight:210},children:e.map(t=>jsxs(Box,{sx:{flex:1,minWidth:0},children:[jsx(Box,{sx:{height:`${Math.max(t.value/o*180,6)}px`,bgcolor:"primary.main",borderRadius:"8px 8px 0 0"}}),jsx(Typography,{variant:"caption",noWrap:true,title:t.name,sx:{display:"block",mt:.5},children:t.name}),jsxs(Typography,{variant:"caption",color:"text.secondary",children:[t.value.toFixed(1),"%"]})]},t.name))})},Ga=({data:e})=>{if(e.length===0)return jsx(Typography,{variant:"body2",color:"text.secondary",children:"No data"});let o=0,i=`conic-gradient(${e.map((s,a)=>{let l=o;return o+=s.percent,`${ft[a%ft.length]} ${l}% ${o}%`}).join(", ")})`;return jsxs(Stack,{direction:{xs:"column",sm:"row"},spacing:2,alignItems:"center",children:[jsx(Box,{sx:{width:180,height:180,borderRadius:"50%",background:i,position:"relative"},children:jsx(Box,{sx:{position:"absolute",inset:30,bgcolor:"background.paper",borderRadius:"50%"}})}),jsx(Stack,{spacing:1,sx:{minWidth:180},children:e.map((s,a)=>jsxs(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsx(Box,{sx:{width:10,height:10,borderRadius:"50%",bgcolor:ft[a%ft.length]}}),jsx(Typography,{variant:"caption",sx:{flex:1},children:s.name}),jsxs(Typography,{variant:"caption",sx:{fontWeight:700},children:[s.percent.toFixed(0),"%"]})]},s.name))})]})},eo=({title:e,subtitle:o,children:t})=>jsxs(Paper,{variant:"outlined",sx:{p:2,borderRadius:2},children:[jsx(Typography,{variant:"subtitle1",fontWeight:700,children:e}),jsx(Typography,{variant:"body2",color:"text.secondary",sx:{mb:2},children:o}),t]}),Uo=({billableByPrimary:e,efficiencyBySecondary:o,statusDistribution:t})=>jsxs(Box,{sx:{display:"grid",gap:1.5,gridTemplateColumns:{xs:"1fr",lg:"1.2fr 1.2fr 1fr"}},children:[jsx(eo,{title:"Billable by Dimension",subtitle:"Top values by billable hours",children:jsx(za,{data:e})}),jsx(eo,{title:"Efficiency by Person",subtitle:"Lowest efficiency first",children:jsx(Oa,{data:o})}),jsx(eo,{title:"Status Distribution",subtitle:"Record ratio by status",children:jsx(Ga,{data:t})})]});var Yo=({open:e,onClose:o,model:t,tableContent:i})=>jsx(Dialog,{open:e,onClose:o,fullScreen:true,children:jsxs(Box,{sx:{height:"100%",display:"flex",flexDirection:"column",bgcolor:"background.default"},children:[jsx(Box,{sx:{p:2,borderBottom:1,borderColor:"divider"},children:jsxs(Stack,{direction:"row",alignItems:"center",justifyContent:"space-between",spacing:2,children:[jsxs(Stack,{direction:"row",spacing:1.5,alignItems:"center",children:[jsx(Typography,{variant:"h5",fontWeight:800,children:t.title}),jsx(Chip,{size:"small",label:`${t.kpis.totalRecords} records`})]}),jsx(IconButton,{onClick:o,children:jsx(Ua,{})})]})}),jsxs(Box,{sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,overflow:"auto",minHeight:0},children:[jsx(jo,{kpis:t.kpis}),jsx(Uo,{billableByPrimary:t.charts.billableByPrimary,efficiencyBySecondary:t.charts.efficiencyBySecondary,statusDistribution:t.charts.statusDistribution}),i]})]})});var Se={primaryDimension:["Client","Customer","Category","Project"],secondaryDimension:["Person","Consultant","Owner","Name"],status:["Status","state"],date:["Date","WorkDate","CreatedAt"],description:["Description","Task","Title","Memo"],reportHours:["Report_Hour","Report Hours","Hours","ReportHours"],billableHours:["Billable_Hour","Billable Hours","BillableHours"],amount:["Amount","Billable_Amount","Total_Amount","Value"]},Ka=5,qo=e=>e.toLowerCase().replace(/[\s_-]/g,""),Te=(e,o,t,i)=>{if(o)return o;if(e.length===0)return i;let s=Object.keys(e[0]),a=new Map(s.map(l=>[qo(l),l]));for(let l of t){let n=a.get(qo(l));if(n)return n}return s[0]||i},ye=e=>{if(typeof e=="number")return Number.isFinite(e)?e:0;if(typeof e=="string"){let o=Number(e.replace(/,/g,"").trim());return Number.isFinite(o)?o:0}return 0},be=(e,o)=>e==null||e===""?o:String(e),Ya=(e,o,t,i)=>{let s=new Map;return e.forEach(a=>{let l=be(a[o],"Unassigned");s.set(l,(s.get(l)||0)+ye(a[t]));}),Array.from(s.entries()).map(([a,l])=>({name:a,value:l})).sort((a,l)=>l.value-a.value).slice(0,i)},qa=(e,o,t,i,s)=>{let a=new Map;return e.forEach(l=>{let n=be(l[o],"Unassigned"),u=a.get(n)||{report:0,billable:0};u.report+=ye(l[t]),u.billable+=ye(l[i]),a.set(n,u);}),Array.from(a.entries()).map(([l,n])=>({name:l,value:n.report>0?n.billable/n.report*100:0})).sort((l,n)=>l.value-n.value).slice(0,s)},Xa=(e,o)=>{let t=e.length;if(t===0)return [];let i=new Map;return e.forEach(s=>{let a=be(s[o],"Unassigned");i.set(a,(i.get(a)||0)+1);}),Array.from(i.entries()).map(([s,a])=>({name:s,value:a,percent:a/t*100}))},Xo=({rows:e,config:o})=>{let t=useMemo(()=>{let u=o?.fieldMapping;return {primaryDimension:Te(e,u?.primaryDimension,Se.primaryDimension,"Category"),secondaryDimension:Te(e,u?.secondaryDimension,Se.secondaryDimension,"Owner"),status:Te(e,u?.status,Se.status,"Status"),date:Te(e,u?.date,Se.date,"Date"),description:Te(e,u?.description,Se.description,"Description"),reportHours:Te(e,u?.reportHours,Se.reportHours,"ReportHours"),billableHours:Te(e,u?.billableHours,Se.billableHours,"BillableHours"),amount:Te(e,u?.amount,Se.amount,"Amount")}},[e,o?.fieldMapping]),i=useMemo(()=>e.map((u,v)=>{let w=ye(u[t.reportHours]),S=ye(u[t.billableHours]),x=ye(u[t.amount]),P=w>0?S/w*100:0;return {id:`graph-row-${v}`,Date:be(u[t.date],""),Primary:be(u[t.primaryDimension],"Unassigned"),Secondary:be(u[t.secondaryDimension],"Unassigned"),Description:be(u[t.description],""),ReportHours:w,BillableHours:S,Amount:x,Efficiency:P,Status:be(u[t.status],"Unassigned")}}),[e,t]),s=useMemo(()=>{let u=i.length,v=i.reduce((m,g)=>m+ye(g.ReportHours),0),w=i.reduce((m,g)=>m+ye(g.BillableHours),0),S=i.reduce((m,g)=>m+ye(g.Amount),0),x=v>0?w/v*100:0,P=o?.statusFlagValues||["flag","flagged","warning","risk"],k=i.filter(m=>P.includes(be(m.Status,"").toLowerCase())).length;return {totalRecords:u,totalReportHours:v,totalBillableHours:w,efficiency:x,totalAmount:S,flaggedCount:k}},[i,o?.statusFlagValues]),a=o?.topN||Ka,l=useMemo(()=>({billableByPrimary:Ya(i,"Primary","BillableHours",a),efficiencyBySecondary:qa(i,"Secondary","ReportHours","BillableHours",a),statusDistribution:Xa(i,"Status")}),[i,a]),n=useMemo(()=>({title:o?.title||"Graphic Report",kpis:s,charts:l,table:{columns:[{id:"Date",label:t.date},{id:"Primary",label:t.primaryDimension},{id:"Secondary",label:t.secondaryDimension},{id:"Description",label:t.description},{id:"ReportHours",label:"Report Hours",align:"right"},{id:"BillableHours",label:"Billable Hours",align:"right"},{id:"Amount",label:"Amount",align:"right"},{id:"Efficiency",label:"Efficiency",align:"right"},{id:"Status",label:t.status}],rows:i}}),[l,o?.title,t,s,i]);return {fieldMapping:t,model:n}};var bt=({variants:e,currentVariantId:o,onLoad:t,onSave:i,onDelete:s,onSetDefault:a})=>{let l="0.75rem",[n,u]=useState(false),[v,w]=useState(""),[S,x]=useState(false),[P,k]=useState(false),m=e.find(d=>d.id===o);return jsxs(Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsx(Typography,{variant:"body2",sx:{fontWeight:"bold",minWidth:"fit-content",fontSize:l},children:"Variant:"}),jsx(Autocomplete,{size:"small",sx:{width:200,"& .MuiInputBase-root":{fontSize:l},"& .MuiInputBase-input":{fontSize:l},"& .MuiAutocomplete-noOptions":{fontSize:l}},noOptionsText:jsx(Typography,{sx:{fontSize:l},children:"No options"}),options:e,getOptionLabel:d=>d.name+(d.isDefault?" (Default)":""),value:m||null,onChange:(d,I)=>{I&&t(I);},renderInput:d=>jsx(TextField,{...d,variant:"outlined",size:"small",InputProps:{...d.InputProps,sx:{fontSize:l}},placeholder:"Select Variant"}),renderOption:(d,I)=>jsx("li",{...d,children:jsxs(Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsx(Typography,{sx:{flex:1,fontSize:l},children:I.name}),I.isDefault&&jsx(rr,{fontSize:"small",color:"action"})]})})}),jsx(Tooltip,{title:"Save View",children:jsx(IconButton,{onClick:()=>{w(m?.name||"New Variant"),x(m?.isDefault||false),k(m?.isPublic||false),u(true);},size:"small",color:"primary",children:jsx(yn,{})})}),jsxs(Dialog,{open:n,onClose:()=>u(false),children:[jsx(DialogTitle,{children:"Save View"}),jsxs(DialogContent,{children:[jsx(TextField,{autoFocus:true,margin:"dense",label:"View Name",fullWidth:true,variant:"outlined",value:v,onChange:d=>w(d.target.value)}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:S,onChange:d=>x(d.target.checked)}),label:"Set as Default"}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:P,onChange:d=>k(d.target.checked)}),label:"Public (All Users)"})]}),jsxs(DialogActions,{children:[jsx(Button,{onClick:()=>u(false),children:"Cancel"}),jsx(Button,{onClick:()=>{i({name:v,isDefault:S,isPublic:P,description:""}),u(false);},variant:"contained",children:"Save"})]})]})]})};var sr="http://127.0.0.1:8515",nn=({appId:e,tableKey:o="default",currentFilters:t,currentLayoutId:i,layoutRefs:s,onLoad:a,serviceUrl:l=sr,onError:n,onSuccess:u,currentVariantId:v,onVariantChange:w})=>{let[S,x]=useState([]),[P,k]=useState(""),m=v!==void 0?v:P,g=c=>{v===void 0&&k(c),w&&w(c);},y=useCallback(async()=>{if(!e)return [];try{let c=await fetch(`${l}/api/variants?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!c.ok)throw new Error("Failed to fetch variants");let C=await c.json();x(C);let M=C.find(T=>T.isDefault);return M&&!m&&(g(M.id),a(M)),C}catch(c){return console.error("Error fetching variants",c),n&&n("Failed to load variants"),[]}},[e,o,l,n,m,a]);return useEffect(()=>{y();},[e,o]),jsx(bt,{variants:S,currentVariantId:m,onLoad:c=>{g(c.id),a(c);},onSave:async c=>{try{let C=S.find(A=>A.name===c.name),M=C?C.id:Date.now().toString(),T=[];if(C&&(Array.isArray(C.filters)?T=[...C.filters]:C.filters&&(T=[{scope:"default",filters:C.filters}])),c.scope==="Search"||c.scope==="Both"){let A=(Array.isArray(t),t);if(A)if(Array.isArray(A)&&A.length>0&&A[0].scope)A.forEach(V=>{let B=T.findIndex(H=>H.scope===V.scope);B>=0?T[B]=V:T.push(V);});else {let V={scope:o,filters:A},B=T.findIndex(H=>H.scope===o);B>=0?T[B]=V:T.push(V);}}let p=C?.layout||{},D=[];if(C&&Array.isArray(C.layoutRefs)&&(D=[...C.layoutRefs]),c.scope==="Layout"||c.scope==="Both")if(s&&s.length>0)s.forEach(A=>{let V=D.findIndex(B=>B.tableKey===A.tableKey);V>=0?D[V]=A:D.push(A);});else {let A={tableKey:o,layoutId:i||null},V=D.findIndex(B=>B.tableKey===o);V>=0?D[V]=A:D.push(A);}let f={appId:e,tableKey:o,...c,id:M,createdAt:new Date().toISOString(),filters:T,layout:p,layoutRefs:D};if(!(await fetch(`${l}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(f)})).ok)throw new Error("Failed to save variant");u&&u("Variant saved successfully"),await y(),g(M),a(f);}catch(C){console.error("Error saving variant",C),n&&n("Failed to save variant");}},onDelete:async c=>{try{if(!(await fetch(`${l}/api/variants/${c}`,{method:"DELETE"})).ok)throw new Error("Failed to delete variant");m===c&&g(""),y(),u&&u("Variant deleted successfully");}catch(C){console.error("Error deleting variant",C),n&&n("Failed to delete variant");}},onSetDefault:async c=>{try{let C=S.find(p=>p.id===c);if(!C)return;let M={appId:e,tableKey:o,...C,isDefault:!0};if(!(await fetch(`${l}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(M)})).ok)throw new Error("Failed to set default variant");await y(),u&&u("Default variant updated");}catch(C){console.error("Error setting default variant",C),n&&n("Failed to update default variant");}}})};De.extend(Tr);var wr=[null,null],io="0.75rem",Ir=styled(PickersDay,{shouldForwardProp:e=>e!=="isInRange"&&e!=="isStart"&&e!=="isEnd"&&e!=="isHovered"})(({theme:e,isInRange:o,isStart:t,isEnd:i,isHovered:s})=>({...o&&{borderRadius:0,backgroundColor:e.palette.primary.light,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.main}},...s&&!o&&!t&&!i&&{borderRadius:0,backgroundColor:e.palette.action.hover,border:`1px dashed ${e.palette.primary.main}`},...t&&{borderRadius:"50% 0 0 50%",backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.dark}},...i&&{borderRadius:"0 50% 50% 0",backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.dark}},...t&&i&&{borderRadius:"50%"}})),ln=({label:e="Date Range",value:o=wr,onChange:t})=>{let[i,s]=useState(null),[a,l]=useState(o),[n,u]=useState("start"),[v,w]=useState(null),[S,x]=useState(o[0]||De()),P=bo__default.useRef(o);useEffect(()=>{let[M,T]=o,[p,D]=P.current,f=V=>V&&typeof V.isSame=="function",W=!(M===null&&p===null||f(M)&&f(p)&&M.isSame(p,"day")),A=!(T===null&&D===null||f(T)&&f(D)&&T.isSame(D,"day"));(W||A)&&(l(o),o[0]&&f(o[0])&&x(o[0])),P.current=o;},[o]);let k=M=>{s(M.currentTarget);},m=()=>{s(null),u("start"),w(null);},g=!!i,y=M=>{if(!M)return;let T=[...a];if(n==="start")T=[M,null],u("end");else {let p=T[0];p&&M.isBefore(p)?(T=[M,null],u("end")):(T=[p,M],u("start"));}l(T);},d=M=>{let T=De(),p=[null,null];switch(M){case "today":p=[T,T];break;case "week":p=[T.startOf("week"),T.endOf("week")];break;case "month":p=[T.startOf("month"),T.endOf("month")];break}l(p),u("start"),x(T);},I=()=>{l([null,null]),u("start"),x(De());},r=()=>{t&&t(a),m();},b=()=>{l(o),u("start"),m();},c=useCallback(M=>{let{day:T,...p}=M,[D,f]=a,W=D?T.isSame(D,"day"):false,A=f?T.isSame(f,"day"):false,V=D&&f?T.isBetween(D,f,"day","()"):false,B=false;return n==="end"&&D&&!f&&v&&T.isAfter(D,"day")&&T.isBefore(v.add(1,"day"),"day")&&(B=true),jsx(Ir,{...p,day:T,disableMargin:true,isStart:W,isEnd:A,isInRange:V||B,onMouseEnter:()=>w(T)})},[a,n,v]),C=M=>M?M.format("YYYY-MM-DD"):"";return jsxs(Box,{children:[jsx(TextField,{label:e,value:a[0]?`${C(a[0])} - ${C(a[1])}`:"",onClick:k,fullWidth:true,size:"small",InputLabelProps:{sx:{fontSize:io}},InputProps:{readOnly:true,sx:{fontSize:io,"& .MuiOutlinedInput-input":{fontSize:io},paddingRight:"4px"},endAdornment:jsxs(InputAdornment,{position:"end",sx:{ml:0},children:[(a[0]||a[1])&&jsx(IconButton,{size:"small",onClick:M=>{M.stopPropagation(),I();},edge:"end",sx:{mr:.5,padding:"2px"},children:jsx(vr,{sx:{fontSize:"1rem"}})}),jsx(IconButton,{size:"small",edge:"end",onClick:k,sx:{padding:"2px"},children:jsx(Cr,{sx:{fontSize:"1rem"},color:"action"})})]})}}),jsxs(Popover,{open:g,anchorEl:i,onClose:m,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},slotProps:{paper:{sx:{display:"flex",flexDirection:"column",p:0,minWidth:320}}},children:[jsx(Box,{sx:{p:2,bgcolor:"background.default",borderBottom:1,borderColor:"divider"},children:jsxs(Stack,{direction:"row",alignItems:"center",spacing:2,justifyContent:"space-between",children:[jsxs(Box,{sx:{p:1,border:1,borderColor:n==="start"?"primary.main":"divider",borderRadius:1,bgcolor:n==="start"?"action.hover":"transparent",flex:1,cursor:"pointer"},onClick:()=>u("start"),children:[jsx(Typography,{variant:"caption",color:"text.secondary",display:"block",children:"Start Date"}),jsx(Typography,{variant:"body2",fontWeight:500,children:a[0]?a[0].format("MMM DD, YYYY"):"Select..."})]}),jsx(Sr,{color:"action",fontSize:"small"}),jsxs(Box,{sx:{p:1,border:1,borderColor:n==="end"?"primary.main":"divider",borderRadius:1,bgcolor:n==="end"?"action.hover":"transparent",flex:1,cursor:"pointer"},onClick:()=>{a[0]&&u("end");},children:[jsx(Typography,{variant:"caption",color:"text.secondary",display:"block",children:"End Date"}),jsx(Typography,{variant:"body2",fontWeight:500,children:a[1]?a[1].format("MMM DD, YYYY"):"Select..."})]})]})}),jsx(Box,{sx:{p:2,pb:0},children:jsxs(Stack,{direction:"row",spacing:1,justifyContent:"center",children:[jsx(Chip,{label:"Today",onClick:()=>d("today"),clickable:true,size:"small",variant:"outlined"}),jsx(Chip,{label:"This Week",onClick:()=>d("week"),clickable:true,size:"small",variant:"outlined"}),jsx(Chip,{label:"This Month",onClick:()=>d("month"),clickable:true,size:"small",variant:"outlined"})]})}),jsx(DateCalendar,{value:null,referenceDate:S,onMonthChange:x,onYearChange:x,onChange:y,slots:{day:c},views:["day"],showDaysOutsideCurrentMonth:true,sx:{m:0}}),jsx(Divider,{}),jsxs(Stack,{direction:"row",justifyContent:"flex-end",spacing:1,sx:{p:2},children:[jsx(Button,{size:"small",onClick:b,color:"inherit",children:"Cancel"}),jsx(Button,{size:"small",variant:"contained",onClick:r,children:"Done"})]})]})]})};var St={equals:"=",contains:"\u2287",notContains:"\u2285",wildcard:"*","=":"=","!=":"!=",">":">","<":"<",">=":"\u2265","<=":"\u2264",between:"\u2194"},Vr={equals:"Equals",contains:"Contains",notContains:"Does Not Contain",wildcard:"Wildcard Search","=":"Equals","!=":"Not Equals",">":"Greater Than","<":"Less Than",">=":"Greater Than or Equal","<=":"Less Than or Equal",between:"Between"},Nr=["equals","contains","notContains","wildcard"],dn=["=","!=",">","<",">=","<=","between"],Z="0.75rem",Hr=({field:e,value:o,onChange:t})=>{let[i,s]=useState(null),[a,l]=useState(null),[n,u]=useState(""),[v,w]=useState(""),[S,x]=useState(false),[P,k]=useState(""),[m,g]=useState("");useEffect(()=>{let p=setTimeout(()=>{g(P);},1e3);return ()=>clearTimeout(p)},[P]);let y=o?.operator||(e.type==="number"?"=":"equals"),d=o?.value,I=p=>Vr[p]||p,r=p=>{s(p.currentTarget);},b=p=>{t({...o,operator:p,value:d}),s(null);},c={size:"small",fullWidth:true,variant:"outlined",InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}},SelectProps:{MenuProps:{PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,paddingTop:"4px",paddingBottom:"4px",minHeight:"auto"}}}}}},C=e.type||"text";if(C==="date"){let D=(f=>{if(!f)return [null,null];if(Array.isArray(f)&&f.length===2){let W=f[0]?De.isDayjs(f[0])?f[0]:De(f[0]):null,A=f[1]?De.isDayjs(f[1])?f[1]:De(f[1]):null;return [W,A]}return De.isDayjs(f)||typeof f=="string"?[De.isDayjs(f)?f:De(f),null]:[null,null]})(d);return jsx(ln,{label:e.label,value:D,onChange:f=>t({value:f,operator:"between"})})}if(C==="number"&&y==="between"){let p=()=>{t({value:[n,v],operator:"between"}),l(null);},D=Array.isArray(d)?`${d[0]||""} - ${d[1]||""}`:"";return jsxs(Fragment,{children:[jsx(TextField,{...c,label:e.label,value:D,placeholder:"Min - Max",InputProps:{...c.InputProps,startAdornment:jsx(InputAdornment,{position:"start",children:jsx(Tooltip,{title:I("between"),children:jsx(IconButton,{size:"small",onClick:r,sx:{width:24,height:24,fontSize:Z},children:St.between})})}),readOnly:true},onClick:f=>l(f.currentTarget)}),jsx(Menu,{anchorEl:i,open:!!i,onClose:()=>s(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,minHeight:"auto",py:.5}}},children:dn.map(f=>jsxs(MenuItem,{selected:f===y,onClick:()=>b(f),children:[jsx(Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:St[f]}),jsx(ListItemText,{primary:I(f),primaryTypographyProps:{fontSize:Z}})]},f))}),jsx(Popover,{open:!!a,anchorEl:a,onClose:()=>l(null),anchorOrigin:{vertical:"bottom",horizontal:"left"},children:jsxs(Box,{sx:{p:2,display:"flex",gap:1,alignItems:"center"},children:[jsx(TextField,{size:"small",label:"Min",type:"number",value:n,onChange:f=>u(f.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}}}),jsx(Fr,{color:"action"}),jsx(TextField,{size:"small",label:"Max",type:"number",value:v,onChange:f=>w(f.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}}}),jsx(Button,{variant:"contained",size:"small",onClick:p,children:"OK"})]})})]})}if(C==="select")return jsxs(TextField,{...c,select:true,label:e.label,value:d||"",onChange:p=>t({...o,value:p.target.value,operator:"equals"}),children:[jsx(MenuItem,{value:"",children:jsx("em",{children:"None"})}),e.options?.map(p=>jsx(MenuItem,{value:p.value,children:p.label},p.value))]});if(C==="multi-select"){let p=Array.isArray(d)?d:[],D=e.options?.filter(f=>f.label.toLowerCase().includes(m.toLowerCase()))||[];return jsxs(TextField,{...c,select:true,label:e.label,value:p,onChange:f=>t({...o,value:f.target.value,operator:"anyOf"}),SelectProps:{...c.SelectProps,multiple:true,onClose:()=>{k(""),g("");},renderValue:f=>{if(!Array.isArray(f)||f.length===0)return jsx("em",{children:"None"});let W=V=>e.options?.find(B=>B.value===V)?.label||V,A=f.map(W);return A.length>2?`${A.slice(0,2).join(", ")} +${A.length-2}`:A.join(", ")}},children:[jsx(ListSubheader,{children:jsx(TextField,{size:"small",autoFocus:true,placeholder:"Search...",fullWidth:true,InputProps:{startAdornment:jsx(InputAdornment,{position:"start",children:jsx(cn,{fontSize:"small"})}),sx:{fontSize:Z}},value:P,onChange:f=>k(f.target.value),onKeyDown:f=>{f.key!=="Escape"&&f.stopPropagation();},onClick:f=>f.stopPropagation()})}),D.length>0?D.map(f=>jsxs(MenuItem,{value:f.value,children:[jsx(Checkbox,{checked:p.indexOf(f.value)>-1,size:"small"}),jsx(ListItemText,{primary:f.label,primaryTypographyProps:{fontSize:Z}})]},f.value)):jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"No options found",primaryTypographyProps:{fontSize:Z}})})]})}let M=C==="number"?dn:Nr,T=S||d!==void 0&&d!==""&&d!==null||!!i;return jsxs(Fragment,{children:[jsx(TextField,{...c,label:e.label,sx:{minWidth:"120px"},value:d||"",type:C==="number"?"number":"text",onChange:p=>t({...o,value:p.target.value,operator:y}),onFocus:()=>x(true),onBlur:()=>x(false),InputProps:{...c.InputProps,startAdornment:T?jsx(InputAdornment,{position:"start",children:jsx(Tooltip,{title:I(y),children:jsx(IconButton,{size:"small",onClick:r,onMouseDown:p=>p.preventDefault(),sx:{width:24,height:24,fontSize:Z,fontWeight:"bold",color:"primary.main",bgcolor:"action.hover"},children:St[y]})})}):null,endAdornment:e.hasSearchIcon?jsx(InputAdornment,{position:"end",children:jsx(cn,{color:"action"})}):void 0}}),jsx(Menu,{anchorEl:i,open:!!i,onClose:()=>s(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,minHeight:"auto",py:.5}}},children:M.map(p=>jsxs(MenuItem,{selected:p===y,onClick:()=>b(p),children:[jsx(Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:St[p]}),jsx(ListItemText,{primary:I(p),primaryTypographyProps:{fontSize:Z}})]},p))})]})},qe=({fields:e,filters:o,onFilterChange:t,variants:i=[],currentVariantId:s,onVariantLoad:a,onVariantSave:l,onVariantDelete:n,onVariantSetDefault:u,onSearch:v,loading:w=false,appId:S,tableKey:x,currentLayout:P,currentLayoutId:k,layoutRefs:m,variantService:g})=>{let[y,d]=useState(true),[I,r]=useState(null),[b,c]=useState(e.filter(p=>!p.hidden).map(p=>p.id)),C=(p,D)=>{t({...o,[p]:D});},M=p=>{b.includes(p)?c(b.filter(D=>D!==p)):c([...b,p]);};return jsxs(Paper,{sx:{mb:0,display:"flex",flexDirection:"column",overflow:"visible",position:"relative"},children:[jsxs(Box,{sx:{p:2,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[S?jsx(nn,{appId:S,tableKey:x,currentFilters:{values:o,visibleFields:b},currentLayout:P,currentLayoutId:k,layoutRefs:m,onLoad:p=>{if(!p.filters)return;let D=null;if(Array.isArray(p.filters)){let f=x||"default",W=p.filters.find(A=>A.scope===f);D=W?W.filters:null;}else D=p.filters;D&&(D.values||D.visibleFields?(D.visibleFields&&Array.isArray(D.visibleFields)&&c(D.visibleFields),D.values&&t(D.values)):t(D)),a&&a(p);},variantService:g,currentVariantId:s}):jsx(bt,{variants:i,currentVariantId:s,onLoad:a,onSave:p=>{l&&l({...p,filters:{values:o,visibleFields:b}});},onDelete:n,onSetDefault:u}),jsxs(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsx(Tooltip,{title:"Add Filters",children:jsx(Button,{onClick:p=>r(p.currentTarget),size:"small",color:"primary",startIcon:jsx(Br,{fontSize:"small"}),sx:{textTransform:"none",fontSize:Z},children:"Adapt Filters"})}),jsx(Button,{variant:"contained",size:"small",onClick:v,disabled:w,sx:{minWidth:"40px",fontWeight:"bold"},children:w?"...":"Go"}),jsxs(Menu,{anchorEl:I,open:!!I,onClose:()=>r(null),slotProps:{paper:{style:{maxHeight:400,width:"25ch"}}},children:[jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"Visible Filters"})}),jsx(Divider,{}),e.map(p=>jsxs(MenuItem,{onClick:()=>M(p.id),children:[jsx(Checkbox,{checked:b.includes(p.id),size:"small"}),jsx(ListItemText,{primary:p.label})]},p.id))]})]})]}),jsx(Collapse,{in:y,children:jsx(Box,{sx:{px:2,pb:2},children:jsx(Grid,{container:true,spacing:2,columns:{xs:2,sm:3,md:4,lg:6},children:e.filter(p=>b.includes(p.id)).map(p=>jsx(Grid,{size:1,children:jsx(Hr,{field:p,value:o[p.id]||{value:"",operator:p.type==="number"?"=":"equals"},onChange:D=>C(p.id,D)})},p.id))})})}),jsx(Box,{sx:{position:"absolute",bottom:0,left:"50%",transform:"translate(-50%, 50%)",zIndex:10},children:jsx(IconButton,{size:"small",onClick:()=>d(!y),sx:{bgcolor:"background.paper",boxShadow:2,border:"1px solid",borderColor:"divider",width:20,height:20,minHeight:0,p:0,"&:hover":{bgcolor:"background.paper"}},children:y?jsx(Lr,{sx:{fontSize:16},color:"action"}):jsx(va,{sx:{fontSize:16},color:"action"})})})]})};var bn=({layouts:e,currentLayoutId:o,onLoad:t,onSave:i,onDelete:s,onSetDefault:a})=>{let[l,n]=useState(null),[u,v]=useState(false),[w,S]=useState(""),[x,P]=useState(""),[k,m]=useState({isDefault:false,isPublic:false}),g=e.find(c=>c.id===o),y=c=>{n(c.currentTarget);},d=()=>{n(null);},I=c=>{t(c),d();},r=()=>{S(""),P(""),m({isDefault:false,isPublic:false}),v(true),d();},b=()=>{w.trim()&&(i({name:w,description:x,...k}),v(false));};return jsxs(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsx(Tooltip,{title:"Save Layout",children:jsx(IconButton,{onClick:r,color:"primary",size:"small",children:jsx(yn,{})})}),jsx(Tooltip,{title:"Layout Options",children:jsx(IconButton,{onClick:y,color:g?"primary":"default",children:jsx(Xr,{})})}),jsxs(Menu,{anchorEl:l,open:!!l,onClose:d,PaperProps:{sx:{width:320,maxHeight:400}},children:[jsx(MenuItem,{disabled:true,children:jsx(Typography,{variant:"caption",children:"Select Layout"})}),jsxs(MenuItem,{onClick:r,children:[jsx(ListItemIcon,{children:jsx(yn,{fontSize:"small"})}),jsx(ListItemText,{children:"Save Current Layout..."})]}),jsx(Divider,{}),e.length===0&&jsx(MenuItem,{disabled:true,children:jsx(Typography,{variant:"body2",color:"text.secondary",children:"No saved layouts"})}),e.map((c,C)=>jsx(MenuItem,{onClick:()=>I(c),selected:c.id===o,children:jsxs(Box,{sx:{display:"flex",alignItems:"center",width:"100%",justifyContent:"space-between"},children:[jsxs(Box,{sx:{display:"flex",flexDirection:"column",overflow:"hidden",mr:1},children:[jsx(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:jsx(Typography,{variant:"body2",fontWeight:c.id===o?"bold":"normal",noWrap:true,children:c.name})}),c.description&&jsx(Typography,{variant:"caption",color:"text.secondary",noWrap:true,children:c.description})]}),jsxs(Box,{sx:{display:"flex",alignItems:"center"},onClick:M=>M.stopPropagation(),children:[jsx(Tooltip,{title:c.isDefault?"Remove Default":"Set as Default",children:jsx(IconButton,{size:"small",onClick:M=>{M.stopPropagation(),a(c.id);},children:c.isDefault?jsx(rr,{fontSize:"small",color:"warning"}):jsx(qr,{fontSize:"small"})})}),jsx(Tooltip,{title:"Delete",children:jsx(IconButton,{size:"small",color:"error",onClick:M=>{M.stopPropagation(),s(c.id);},children:jsx(Kr,{fontSize:"small"})})})]})]})},c.id||C))]}),jsxs(Dialog,{open:u,onClose:()=>v(false),maxWidth:"xs",fullWidth:true,children:[jsx(DialogTitle,{children:"Save Layout"}),jsx(DialogContent,{children:jsxs(Box,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[jsx(TextField,{label:"Layout Name",value:w,onChange:c=>S(c.target.value),fullWidth:true,autoFocus:true,size:"small",helperText:"e.g., 'Compact View'"}),e.some(c=>c.name===w)&&jsx(Typography,{variant:"caption",color:"warning.main",sx:{ml:1},children:"Warning: Existing layout will be overwritten"}),jsx(TextField,{label:"Description",value:x,onChange:c=>P(c.target.value),fullWidth:true,size:"small"}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:k.isDefault,onChange:c=>m({...k,isDefault:c.target.checked})}),label:"Use as Default Layout"}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:k.isPublic,onChange:c=>m({...k,isPublic:c.target.checked})}),label:"Public (Visible to all users)"})]})}),jsxs(DialogActions,{children:[jsx(Button,{onClick:()=>v(false),children:"Cancel"}),jsx(Button,{onClick:b,variant:"contained",disabled:!w,children:"Save"})]})]})]})};var Zr="http://127.0.0.1:8515",Cn=({appId:e,tableKey:o="default",currentLayoutData:t,onLayoutLoad:i,targetLayoutId:s,activeLayoutId:a,serviceUrl:l=Zr,onError:n,onSuccess:u})=>{let[v,w]=useState([]),[S,x]=useState(""),P=r=>({id:r.layoutId,name:r.name,description:r.description??"",isDefault:!!r.isDefault,isPublic:!!r.isPublic,createdAt:r.createdAt??new Date().toISOString(),layoutData:r.layout??{}}),k=r=>({appId:e,tableKey:o,layoutId:r.id,name:r.name,description:r.description??"",isDefault:!!r.isDefault,isPublic:!!r.isPublic,createdAt:r.createdAt,layout:r.layoutData});useEffect(()=>{a!==void 0&&x(a);},[a]),useEffect(()=>{if(s&&v.length>0){let r=v.find(b=>b.id===s);r&&(x(r.id),i(r));}},[s,v,i]);let m=useCallback(async()=>{if(e)try{let r=await fetch(`${l}/api/layouts?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!r.ok)throw new Error("Failed to fetch layouts");let c=(await r.json()).map(P);w(c);let C=c.find(M=>M.isDefault);C&&!S&&!s&&(x(C.id),i(C));}catch(r){console.error("Error fetching layouts",r),n&&n("Failed to load layouts");}},[e,o,l,n,S,i,s]);return useEffect(()=>{m();},[e,o]),jsx(bn,{layouts:v,currentLayoutId:S,onLoad:r=>{x(r.id),i(r);},onSave:async r=>{try{let b=v.find(T=>T.name===r.name),c=b?b.id:Date.now().toString(),C={id:c,...r,createdAt:new Date().toISOString(),layoutData:t,isDefault:r.isDefault??!1,isPublic:r.isPublic??!1};if(!(await fetch(`${l}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k(C))})).ok)throw new Error("Failed to save layout");u&&u("Layout saved successfully"),await m(),x(c),i(C);}catch(b){console.error("Error saving layout",b),n&&n("Failed to save layout");}},onDelete:async r=>{try{if(!(await fetch(`${l}/api/layouts/${encodeURIComponent(r)}`,{method:"DELETE"})).ok)throw new Error("Failed to delete layout");S===r&&x(""),u&&u("Layout deleted successfully"),await m();}catch(b){console.error("Error deleting layout",b),n&&n("Failed to delete layout");}},onSetDefault:async r=>{try{let b=v.find(C=>C.id===r);if(!b)return;if(!(await fetch(`${l}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k({...b,isDefault:!0}))})).ok)throw new Error("Failed to set default layout");u&&u("Default layout set"),await m();}catch(b){console.error("Error setting default",b),n&&n("Failed to set default layout");}}})};function Sn(e,o,t){return o[t]<e[t]?-1:o[t]>e[t]?1:0}function ei(e,o){return e==="desc"?(t,i)=>Sn(t,i,o):(t,i)=>-Sn(t,i,o)}function ti(e,o){let t=e.map((i,s)=>[i,s]);return t.sort((i,s)=>{let a=o(i[0],s[0]);return a!==0?a:i[1]-s[1]}),t.map(i=>i[0])}var Tn=e=>{let o=useCallback(h=>{let L=String(h?.label??h?.id??"").length*9+64,ee=typeof h?.minWidth=="number"?h.minWidth:0;return Math.max(100,ee,L)},[]),[t,i]=useState(""),[s,a]=useState(e.order||"asc"),[l,n]=useState(e.orderBy||""),[u,v]=useState(e.page||0),[w,S]=useState(e.rowsPerPage||20),[x,P]=useState(e.selected||[]),[k,m]=useState(e.columns?e.columns.map(h=>h.id):[]),[g,y]=useState(e.showSummary||false),[d,I]=useState([]),[r,b]=useState(new Set),[c,C]=useState(()=>{let h={};return (e.columns||[]).forEach(E=>{h[E.id]=o(E);}),h}),[M,T]=useState(null),[p,D]=useState(null),[f,W]=useState(null),[A,V]=useState(null),[B,H]=useState(false);useEffect(()=>{e.order!==void 0&&a(e.order),e.orderBy!==void 0&&n(e.orderBy);},[e.order,e.orderBy]),useEffect(()=>{e.selected!==void 0&&P(e.selected);},[e.selected]),useEffect(()=>{e.page!==void 0&&v(e.page);},[e.page]),useEffect(()=>{C(h=>{let E={...h};return (e.columns||[]).forEach(L=>{E[L.id]===void 0&&(E[L.id]=o(L));}),E});},[e.columns,o]);let z=useMemo(()=>{let h=e.rows||[];return t&&(h=h.filter(E=>Object.keys(E).some(L=>String(E[L]).toLowerCase().includes(t.toLowerCase())))),h},[e.rows,t]),ke=useMemo(()=>e.onSortChange||!l?z:ti(z,ei(s,l)),[z,s,l,e.onSortChange]),Me=useCallback(h=>{if(d.length===0)return h.map(Y=>({type:"row",data:Y,id:Y[e.rowKey||"id"]}));let E=[...h].sort((Y,J)=>{for(let U of d){if(Y[U]<J[U])return -1;if(Y[U]>J[U])return 1}return 0}),L=(Y,J=0)=>{if(J>=d.length)return Y;let U=d[J],$={},le=[];return Y.forEach(se=>{let Ee=se[U],pe=`${U}:${Ee}`;$[pe]||($[pe]={key:pe,field:U,value:Ee,children:[],count:0,level:J},le.push($[pe])),$[pe].children.push(se),$[pe].count++;}),le.forEach(se=>{se.children&&(se.children=L(se.children,J+1));}),le},ee=L(E),O=(Y,J="")=>{let U=[];return Y.forEach($=>{if($.children){let le=J?`${J}>${$.key}`:$.key,se=r.has(le);U.push({type:"group",id:le,field:$.field,value:$.value,level:$.level,count:$.count,isExpanded:se,childIds:(function Ee(pe){let Be=[];return pe.children.forEach(Le=>{Le.children?Be=Be.concat(Ee(Le)):Be.push(Le[e.rowKey||"id"]);}),Be})($)}),se&&(U=U.concat(O($.children,le)));}else U.push({type:"row",data:$,id:$[e.rowKey||"id"],level:d.length});}),U};return O(ee)},[d,r,e.rowKey]),ie=useMemo(()=>Me(ke),[ke,Me]),oe=useMemo(()=>w>0?ie.slice(u*w,u*w+w):ie,[ie,u,w]),Oe=h=>{let E=new Set(r);E.has(h)?E.delete(h):E.add(h),b(E);},Et=h=>{Oe(h);},Ge=h=>{let E=new Set(r);Array.from(E).forEach(L=>{L.startsWith(h)&&E.delete(L);}),b(E);},Bt=h=>{h||b(new Set);},Lt=h=>{let E=l===h&&s==="asc",L=l===h&&s==="desc";if(e.onSortChange){E?e.onSortChange(h,"desc"):L?e.onSortChange("","asc"):e.onSortChange(h,"asc");return}E?(a("desc"),n(h)):L?(a("asc"),n("")):(a("asc"),n(h));},We=(h,E)=>{C(L=>({...L,[h]:E}));},nt=h=>{if(h.target.checked){let E=z.map(L=>L[e.rowKey||"id"]);P(E),e.onSelectionChange&&e.onSelectionChange(E);return}P([]),e.onSelectionChange&&e.onSelectionChange([]);},At=(h,E)=>{let L=E[e.rowKey||"id"],ee=x.indexOf(L),O=[];ee===-1?O=O.concat(x,L):ee===0?O=O.concat(x.slice(1)):ee===x.length-1?O=O.concat(x.slice(0,-1)):ee>0&&(O=O.concat(x.slice(0,ee),x.slice(ee+1))),P(O),e.onSelectionChange&&e.onSelectionChange(O);},at=h=>{v(h),e.onPageChange&&e.onPageChange(h);},rt=h=>{S(h),v(0),e.onRowsPerPageChange&&e.onRowsPerPageChange(h);},Ft=h=>{let E=k.indexOf(h),L=[...k];E===-1?L.push(h):L.splice(E,1),m(L);},Vt=h=>{let E=d.indexOf(h),L=[...d];E===-1?L.push(h):L.splice(E,1),I(L);},it=h=>{e.onLayoutSave&&e.onLayoutSave({visibleColumns:k,order:s,orderBy:l,grouping:d,columnWidths:c});},lt=h=>{h.layout&&(h.layout.visibleColumns&&m(h.layout.visibleColumns),h.layout.order&&a(h.layout.order),h.layout.orderBy&&n(h.layout.orderBy),h.layout.grouping&&I(h.layout.grouping),h.layout.columnWidths&&C(h.layout.columnWidths));};useEffect(()=>{e.layout&&lt({layout:e.layout});},[e.layout]);let Nt=h=>{h.preventDefault(),V(A===null?{mouseX:h.clientX+2,mouseY:h.clientY-6}:null);},Ht=()=>{V(null);},zt=useMemo(()=>{if(!g)return {};let h={};e.columns.forEach(L=>{if(L.numeric){let ee=z.reduce((O,Y)=>{let J=parseFloat(Y[L.id]);return O+(isNaN(J)?0:J)},0);h[L.id]=ee.toFixed(2);}else h[L.id]="";});let E=e.columns.find(L=>k.includes(L.id));return E&&!E.numeric&&(h[E.id]="Total"),h},[z,e.columns,g,k]),Ot=()=>{if(!e.columns||!z)return;let h=e.columns.map(Y=>Y.label).join(","),E=z.map(Y=>e.columns.map(J=>{let U=Y[J.id];return `"${(U==null?"":String(U)).replace(/"/g,'""')}"`}).join(",")).join(`
2
- `),L=`data:text/csv;charset=utf-8,${h}
3
- ${E}`,ee=encodeURI(L),O=document.createElement("a");O.setAttribute("href",ee),O.setAttribute("download",`${e.title||"export"}.csv`),document.body.appendChild(O),O.click(),document.body.removeChild(O);},st=()=>{H(true);},Gt=()=>{H(false);};return {isMobile:false,columns:e.columns,order:s,orderBy:l,filterText:t,setFilterText:i,visibleColumns:k,setVisibleColumns:m,showSummary:g,setShowSummary:y,summaryColumns:[],grouping:d,setGrouping:I,expandedGroups:r,setExpandedGroups:b,groupAnchorEl:p,setGroupAnchorEl:D,summaryAnchorEl:f,setSummaryAnchorEl:W,columnWidths:c,setColumnWidths:C,anchorEl:M,setAnchorEl:T,contextMenu:A,setContextMenu:V,sensors:void 0,sortedAndFilteredRows:ke,visibleRows:oe,summaryRow:zt,page:u,setPage:at,rowsPerPage:w,setRowsPerPage:rt,selected:x,setSelected:P,isAllExpanded:false,handleColumnResize:We,handleRequestSort:Lt,handleSelectAllClick:nt,handleClick:At,toggleSummaryColumn:()=>{},handleDragEnd:()=>{},handleExport:Ot,handleContextMenu:Nt,handleCloseContextMenu:Ht,toggleColumnVisibility:Ft,toggleGroupExpand:Oe,toggleGroupField:Vt,handleToggleAll:Bt,handleExpandGroupRecursively:Et,handleCollapseGroupRecursively:Ge,handleLayoutLoad:()=>{},handleVariantLoad:lt,handleLayoutSave:it,effectiveAppId:e.appId||"",currentLayoutData:{visibleColumns:k,order:s,orderBy:l,grouping:d,columnWidths:c},currentLayoutId:"",layoutIdToLoad:"",onPageChange:at,onRowsPerPageChange:rt,graphReportOpen:B,handleOpenGraphReport:st,handleCloseGraphReport:Gt}};var Ec=e=>jsx(ai,{...e}),Bc=e=>jsx(Do,{...e}),Lc=e=>jsx(wn,{...e}),Ac=e=>jsx(pa,{...e}),Fc=e=>jsx(ma,{...e}),kt=e=>{let{title:o="Data Table",selectionMode:t,selected:i=[],onSelectionChange:s,actions:a,extraTools:l,fitContainer:n=false,fullWidth:u=false,maxHeight:v,loading:w=false,page:S=0,rowsPerPage:x=20,rowsPerPageOptions:P=[20,50,100,-1],count:k=0,onPageChange:m,onRowsPerPageChange:g,onLayoutSave:y,filterConfig:d,rowKey:I,tableKey:r="default",graphReport:b}=e,{isMobile:c,columns:C,order:M,orderBy:T,filterText:p,setFilterText:D,visibleColumns:f,showSummary:W,setShowSummary:A,summaryColumns:V,grouping:B,setGrouping:H,expandedGroups:z,groupAnchorEl:ke,setGroupAnchorEl:Me,summaryAnchorEl:ie,setSummaryAnchorEl:oe,columnWidths:Oe,anchorEl:Et,setAnchorEl:Ge,contextMenu:Bt,sensors:Lt,sortedAndFilteredRows:We,summaryRow:nt,visibleRows:At,isAllExpanded:at,handleColumnResize:rt,handleRequestSort:Ft,handleSelectAllClick:Vt,handleClick:it,toggleSummaryColumn:lt,handleDragEnd:Nt,handleExport:Ht,handleContextMenu:zt,handleCloseContextMenu:Ot,toggleColumnVisibility:st,toggleGroupExpand:Gt,toggleGroupField:h,handleToggleAll:E,handleExpandGroupRecursively:L,handleCollapseGroupRecursively:ee,handleLayoutLoad:O,handleVariantLoad:Y,handleLayoutSave:J,effectiveAppId:U,currentLayoutData:$,currentLayoutId:le,layoutIdToLoad:se,graphReportOpen:Ee,handleOpenGraphReport:pe,handleCloseGraphReport:Be}=Tn(e),Le=b?.enabled??false,{model:Wt}=Xo({rows:We,config:{...b,title:b?.title||`${o} Graphic Report`}}),Bn=Wt.table.columns.map(ct=>({id:ct.id,label:ct.label,align:ct.align||"left",minWidth:120,numeric:ct.align==="right"})),Ln=U?jsx(Cn,{appId:U,tableKey:r,currentLayoutData:$,onLayoutLoad:O,targetLayoutId:se,activeLayoutId:le,serviceUrl:(d?.variantService,void 0)}):null,ho=jsxs(Fragment,{children:[jsx(Oo,{groupAnchorEl:ke,setGroupAnchorEl:Me,grouping:B,setGrouping:H,columns:C,toggleGroupField:h}),jsx(Go,{anchorEl:Et,setAnchorEl:Ge,columns:C,visibleColumns:f,toggleColumnVisibility:st}),jsx(Wo,{anchorEl:ie,setAnchorEl:oe,showSummary:W,setShowSummary:A,columns:C,summaryColumns:V,toggleSummaryColumn:lt}),jsx($o,{contextMenu:Bt,handleCloseContextMenu:Ot,columns:C,visibleColumns:f,toggleColumnVisibility:st})]});return c?jsxs(mo,{sx:{display:"flex",flexDirection:"column",gap:2,height:"100%"},children:[d&&jsx(qe,{fields:d.fields,filters:d.filters,onFilterChange:d.onFilterChange,onSearch:d.onSearch,variants:d.variants||[],currentVariantId:d.currentVariantId,onVariantLoad:d.onVariantLoad,onVariantSave:d.onVariantSave,onVariantDelete:d.onVariantDelete,onVariantSetDefault:d.onVariantSetDefault,appId:d.appId,tableKey:r,currentLayout:[{tableKey:r,layoutData:$}],variantService:d.variantService}),jsx(Ho,{title:o,loading:w,showSummary:W,setShowSummary:A,setAnchorEl:Ge,setSummaryAnchorEl:oe,filterText:p,setFilterText:D,sortedAndFilteredRows:We,selected:i,columns:C,visibleColumns:f,summaryRow:nt,handleClick:it,selectionMode:t}),ho]}):jsxs(mo,{sx:{width:u?"100%":"auto",mb:n?0:2,...n?{flex:1,display:"flex",flexDirection:"column",minHeight:0,height:"100%"}:{}},children:[d&&jsx(mo,{sx:{mb:2},children:jsx(qe,{fields:d.fields,filters:d.filters,onFilterChange:d.onFilterChange,onSearch:d.onSearch,variants:d.variants||[],currentVariantId:d.currentVariantId,onVariantLoad:Y,onVariantSave:d.onVariantSave,onVariantDelete:d.onVariantDelete,onVariantSetDefault:d.onVariantSetDefault,loading:w,appId:d.appId,tableKey:r,currentLayout:[{tableKey:r,layoutData:$}],currentLayoutId:le,layoutRefs:[{tableKey:r,layoutId:le}],variantService:d.variantService})}),jsxs(oi,{sx:{width:u?"100%":"auto",mb:n?0:2,display:"flex",flexDirection:"column",overflow:"hidden",...v?{height:v}:n?{flex:1,minHeight:0}:{}},children:[jsx(Ro,{filterText:p,setFilterText:D,onRowsPerPageChange:g,rowsPerPage:x,rowsPerPageOptions:P,page:S,count:k,onPageChange:m,actions:a,extraTools:l,grouping:B,setGroupAnchorEl:Me,showSummary:W,setShowSummary:A,setAnchorEl:Ge,setSummaryAnchorEl:oe,handleExport:Ht,onLayoutSave:y||d?.variantService&&d?.appId?J:void 0,loading:w,layoutManager:Ln,onOpenGraphReport:Le?pe:void 0}),jsx(wn,{sx:{flex:1,maxHeight:v||"calc(100vh - 320px)",overflowY:"auto",overflowX:"auto",position:"relative",minHeight:0},children:jsx(DndContext,{sensors:Lt,collisionDetection:closestCenter,onDragEnd:Nt,modifiers:[restrictToHorizontalAxis],children:jsxs(ni,{sx:{minWidth:u?750:"auto",width:u?"100%":"auto",tableLayout:Object.keys(Oe).length>0?"fixed":"auto",borderCollapse:"separate",borderSpacing:0},"aria-labelledby":"tableTitle",size:"small",stickyHeader:true,children:[jsx(Bo,{columns:C,visibleColumns:f,order:M,orderBy:T,onRequestSort:Ft,onContextMenu:zt,selectionMode:t,grouping:B,isAllExpanded:at,handleToggleAll:E,rowCount:We.length,numSelected:i.length,onSelectAllClick:Vt,columnWidths:Oe,onColumnResize:rt}),jsx(Ao,{visibleRows:At,columns:C,visibleColumns:f,selectionMode:t,selected:i,orderBy:T,loading:w,expandedGroups:z,toggleGroupExpand:Gt,handleExpandGroupRecursively:L,handleCollapseGroupRecursively:ee,handleClick:it,onSelectionChange:s,grouping:B,rowKeyProp:I,page:S,rowsPerPage:x}),W&&jsx(Vo,{showSummary:W,columns:C,visibleColumns:f,summaryRow:nt,selectionMode:t?.toString(),orderBy:T,zIndex:3})]})})})]}),ho,Le&&jsx(Yo,{open:Ee,onClose:Be,model:Wt,tableContent:jsx(kt,{title:"Data Body",columns:Bn,rows:Wt.table.rows,rowKey:"id",fullWidth:true,maxHeight:"420px",rowsPerPage:20,rowsPerPageOptions:[20,50,100],graphReport:{enabled:false}})})]})},Vc=kt;var $c=({title:e,hideHeader:o=true,filterConfig:t,tableProps:i,children:s,spacing:a=1})=>jsxs(ko,{title:e,hideHeader:o,children:[jsxs(Stack,{spacing:a,sx:{height:"100%",overflow:"hidden"},children:[t&&jsx(Box,{sx:{flexShrink:0},children:jsx(qe,{...t})}),jsx(Box,{sx:{flex:1,minHeight:0,overflow:"hidden"},children:jsx(kt,{...i,fitContainer:true,filterConfig:void 0})})]}),s]});var Kc=({metadata:e,fetchData:o})=>{let[t,i]=useState(false),[s,a]=useState([]),[l,n]=useState({}),[u,v]=useState(e.variants||[]),[w,S]=useState(e.layout||null),[x,P]=useState(0),[k,m]=useState(0),[g,y]=useState(10),[d,I]=useState([]),[r,b]=useState("asc"),[c,C]=useState("");useEffect(()=>{let B={};e.filters.forEach(H=>{H.defaultValue!==void 0&&(B[H.id]=H.defaultValue);}),n(B);},[e.filters]);let M=useCallback(async(B,H,z,ke,Me)=>{i(true);try{let ie={...B,page:H+1,limit:z,sort:Me,order:ke},oe;o?oe=await o(ie):typeof e.api=="function"?oe=await e.api(ie):e.api&&typeof e.api=="object"?(console.log("Fetching from URL:",e.api.url,ie),oe={rows:[],total:0}):(console.warn("No API configured for report"),oe={rows:[],total:0}),oe&&(a(oe.rows||[]),P(oe.total||0));}catch(ie){console.error("Failed to fetch report data",ie);}finally{i(false);}},[e.api,o]);useEffect(()=>{M(l,k,g,r,c);},[M,k,g,r,c]);let T=()=>{m(0),M(l,0,g,r,c);},p=(B,H)=>{b(H),C(B);},D=B=>{n(B);},f=B=>{if(B.filters){let H=B.filters.find(z=>z.scope==="default"||z.scope===e.id);H&&(n(H.filters),M(H.filters,0,g));}B.layout&&S(B.layout);},W=B=>{let H={...B,id:Date.now().toString(),createdAt:new Date().toISOString()};v(z=>[...z,H]);},A=B=>{S(B);};return {pageProps:{title:e.title,filterConfig:{appId:e.id,fields:e.filters,filters:l,onFilterChange:D,onSearch:T,onVariantLoad:f,onVariantSave:W,onVariantDelete:B=>v(H=>H.filter(z=>z.id!==B)),onVariantSetDefault:B=>{v(H=>H.map(z=>({...z,isDefault:z.id===B})));},variants:u},tableProps:{appId:e.id,columns:e.columns,rows:s,loading:t,rowKey:"id",count:x,page:k,rowsPerPage:g,rowsPerPageOptions:[10,25,50,100],onPageChange:m,onRowsPerPageChange:y,selectionMode:"multiple",selected:d,onSelectionChange:I,onLayoutSave:A,layout:w,title:e.title,showSummary:true,order:r,orderBy:c,onSortChange:p,graphReport:e.graphReport||{enabled:true,title:`${e.title} Graphic Report`}}},filters:l,rows:s,loading:t,refresh:T}};var Rn=64,Mi="#E9EDF2",Ri="linear-gradient(90deg, #F5F7FA 0%, #E9EDF2 50%, #F5F7FA 100%)",Dn=({appTitle:e,logo:o,mode:t="dark",onToggleMode:i,localeLabel:s="EN",searchPlaceholder:a="Ask me...",onSearch:l,user:n,leftSlot:u,rightSlot:v})=>{let S=useTheme().palette.mode==="dark",[x,P]=useState(""),k=y=>{y.preventDefault(),l&&l(x.trim());},m=t==="system"?jsx(wi,{fontSize:"small"}):t==="dark"?jsx(Ii,{fontSize:"small"}):jsx(ki,{fontSize:"small"}),g=t==="system"?"Theme: System":t==="dark"?"Theme: Dark":"Theme: Light";return jsx(AppBar,{position:"sticky",elevation:0,sx:y=>({top:0,zIndex:y.zIndex.drawer+10,height:Rn,backgroundColor:y.palette.mode==="dark"?"#0D0D0D":Mi,backgroundImage:y.palette.mode==="dark"?["radial-gradient(circle at 18% 22%, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0) 45%)","radial-gradient(circle at 78% 32%, rgba(144,202,249,0.14) 0%, rgba(144,202,249,0) 42%)","linear-gradient(90deg, #0A0A0A 0%, #151515 50%, #0A0A0A 100%)","linear-gradient(rgba(255,255,255,0.04) 1px, transparent 1px)","linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px)"].join(","):["radial-gradient(circle at 22% 22%, rgba(255,255,255,0.7) 0%, rgba(255,255,255,0) 48%)","radial-gradient(circle at 76% 24%, rgba(203,213,225,0.45) 0%, rgba(203,213,225,0) 42%)",Ri,"linear-gradient(rgba(15,23,42,0.05) 1px, transparent 1px)","linear-gradient(90deg, rgba(15,23,42,0.04) 1px, transparent 1px)"].join(","),backgroundSize:"auto, auto, auto, 24px 24px, 24px 24px",borderBottom:"1px solid",borderColor:y.palette.mode==="dark"?"rgba(255,255,255,0.12)":"rgba(15,23,42,0.12)"}),children:jsxs(Toolbar,{sx:{minHeight:`${Rn}px !important`,px:2,gap:2},children:[jsxs(Stack,{direction:"row",alignItems:"center",spacing:1.5,sx:{minWidth:220},children:[o||jsx(Box,{component:"img",src:"/orbcafe.png",alt:"ORBCAFE Logo",sx:{width:44,height:44,display:"block",objectFit:"contain",flexShrink:0}}),e&&jsx(Typography,{variant:"h6",sx:{fontWeight:700,color:S?"common.white":"#111827"},children:e}),u]}),jsx(Box,{sx:{flex:1,display:"flex",justifyContent:"center",minWidth:0},children:jsx(Box,{component:"form",onSubmit:k,sx:{width:"100%",maxWidth:540},children:jsx(TextField,{size:"small",fullWidth:true,value:x,onChange:y=>P(y.target.value),placeholder:a,InputProps:{startAdornment:jsx(InputAdornment,{position:"start",children:jsx(cn,{sx:{color:S?"rgba(255,255,255,0.7)":"rgba(15,23,42,0.55)",fontSize:18}})}),sx:{color:S?"common.white":"rgba(17,24,39,0.9)",bgcolor:S?"rgba(255,255,255,0.08)":"#ffffff",borderRadius:999,"& .MuiOutlinedInput-notchedOutline":{borderColor:S?"rgba(255,255,255,0.15)":"rgba(15,23,42,0.2)"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:S?"rgba(255,255,255,0.35)":"rgba(15,23,42,0.35)"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:S?"rgba(255,255,255,0.5)":"rgba(15,23,42,0.55)"}}},inputProps:{style:{color:S?"white":"#111827"}}})})}),jsxs(Stack,{direction:"row",alignItems:"center",spacing:1.5,children:[jsxs(Stack,{direction:"row",alignItems:"center",spacing:.5,children:[jsx(Ti,{sx:{color:S?"common.white":"#111827",fontSize:18}}),jsx(Typography,{variant:"caption",sx:{color:S?"common.white":"#111827",fontWeight:500},children:s})]}),jsx(IconButton,{size:"small",sx:{color:S?"common.white":"#111827"},onClick:i,title:g,children:m}),n&&jsxs(Stack,{direction:"row",alignItems:"center",spacing:1,children:[jsx(Box,{sx:{textAlign:"right"},children:jsx(Typography,{variant:"body2",sx:{color:S?"common.white":"#111827",fontWeight:600,lineHeight:1.2},children:n.name})}),jsx(Avatar,{src:n.avatarSrc,imgProps:{style:{objectFit:"cover"}},sx:{width:34,height:34,bgcolor:"grey.100",color:"grey.700",fontSize:"0.85rem"},children:n.avatarText||n.name.slice(0,1).toUpperCase()})]}),v]})]})})};var Pn=({menuData:e=[],initialNavigationCollapsed:o=false}={})=>{let{navigationIslandProps:t}=Io({initialCollapsed:o,content:e}),[i,s]=useState(900);useEffect(()=>{let l=()=>s(window.innerHeight);return l(),window.addEventListener("resize",l),()=>window.removeEventListener("resize",l)},[]);let a=useMemo(()=>Math.max(280,i-100),[i]);return {navigationIslandProps:t,navigationMaxHeight:a}};var md=({appTitle:e,menuData:o=[],children:t,showNavigation:i=true,localeLabel:s,user:a,logo:l,onSearch:n,rightHeaderSlot:u,leftHeaderSlot:v,contentSx:w})=>{let[S,x]=useState("system"),[P,k]=useState("light"),[m,g]=useState(false),y=S==="system"?m?P:"light":S;useEffect(()=>{g(true);let b=window.matchMedia("(prefers-color-scheme: dark)"),c=()=>{k(b.matches?"dark":"light");};return c(),b.addEventListener("change",c),()=>b.removeEventListener("change",c)},[]);let d=useMemo(()=>createTheme({palette:{mode:y}}),[y]),{navigationIslandProps:I,navigationMaxHeight:r}=Pn({menuData:o,initialNavigationCollapsed:false});return jsx(ThemeProvider,{theme:d,children:jsxs(Box,{sx:b=>({minHeight:"100vh",display:"flex",flexDirection:"column",background:b.palette.mode==="dark"?"linear-gradient(180deg, #0A0A0A 0%, #141414 55%, #1A1A1A 100%)":b.palette.background.default}),children:[jsx(Dn,{appTitle:e,logo:l,mode:S,onToggleMode:()=>x(b=>b==="system"?"dark":b==="dark"?"light":"system"),localeLabel:s,user:a,onSearch:n,leftSlot:v,rightSlot:u}),jsxs(Box,{sx:{flex:1,minHeight:0,display:"flex"},children:[i&&jsx(Box,{sx:{p:1.5,display:"flex",alignItems:"flex-start",flexShrink:0},children:jsx(To,{...I,maxHeight:r,colorMode:y})}),jsx(Box,{sx:{flex:1,minWidth:0,minHeight:0,overflow:"auto",p:1.5,...w},children:t})]})]})})};export{_t as Button,Dn as CAppHeader,md as CAppPageLayout,bn as CLayoutManagement,Cn as CLayoutManager,ko as CPageLayout,qe as CSmartFilter,Vc as CSmartTable,$c as CStandardPage,kt as CTable,Ec as CTableBody,Bc as CTableCell,Lc as CTableContainer,Ac as CTableHead,Fc as CTableRow,bt as CVariantManagement,nn as CVariantManager,To as NavigationIsland,Ut as TreeMenu,Hn as buttonVariants,Io as useNavigationIsland,Pn as usePageLayout,Kc as useStandardReport};
1
+ import*as So from'react';import So__default,{useState,useEffect,useCallback,useMemo,useRef}from'react';import {usePathname,useRouter}from'next/navigation';import {ChevronRight,Search}from'lucide-react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {Slot}from'@radix-ui/react-slot';import {cva}from'class-variance-authority';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {styled,Box,Typography,Autocomplete,TextField,Tooltip,IconButton,Dialog,DialogTitle,DialogContent,FormControlLabel,Checkbox,DialogActions,Button,Paper,Menu,MenuItem,ListItemText,Divider,Collapse,Grid,ListItemIcon,Stack,useTheme,AppBar,Toolbar,InputAdornment,Avatar,createTheme,ThemeProvider,Popover,ListSubheader,Badge,Switch,TableBody,TableRow,TableCell,TableFooter,Chip}from'@mui/material';import bo from'@mui/material/Box';import si from'@mui/material/Paper';import ci from'@mui/material/Table';import di from'@mui/material/TableBody';import Bo from'@mui/material/TableCell';import Rn from'@mui/material/TableContainer';import xa from'@mui/material/TableHead';import Ca from'@mui/material/TableRow';import {DndContext,closestCenter}from'@dnd-kit/core';import {restrictToHorizontalAxis}from'@dnd-kit/modifiers';import mn from'@mui/icons-material/Search';import da from'@mui/icons-material/ViewColumn';import vn from'@mui/icons-material/Save';import pa from'@mui/icons-material/Download';import ma from'@mui/icons-material/AccountTree';import ga from'@mui/icons-material/Functions';import fa from'@mui/icons-material/Insights';import va from'@mui/material/Checkbox';import Sa from'@mui/material/TableSortLabel';import Ma from'@mui/icons-material/KeyboardArrowRight';import Ra from'@mui/icons-material/KeyboardArrowDown';import Oa from'@mui/icons-material/Check';import Ga from'@mui/icons-material/ClearAll';import Qa from'@mui/icons-material/Close';import zr from'@mui/icons-material/Settings';import Or from'@mui/icons-material/KeyboardArrowUp';import Wr from'@mui/icons-material/ArrowRightAlt';import pr from'@mui/icons-material/Star';import {DateCalendar}from'@mui/x-date-pickers/DateCalendar';import {PickersDay}from'@mui/x-date-pickers/PickersDay';import Mr from'@mui/icons-material/CalendarMonth';import Rr from'@mui/icons-material/Clear';import Dr from'@mui/icons-material/ArrowForward';import Ee from'dayjs';import Pr from'dayjs/plugin/isBetween';import ei from'@mui/icons-material/Delete';import oi from'@mui/icons-material/StarBorder';import ni from'@mui/icons-material/ViewQuilt';import Ri from'@mui/icons-material/Language';import Di from'@mui/icons-material/DesktopWindows';import Pi from'@mui/icons-material/DarkMode';import Ei from'@mui/icons-material/LightMode';import Bi from'@mui/icons-material/Logout';function le(...e){return twMerge(clsx(e))}var Kt={primary:"#000000",primaryHover:"#333333"},pt={primary:"bg-primary text-primary-foreground hover:bg-primary/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",ghost:"hover:bg-accent hover:text-accent-foreground"},_e={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",full:"rounded-full"},vo=()=>"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50";var Un=cva(vo(),{variants:{variant:{default:`${pt.primary} shadow-sm`,destructive:"bg-red-500 text-white hover:bg-red-600 active:bg-red-700 dark:bg-red-600 dark:hover:bg-red-500 dark:active:bg-red-700 shadow-sm",outline:`${pt.outline} shadow-sm`,secondary:"bg-gray-200 text-gray-700 hover:bg-gray-300 active:bg-gray-400 dark:bg-gray-700 dark:text-gray-200 dark:hover:bg-gray-600 dark:active:bg-gray-500 shadow-sm",ghost:pt.ghost,link:"text-blue-600 dark:text-blue-400 underline-offset-4 hover:underline hover:text-blue-700 dark:hover:text-blue-300 active:text-blue-800 dark:active:text-blue-200","chat-tool":"bg-[var(--orbai-surface-2)] border border-[var(--orbai-border-soft)] text-[var(--orbai-text-2)] hover:bg-[var(--orbai-surface-3)] hover:border-[var(--orbai-border-strong)] hover:text-[var(--orbai-text-1)] active:scale-95 transition-all duration-200","chat-send":`bg-[${Kt.primary}] hover:bg-[${Kt.primaryHover}] text-white border border-[var(--orbai-border-strong)] shadow-[var(--orbai-shadow-soft-sm)] hover:shadow-[var(--orbai-shadow-soft-md)] active:scale-95 transition-all duration-200`,"chat-stop":"bg-red-500 hover:bg-red-600 border border-[var(--orbai-border-strong)] shadow-[var(--orbai-shadow-soft-sm)] hover:shadow-[var(--orbai-shadow-soft-md)] active:scale-95 text-white transition-all duration-200","chat-disabled":"cursor-not-allowed opacity-50 bg-[var(--orbai-surface-2)] border border-[var(--orbai-border-soft)] text-[var(--orbai-muted)]"},size:{default:"h-10 px-4 py-2",sm:"h-9 px-3",lg:"h-11 px-8",icon:"h-10 w-10","chat-sm":"h-8 w-8 rounded-full","chat-md":"h-10 w-10 rounded-full","chat-lg":"h-12 w-12 rounded-full"},rounded:{none:_e.none,sm:_e.sm,md:_e.md,full:_e.full}},defaultVariants:{variant:"default",size:"default",rounded:"md"}}),Yt=So.forwardRef(({className:e,variant:o,size:t,asChild:r=false,...l},n)=>jsx(r?Slot:"button",{className:le(Un({variant:o,size:t,className:e})),ref:n,...l}));Yt.displayName="Button";function Xt({items:e,onItemClick:o,className:t="",level:r=0,expandedIds:l,onToggleExpand:n,colorMode:i="light"}){let a=i==="dark",d=usePathname(),[T,k]=useState(new Set),w=l!==void 0&&n!==void 0,C=w?l:T,E=m=>{if(w)n(m);else {let f=new Set(T);f.has(m)?f.delete(m):f.add(m),k(f);}},M=m=>{m.children&&m.children.length>0&&E(m.id),o&&o(m);};return !e||!Array.isArray(e)?jsx("div",{className:le("tree-menu",t),children:jsx("div",{className:"text-sm text-gray-500 p-2",children:"No items to display"})}):jsx("div",{className:le("tree-menu",t),children:e.map(m=>{let f=C.has(m.id)||m.isExpanded,S=m.children&&m.children.length>0,y=m.appurl||m.href,g=y?d===y:false;return jsxs("div",{className:"tree-menu-item relative",children:[g&&jsx("div",{className:le("absolute left-0 top-2 bottom-2 w-[3px] rounded-r-full z-10",a?"bg-[#90caf9]":"bg-[#1976d2]")}),jsxs(Yt,{variant:"ghost",className:le("w-full justify-start gap-2 h-auto py-2 relative overflow-hidden group",`ml-${r*4}`,g?a?"bg-transparent text-[#90caf9] hover:bg-gray-800/35":"bg-transparent text-[#1976d2] hover:bg-gray-100/60":a?"hover:bg-gray-800/50 text-gray-300":"hover:bg-gray-100/50 text-gray-700"),onClick:()=>M(m),children:[S&&jsx("div",{className:le("flex-shrink-0 transition-transform duration-200",f&&"rotate-90",g?a?"text-[#90caf9]":"text-[#1976d2]":a?"text-gray-500 group-hover:text-gray-300":"text-gray-400 group-hover:text-gray-600"),children:jsx(ChevronRight,{className:"h-4 w-4"})}),!S&&jsx("div",{className:"w-4 h-4 flex-shrink-0"}),m.icon&&jsx("div",{className:le("flex-shrink-0 transition-colors duration-200",g?a?"text-[#90caf9]":"text-[#1976d2]":a?"text-gray-500 group-hover:text-gray-300":"text-gray-400 group-hover:text-gray-600"),children:m.icon}),jsxs("div",{className:"flex-1 text-left overflow-hidden z-10",children:[jsx("div",{className:le("text-sm truncate transition-colors duration-200",g?"font-semibold":"font-medium"),children:m.title||m.label}),m.description&&jsx("div",{className:le("text-xs truncate transition-colors duration-200",g?a?"text-[#90caf9]/70":"text-[#1976d2]/75":a?"text-gray-400":"text-gray-500"),title:m.description,children:m.description})]})]}),S&&jsx("div",{className:le("grid transition-[grid-template-rows] duration-300 ease-in-out",f?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:jsx("div",{className:"overflow-hidden",children:jsx(Xt,{items:m.children,onItemClick:o,level:r+1,expandedIds:l,onToggleExpand:n,colorMode:i})})})]},m.id)})})}var Mo=({collapsed:e,onToggle:o,className:t="",maxHeight:r,menuData:l=[],colorMode:n="light"})=>{let i=n==="dark",a=useRouter(),[d,T]=useState(""),[k,w]=useState(new Set);useEffect(()=>{e&&w(new Set);},[e]);let C=useCallback(f=>{let S=[],y=g=>{g.forEach(p=>{S.push(p.id),p.children&&y(p.children);});};return y(f),S},[]),E=useMemo(()=>{if(!d.trim())return l;let f=S=>S.reduce((y,g)=>{let p=g.title?.toLowerCase().includes(d.toLowerCase())||g.description?.toLowerCase().includes(d.toLowerCase()),I=g.children?f(g.children):[];return (p||I.length>0)&&y.push({...g,children:I.length>0?I:g.children}),y},[]);return f(l)},[d,l]),M=useMemo(()=>d.trim()?new Set(C(l)):k,[d,l,k,C]),m=useCallback(async f=>{if(console.log("\u{1F5B1}\uFE0F \u5BFC\u822A\u83DC\u5355\u9879\u70B9\u51FB:",f),f.id==="chat"||f.appurl==="/chat"){console.log("\u{1F4AC} \u68C0\u6D4B\u5230chat\u83DC\u5355\u70B9\u51FB\uFF0C\u8DF3\u8F6C\u5230\u65B0\u7684\u804A\u5929\u89C6\u56FE");try{a.push("/chat?new=true");}catch(y){console.error("\u274C \u65E0\u6CD5\u8DF3\u8F6C\u5230\u65B0\u804A\u5929\u89C6\u56FE:",y),a.push("/chat");}return}let S=f.appurl||f.href;S&&(S.startsWith("http://")||S.startsWith("https://")?window.open(S,"_blank"):a.push(S));},[a]);return jsxs("div",{className:`flex flex-col backdrop-blur-xl border shadow-[0_4px_8px_0_rgba(31,38,135,0.1)] ${e?"w-14 rounded-full":"w-[234px] rounded-2xl"} relative ${t} ${i?"bg-[#111111] border-white/10":"bg-white/70 border-white/30"}`,style:{backdropFilter:"blur(16px) saturate(180%)",WebkitBackdropFilter:"blur(16px) saturate(180%)",transition:"width 400ms cubic-bezier(0.4, 0.0, 0.2, 1), border-radius 0ms cubic-bezier(0.4, 0.0, 0.2, 1), box-shadow 400ms ease-out",maxHeight:r?`${r}px`:void 0},children:[jsx("div",{className:`pt-4 pb-2 transition-all duration-500 ease-in-out ${e?"px-1":"px-2"}`,children:e?jsx("div",{className:"flex justify-center",children:jsx("button",{onClick:o,className:`w-10 h-10 flex items-center justify-center rounded-lg transition-colors duration-200 ${i?"text-gray-300 hover:bg-gray-800":"text-gray-500 hover:bg-gray-50"}`,title:"\u5C55\u5F00\u5BFC\u822A",children:jsx(Search,{className:"h-5 w-5"})})}):jsxs("div",{className:`relative transition-opacity duration-300 ${e?"opacity-0":"opacity-100 delay-200"}`,children:[jsx("input",{type:"text",placeholder:"\u641C\u7D22\u83DC\u5355...",value:d,onChange:f=>T(f.target.value),className:`w-full pl-10 pr-4 py-2 text-sm border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent ${i?"border-gray-700 bg-[#1A1A1A] text-white placeholder-gray-400":"border-gray-300 bg-white text-gray-900 placeholder-gray-500"}`}),jsx("div",{className:"absolute left-3 top-1/2 transform -translate-y-1/2 pointer-events-none",children:jsx(Search,{className:`h-4 w-4 ${i?"text-gray-500":"text-gray-400"}`})})]})}),jsx("nav",{className:`flex-1 pb-4 transition-all duration-500 ease-in-out overflow-y-auto min-h-0 ${e?"px-1":"px-2"}`,children:E.length===0?jsx("div",{className:"flex items-center justify-center py-8 text-gray-500 text-sm",children:e?"\u{1F4C2}":d?"\u672A\u627E\u5230\u5339\u914D\u7684\u83DC\u5355\u9879":"\u6682\u65E0\u53EF\u8BBF\u95EE\u7684\u5E94\u7528"}):jsxs(Fragment,{children:[!e&&jsx("div",{className:`transition-opacity duration-300 ${e?"opacity-0":"opacity-100 delay-200"}`,children:jsx(Xt,{items:E,onItemClick:m,className:"space-y-1",expandedIds:M,colorMode:n,onToggleExpand:f=>{let S=new Set(k);E.some(g=>g.id===f)?S.has(f)?S.delete(f):(E.forEach(g=>{g.id!==f&&S.has(g.id)&&S.delete(g.id);}),S.add(f)):S.has(f)?S.delete(f):S.add(f),w(S);}})}),e&&jsx("div",{className:"space-y-2",children:l.map(f=>jsx("div",{className:"space-y-1",children:jsx("button",{onClick:()=>{o();let S=new Set([f.id]);w(S);},className:`w-full flex items-center justify-center p-2 rounded-lg cursor-pointer transition-colors duration-200 ${i?"text-gray-400 hover:bg-gray-800":"text-gray-600 hover:bg-gray-50"}`,title:`\u5C55\u5F00\u67E5\u770B ${f.title}`,children:f.icon||jsx("div",{className:`w-6 h-6 rounded text-xs flex items-center justify-center font-medium ${i?"bg-[#90caf9] text-[#0b0b0b]":"bg-[#1976d2] text-white"}`,children:f.title?.charAt(0)||"?"})})},f.id))})]})}),!e&&jsx("button",{onClick:o,className:`absolute -bottom-1 -right-1 w-6 h-6 bg-transparent rounded-full flex items-center justify-center transition-all duration-300 ease-in-out z-20 ${i?"hover:bg-gray-800/50":"hover:bg-white/20"}`,title:"\u6298\u53E0\u5BFC\u822A",children:jsx("div",{className:"absolute",style:{bottom:"0px",right:"0px",width:"16px",height:"16px",overflow:"hidden"},children:jsx("div",{className:i?"border-yellow-400":"",style:{width:"32px",height:"32px",borderRadius:"16px",border:"3px solid #21BCFF",backgroundColor:"transparent",position:"absolute",top:"-16px",left:"-16px"}})})})]})};var Do=(e={})=>{let{initialCollapsed:o=false,content:t=[]}=e,[r,l]=useState(o),[n,i]=useState(t),a=useCallback(()=>{l(T=>!T);},[]),d=useMemo(()=>({collapsed:r,onToggle:a,menuData:n}),[r,a,n]);return {collapsed:r,setCollapsed:l,toggleCollapsed:a,menuData:n,setMenuData:i,navigationIslandProps:d}};var Po=({title:e,hideHeader:o,children:t})=>jsxs(Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[!o&&jsx(Box,{sx:{mb:2},children:jsx(Typography,{variant:"h4",children:e})}),jsx(Box,{sx:{flex:1,overflow:"hidden"},children:t})]});var Lo=e=>{let o="0.75rem",t=Array.isArray(e.actions)?e.actions:e.actions?[e.actions]:[],r=Array.isArray(e.extraTools)?e.extraTools:e.extraTools?[e.extraTools]:[],l=[...t,...r];return jsxs(Toolbar,{sx:{pl:{sm:2},pr:{xs:1,sm:1},alignItems:"center",gap:1},children:[jsx(TextField,{size:"small",placeholder:"Search...",value:e.filterText,onChange:n=>e.setFilterText(n.target.value),InputProps:{sx:{fontSize:o,"& .MuiInputBase-input":{fontSize:o},"& .MuiInputBase-input::placeholder":{fontSize:o,opacity:1}},startAdornment:jsx(InputAdornment,{position:"start",children:jsx(mn,{fontSize:"small"})})},sx:{width:300}}),jsx(Box,{sx:{flex:1}}),jsxs(Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsx(Box,{sx:{width:1,height:20,bgcolor:"divider",mr:.5}}),jsx(Tooltip,{title:"Group By",children:jsx(IconButton,{onClick:n=>e.setGroupAnchorEl(n.currentTarget),children:jsx(Badge,{badgeContent:e.grouping?.length,color:"primary",children:jsx(ma,{})})})}),jsx(Tooltip,{title:"Summary",children:jsx(IconButton,{onClick:n=>e.setSummaryAnchorEl(n.currentTarget),color:e.showSummary?"primary":"default",children:jsx(ga,{})})}),jsx(Tooltip,{title:"Columns",children:jsx(IconButton,{onClick:n=>e.setAnchorEl(n.currentTarget),children:jsx(da,{})})}),jsx(Tooltip,{title:"Export",children:jsx(IconButton,{onClick:e.handleExport,children:jsx(pa,{})})}),e.onOpenGraphReport&&jsx(Tooltip,{title:"Graphic Report",children:jsx(IconButton,{onClick:e.onOpenGraphReport,children:jsx(fa,{})})}),e.onLayoutSave&&!e.layoutManager&&jsx(Tooltip,{title:"Save Layout",children:jsx(IconButton,{onClick:n=>e.onLayoutSave(n),children:jsx(vn,{})})}),e.layoutManager,l.length>0&&jsx(Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:l.map((n,i)=>jsx(So__default.Fragment,{children:n},`toolbar-custom-${i}`))})]})]})};var Vo=e=>{let{onSelectAllClick:o,order:t,orderBy:r,numSelected:l=0,rowCount:n=0,onRequestSort:i,columns:a,visibleColumns:d,selectionMode:T,onColumnResize:k,columnWidths:w}=e,[C,E]=useState(null),M=useRef(null),m=p=>I=>{C||i(p);},f=(p,I,c)=>{p.preventDefault(),p.stopPropagation(),E(I),M.current={startX:p.clientX,startWidth:c,colId:I},document.addEventListener("mousemove",S),document.addEventListener("mouseup",y),document.body.style.cursor="col-resize";},S=p=>{if(!M.current)return;let{startX:I,startWidth:c,colId:u}=M.current,b=p.clientX-I,x=Math.max(50,c+b);k&&k(u,x);},y=()=>{E(null),M.current=null,document.removeEventListener("mousemove",S),document.removeEventListener("mouseup",y),document.body.style.cursor="";};return useEffect(()=>()=>{document.removeEventListener("mousemove",S),document.removeEventListener("mouseup",y);},[]),jsx(xa,{children:jsxs(Ca,{children:[(T==="multiple"||T==="single")&&jsx(Bo,{padding:"checkbox",sx:p=>({width:48,backgroundColor:p.palette.mode==="dark"?"#000000":"#f5f5f5",color:p.palette.mode==="dark"?"#ffffff":p.palette.text.primary}),children:jsx(va,{color:"primary",indeterminate:l>0&&l<n,checked:n>0&&l===n,onChange:o,disabled:T==="single"})}),a.filter(p=>d.includes(p.id)).map(p=>{let I=w?.[p.id]||p.minWidth||100;return jsxs(Bo,{align:"left",padding:p.disablePadding?"none":"normal",sortDirection:r===p.id?t:false,style:{width:I,minWidth:I,maxWidth:I},sx:c=>({position:"relative",backgroundColor:c.palette.mode==="dark"?"#000000":"#f5f5f5",color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary,fontWeight:"bold",userSelect:"none"}),children:[jsx(Sa,{active:r===p.id,direction:r===p.id?t:"asc",onClick:m(p.id),sx:c=>({"&.MuiTableSortLabel-root":{width:"100%"},"& .MuiTableSortLabel-icon":{color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary,opacity:r===p.id?1:0,transition:"opacity 0.2s"},"&:hover .MuiTableSortLabel-icon":{opacity:.5},"&.Mui-active .MuiTableSortLabel-icon":{opacity:1,color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary},fontWeight:"bold",color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary}),children:jsx(bo,{component:"span",sx:{overflow:"visible",textOverflow:"clip",whiteSpace:"normal",lineHeight:1.2,wordBreak:"break-word",pr:1},children:p.label})}),jsx(bo,{onMouseDown:c=>f(c,p.id,typeof I=="number"?I:100),onClick:c=>c.stopPropagation(),sx:{position:"absolute",right:0,top:0,bottom:0,width:5,cursor:"col-resize","&:hover":{backgroundColor:"primary.main",opacity:.5},zIndex:1}})]},p.id)})]})})};var Ho=e=>{let{visibleRows:o,visibleColumns:t,selected:r=[],handleClick:l,columns:n,toggleGroupExpand:i,expandedGroups:a=new Set,selectionMode:d}=e,T=C=>r.indexOf(C)!==-1,k=d==="multiple"||d==="single",w=t.length+(k?1:0);return jsxs(TableBody,{children:[o.map((C,E)=>{if(C.type==="group"){let M=a.has(C.id),m=C.childIds||[],f=m.filter(p=>T(p)).length,S=m.length>0&&f===m.length,y=f>0&&f<m.length,g=p=>{if(p.stopPropagation(),!!e.onSelectionChange)if(S){let I=r.filter(c=>!m.includes(c));e.onSelectionChange(I);}else {let I=Array.from(new Set([...r,...m]));e.onSelectionChange(I);}};return jsx(TableRow,{sx:p=>({backgroundColor:p.palette.mode==="dark"?"#111111":"#f5f5f5","& .MuiTableCell-root":{color:p.palette.text.primary,borderBottomColor:p.palette.divider},"& .MuiIconButton-root":{color:p.palette.text.primary},"& .MuiCheckbox-root":{color:p.palette.text.secondary},"& .MuiCheckbox-root.Mui-checked, & .MuiCheckbox-root.MuiCheckbox-indeterminate":{color:p.palette.primary.main}}),children:jsx(TableCell,{colSpan:w,sx:{py:1,pl:C.level*4+2},children:jsxs(Box,{sx:{display:"flex",alignItems:"center"},children:[jsx(IconButton,{size:"small",onClick:()=>i&&i(C.id),sx:{mr:1},children:M?jsx(Ra,{}):jsx(Ma,{})}),k&&jsx(Checkbox,{size:"small",checked:S,indeterminate:y,onChange:g,onClick:p=>p.stopPropagation(),sx:{mr:1,p:.5}}),jsxs(Typography,{variant:"body2",fontWeight:"bold",color:"text.primary",children:[C.field,": ",C.value," (",C.count,")"]})]})})},C.id)}else {let M=C.data||C,m=C.id||M.id||E,f=T(m),S=`enhanced-table-checkbox-${E}`,g=(C.level!==void 0?C.level:0)*4;return jsxs(TableRow,{hover:true,onClick:p=>l&&l(p,M),role:"checkbox","aria-checked":f,tabIndex:-1,selected:f,sx:{cursor:"pointer"},children:[k&&jsx(TableCell,{padding:"checkbox",sx:{pl:g>0?g+1:void 0},children:jsx(Checkbox,{color:"primary",checked:f,inputProps:{"aria-labelledby":S}})}),n.filter(p=>t.includes(p.id)).map((p,I)=>{let u=!k&&I===0&&g>0?{pl:g+2}:{};return jsx(TableCell,{align:"left",sx:u,children:p.render?p.render(M[p.id],M):(function(){let x=M[p.id];if(p.numeric){if(typeof x=="number")return x.toLocaleString();if(typeof x=="string"&&x.trim()!==""&&!isNaN(Number(x)))return Number(x).toLocaleString()}return x})()},p.id)})]},m)}}),o.length===0&&jsx(TableRow,{children:jsx(TableCell,{colSpan:w,align:"center",children:"No data"})})]})};var Oo=e=>{let{visibleColumns:o,summaryRow:t,selectionMode:r}=e;if(!e.showSummary)return null;let l=r==="multiple"||r==="single";return jsx(TableFooter,{sx:{position:"sticky",bottom:0,zIndex:e.zIndex,bgcolor:"background.paper"},children:jsxs(TableRow,{children:[l&&jsx(TableCell,{padding:"checkbox",sx:{bgcolor:"background.paper"}}),o.map(n=>jsx(TableCell,{sx:{fontWeight:"bold",fontSize:"0.875rem",bgcolor:"background.paper",color:"text.primary"},children:(function(){let a=t[n];return a==null||a===""?"":typeof a=="number"?a.toLocaleString():typeof a=="string"&&a.trim()!==""&&!isNaN(Number(a))?Number(a).toLocaleString():a})()},n))]})})};var Wo=e=>jsx(Box,{sx:{p:2},children:jsx(Typography,{children:"Mobile View Not Implemented"})});var _o=({groupAnchorEl:e,setGroupAnchorEl:o,grouping:t,setGrouping:r,columns:l,toggleGroupField:n})=>jsxs(Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsxs(Box,{sx:{p:1,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[jsx(Typography,{variant:"subtitle2",sx:{px:1},children:"Group By"}),t.length>0&&jsx(Button,{size:"small",color:"error",onClick:()=>r([]),startIcon:jsx(Ga,{}),children:"Clear All"})]}),jsx(Divider,{}),l.map(i=>{let a=t.includes(i.id),d=t.indexOf(i.id)+1;return jsx(MenuItem,{onClick:()=>n(i.id),children:jsxs(Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsx(Checkbox,{checked:a,size:"small"}),jsx(ListItemText,{primary:i.label}),a&&jsx(Badge,{badgeContent:d,color:"primary",sx:{mr:2}})]})},i.id)})]}),jo=({anchorEl:e,setAnchorEl:o,columns:t,visibleColumns:r,toggleColumnVisibility:l})=>jsxs(Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"Visible Columns"})}),jsx(Divider,{}),t.map(n=>jsxs(MenuItem,{onClick:()=>l(n.id),children:[jsx(Checkbox,{checked:r.includes(n.id),size:"small"}),jsx(ListItemText,{primary:n.label})]},n.id))]}),Uo=({anchorEl:e,setAnchorEl:o,showSummary:t,setShowSummary:r,columns:l,summaryColumns:n,toggleSummaryColumn:i})=>jsxs(Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsx(MenuItem,{children:jsx(FormControlLabel,{control:jsx(Switch,{checked:t,onChange:a=>r(a.target.checked),size:"small"}),label:"Show Summary Row"})}),jsx(Divider,{}),l.filter(a=>a.numeric).map(a=>jsxs(MenuItem,{onClick:()=>i(a.id),disabled:!t,children:[jsx(Checkbox,{checked:n.includes(a.id),size:"small"}),jsx(ListItemText,{primary:a.label})]},a.id)),l.filter(a=>a.numeric).length===0&&jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"No numeric columns"})})]}),Ko=({contextMenu:e,handleCloseContextMenu:o,columns:t,visibleColumns:r,toggleColumnVisibility:l})=>jsxs(Menu,{open:e!==null,onClose:o,anchorReference:"anchorPosition",anchorPosition:e!==null?{top:e.mouseY,left:e.mouseX}:void 0,children:[jsx(MenuItem,{onClick:o,children:"Copy"}),jsx(Divider,{}),jsx(MenuItem,{disabled:true,children:"Visible Columns"}),t.map(n=>jsxs(MenuItem,{onClick:()=>l(n.id),children:[jsx(ListItemIcon,{children:r.includes(n.id)&&jsx(Oa,{fontSize:"small"})}),jsx(ListItemText,{children:n.label})]},n.id))]});var je=(e,o=2)=>e.toLocaleString(void 0,{maximumFractionDigits:o}),qo=({kpis:e})=>{let o=[{label:"Total Records",value:je(e.totalRecords,0),color:"text.primary"},{label:"Total Report",value:je(e.totalReportHours),color:"text.primary"},{label:"Total Billable",value:je(e.totalBillableHours),color:"success.main"},{label:"Efficiency",value:`${e.efficiency.toFixed(2)}%`,color:"warning.main"},{label:"Amount",value:je(e.totalAmount),color:"info.main"},{label:"Flagged",value:je(e.flaggedCount,0),color:"error.main"}];return jsx(Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"repeat(2, minmax(0, 1fr))",lg:"repeat(6, minmax(0, 1fr))"},gap:1.5},children:o.map(t=>jsxs(Paper,{variant:"outlined",sx:{p:1.5,borderRadius:2,minHeight:96,display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[jsx(Typography,{variant:"caption",color:"text.secondary",children:t.label}),jsx(Typography,{variant:"h4",fontWeight:800,sx:{color:t.color},children:t.value})]},t.label))})};var bt=["#1E88E5","#1ABC9C","#FBC02D","#EF5350","#7E57C2","#78909C"],Ua=({data:e})=>{let o=Math.max(...e.map(t=>t.value),1);return jsx(Stack,{spacing:1,children:e.map(t=>jsxs(Box,{sx:{display:"grid",gridTemplateColumns:"140px 1fr 64px",gap:1},children:[jsx(Typography,{variant:"caption",color:"text.secondary",noWrap:true,title:t.name,children:t.name}),jsx(Box,{sx:{alignSelf:"center",bgcolor:"action.hover",height:10,borderRadius:999,overflow:"hidden"},children:jsx(Box,{sx:{width:`${t.value/o*100}%`,height:"100%",bgcolor:"primary.main"}})}),jsx(Typography,{variant:"caption",sx:{textAlign:"right",fontWeight:600},children:t.value.toFixed(1)})]},t.name))})},Ka=({data:e})=>{let o=Math.max(...e.map(t=>t.value),1);return jsx(Box,{sx:{display:"flex",gap:1,alignItems:"flex-end",minHeight:210},children:e.map(t=>jsxs(Box,{sx:{flex:1,minWidth:0},children:[jsx(Box,{sx:{height:`${Math.max(t.value/o*180,6)}px`,bgcolor:"primary.main",borderRadius:"8px 8px 0 0"}}),jsx(Typography,{variant:"caption",noWrap:true,title:t.name,sx:{display:"block",mt:.5},children:t.name}),jsxs(Typography,{variant:"caption",color:"text.secondary",children:[t.value.toFixed(1),"%"]})]},t.name))})},Ya=({data:e})=>{if(e.length===0)return jsx(Typography,{variant:"body2",color:"text.secondary",children:"No data"});let o=0,r=`conic-gradient(${e.map((l,n)=>{let i=o;return o+=l.percent,`${bt[n%bt.length]} ${i}% ${o}%`}).join(", ")})`;return jsxs(Stack,{direction:{xs:"column",sm:"row"},spacing:2,alignItems:"center",children:[jsx(Box,{sx:{width:180,height:180,borderRadius:"50%",background:r,position:"relative"},children:jsx(Box,{sx:{position:"absolute",inset:30,bgcolor:"background.paper",borderRadius:"50%"}})}),jsx(Stack,{spacing:1,sx:{minWidth:180},children:e.map((l,n)=>jsxs(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsx(Box,{sx:{width:10,height:10,borderRadius:"50%",bgcolor:bt[n%bt.length]}}),jsx(Typography,{variant:"caption",sx:{flex:1},children:l.name}),jsxs(Typography,{variant:"caption",sx:{fontWeight:700},children:[l.percent.toFixed(0),"%"]})]},l.name))})]})},ao=({title:e,subtitle:o,children:t})=>jsxs(Paper,{variant:"outlined",sx:{p:2,borderRadius:2},children:[jsx(Typography,{variant:"subtitle1",fontWeight:700,children:e}),jsx(Typography,{variant:"body2",color:"text.secondary",sx:{mb:2},children:o}),t]}),Xo=({billableByPrimary:e,efficiencyBySecondary:o,statusDistribution:t})=>jsxs(Box,{sx:{display:"grid",gap:1.5,gridTemplateColumns:{xs:"1fr",lg:"1.2fr 1.2fr 1fr"}},children:[jsx(ao,{title:"Billable by Dimension",subtitle:"Top values by billable hours",children:jsx(Ua,{data:e})}),jsx(ao,{title:"Efficiency by Person",subtitle:"Lowest efficiency first",children:jsx(Ka,{data:o})}),jsx(ao,{title:"Status Distribution",subtitle:"Record ratio by status",children:jsx(Ya,{data:t})})]});var Zo=({open:e,onClose:o,model:t,tableContent:r})=>jsx(Dialog,{open:e,onClose:o,fullScreen:true,children:jsxs(Box,{sx:{height:"100%",display:"flex",flexDirection:"column",bgcolor:"background.default"},children:[jsx(Box,{sx:{p:2,borderBottom:1,borderColor:"divider"},children:jsxs(Stack,{direction:"row",alignItems:"center",justifyContent:"space-between",spacing:2,children:[jsxs(Stack,{direction:"row",spacing:1.5,alignItems:"center",children:[jsx(Typography,{variant:"h5",fontWeight:800,children:t.title}),jsx(Chip,{size:"small",label:`${t.kpis.totalRecords} records`})]}),jsx(IconButton,{onClick:o,children:jsx(Qa,{})})]})}),jsxs(Box,{sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,overflow:"auto",minHeight:0},children:[jsx(qo,{kpis:t.kpis}),jsx(Xo,{billableByPrimary:t.charts.billableByPrimary,efficiencyBySecondary:t.charts.efficiencyBySecondary,statusDistribution:t.charts.statusDistribution}),r]})]})});var Ie={primaryDimension:["Client","Customer","Category","Project"],secondaryDimension:["Person","Consultant","Owner","Name"],status:["Status","state"],date:["Date","WorkDate","CreatedAt"],description:["Description","Task","Title","Memo"],reportHours:["Report_Hour","Report Hours","Hours","ReportHours"],billableHours:["Billable_Hour","Billable Hours","BillableHours"],amount:["Amount","Billable_Amount","Total_Amount","Value"]},er=5,Qo=e=>e.toLowerCase().replace(/[\s_-]/g,""),ke=(e,o,t,r)=>{if(o)return o;if(e.length===0)return r;let l=Object.keys(e[0]),n=new Map(l.map(i=>[Qo(i),i]));for(let i of t){let a=n.get(Qo(i));if(a)return a}return l[0]||r},xe=e=>{if(typeof e=="number")return Number.isFinite(e)?e:0;if(typeof e=="string"){let o=Number(e.replace(/,/g,"").trim());return Number.isFinite(o)?o:0}return 0},Ce=(e,o)=>e==null||e===""?o:String(e),tr=(e,o,t,r)=>{let l=new Map;return e.forEach(n=>{let i=Ce(n[o],"Unassigned");l.set(i,(l.get(i)||0)+xe(n[t]));}),Array.from(l.entries()).map(([n,i])=>({name:n,value:i})).sort((n,i)=>i.value-n.value).slice(0,r)},or=(e,o,t,r,l)=>{let n=new Map;return e.forEach(i=>{let a=Ce(i[o],"Unassigned"),d=n.get(a)||{report:0,billable:0};d.report+=xe(i[t]),d.billable+=xe(i[r]),n.set(a,d);}),Array.from(n.entries()).map(([i,a])=>({name:i,value:a.report>0?a.billable/a.report*100:0})).sort((i,a)=>i.value-a.value).slice(0,l)},nr=(e,o)=>{let t=e.length;if(t===0)return [];let r=new Map;return e.forEach(l=>{let n=Ce(l[o],"Unassigned");r.set(n,(r.get(n)||0)+1);}),Array.from(r.entries()).map(([l,n])=>({name:l,value:n,percent:n/t*100}))},en=({rows:e,config:o})=>{let t=useMemo(()=>{let d=o?.fieldMapping;return {primaryDimension:ke(e,d?.primaryDimension,Ie.primaryDimension,"Category"),secondaryDimension:ke(e,d?.secondaryDimension,Ie.secondaryDimension,"Owner"),status:ke(e,d?.status,Ie.status,"Status"),date:ke(e,d?.date,Ie.date,"Date"),description:ke(e,d?.description,Ie.description,"Description"),reportHours:ke(e,d?.reportHours,Ie.reportHours,"ReportHours"),billableHours:ke(e,d?.billableHours,Ie.billableHours,"BillableHours"),amount:ke(e,d?.amount,Ie.amount,"Amount")}},[e,o?.fieldMapping]),r=useMemo(()=>e.map((d,T)=>{let k=xe(d[t.reportHours]),w=xe(d[t.billableHours]),C=xe(d[t.amount]),E=k>0?w/k*100:0;return {id:`graph-row-${T}`,Date:Ce(d[t.date],""),Primary:Ce(d[t.primaryDimension],"Unassigned"),Secondary:Ce(d[t.secondaryDimension],"Unassigned"),Description:Ce(d[t.description],""),ReportHours:k,BillableHours:w,Amount:C,Efficiency:E,Status:Ce(d[t.status],"Unassigned")}}),[e,t]),l=useMemo(()=>{let d=r.length,T=r.reduce((m,f)=>m+xe(f.ReportHours),0),k=r.reduce((m,f)=>m+xe(f.BillableHours),0),w=r.reduce((m,f)=>m+xe(f.Amount),0),C=T>0?k/T*100:0,E=o?.statusFlagValues||["flag","flagged","warning","risk"],M=r.filter(m=>E.includes(Ce(m.Status,"").toLowerCase())).length;return {totalRecords:d,totalReportHours:T,totalBillableHours:k,efficiency:C,totalAmount:w,flaggedCount:M}},[r,o?.statusFlagValues]),n=o?.topN||er,i=useMemo(()=>({billableByPrimary:tr(r,"Primary","BillableHours",n),efficiencyBySecondary:or(r,"Secondary","ReportHours","BillableHours",n),statusDistribution:nr(r,"Status")}),[r,n]),a=useMemo(()=>({title:o?.title||"Graphic Report",kpis:l,charts:i,table:{columns:[{id:"Date",label:t.date},{id:"Primary",label:t.primaryDimension},{id:"Secondary",label:t.secondaryDimension},{id:"Description",label:t.description},{id:"ReportHours",label:"Report Hours",align:"right"},{id:"BillableHours",label:"Billable Hours",align:"right"},{id:"Amount",label:"Amount",align:"right"},{id:"Efficiency",label:"Efficiency",align:"right"},{id:"Status",label:t.status}],rows:r}}),[i,o?.title,t,l,r]);return {fieldMapping:t,model:a}};var vt=({variants:e,currentVariantId:o,onLoad:t,onSave:r,onDelete:l,onSetDefault:n})=>{let i="0.75rem",[a,d]=useState(false),[T,k]=useState(""),[w,C]=useState(false),[E,M]=useState(false),m=e.find(y=>y.id===o);return jsxs(Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsx(Typography,{variant:"body2",sx:{fontWeight:"bold",minWidth:"fit-content",fontSize:i},children:"Variant:"}),jsx(Autocomplete,{size:"small",sx:{width:200,"& .MuiInputBase-root":{fontSize:i},"& .MuiInputBase-input":{fontSize:i},"& .MuiAutocomplete-noOptions":{fontSize:i}},noOptionsText:jsx(Typography,{sx:{fontSize:i},children:"No options"}),options:e,getOptionLabel:y=>y.name+(y.isDefault?" (Default)":""),value:m||null,onChange:(y,g)=>{g&&t(g);},renderInput:y=>jsx(TextField,{...y,variant:"outlined",size:"small",InputProps:{...y.InputProps,sx:{fontSize:i}},placeholder:"Select Variant"}),renderOption:(y,g)=>jsx("li",{...y,children:jsxs(Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsx(Typography,{sx:{flex:1,fontSize:i},children:g.name}),g.isDefault&&jsx(pr,{fontSize:"small",color:"action"})]})})}),jsx(Tooltip,{title:"Save View",children:jsx(IconButton,{onClick:()=>{k(m?.name||"New Variant"),C(m?.isDefault||false),M(m?.isPublic||false),d(true);},size:"small",color:"primary",children:jsx(vn,{})})}),jsxs(Dialog,{open:a,onClose:()=>d(false),children:[jsx(DialogTitle,{children:"Save View"}),jsxs(DialogContent,{children:[jsx(TextField,{autoFocus:true,margin:"dense",label:"View Name",fullWidth:true,variant:"outlined",value:T,onChange:y=>k(y.target.value)}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:w,onChange:y=>C(y.target.checked)}),label:"Set as Default"}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:E,onChange:y=>M(y.target.checked)}),label:"Public (All Users)"})]}),jsxs(DialogActions,{children:[jsx(Button,{onClick:()=>d(false),children:"Cancel"}),jsx(Button,{onClick:()=>{r({name:T,isDefault:w,isPublic:E,description:""}),d(false);},variant:"contained",children:"Save"})]})]})]})};var fr="http://127.0.0.1:8515",sn=({appId:e,tableKey:o="default",currentFilters:t,currentLayoutId:r,layoutRefs:l,onLoad:n,serviceUrl:i=fr,onError:a,onSuccess:d,currentVariantId:T,onVariantChange:k})=>{let[w,C]=useState([]),[E,M]=useState(""),m=T!==void 0?T:E,f=c=>{T===void 0&&M(c),k&&k(c);},S=useCallback(async()=>{if(!e)return [];try{let c=await fetch(`${i}/api/variants?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!c.ok)throw new Error("Failed to fetch variants");let u=await c.json();C(u);let b=u.find(x=>x.isDefault);return b&&!m&&(f(b.id),n(b)),u}catch(c){return console.error("Error fetching variants",c),a&&a("Failed to load variants"),[]}},[e,o,i,a,m,n]);return useEffect(()=>{S();},[e,o]),jsx(vt,{variants:w,currentVariantId:m,onLoad:c=>{f(c.id),n(c);},onSave:async c=>{try{let u=w.find(L=>L.name===c.name),b=u?u.id:Date.now().toString(),x=[];if(u&&(Array.isArray(u.filters)?x=[...u.filters]:u.filters&&(x=[{scope:"default",filters:u.filters}])),c.scope==="Search"||c.scope==="Both"){let L=(Array.isArray(t),t);if(L)if(Array.isArray(L)&&L.length>0&&L[0].scope)L.forEach(V=>{let A=x.findIndex(N=>N.scope===V.scope);A>=0?x[A]=V:x.push(V);});else {let V={scope:o,filters:L},A=x.findIndex(N=>N.scope===o);A>=0?x[A]=V:x.push(V);}}let s=u?.layout||{},R=[];if(u&&Array.isArray(u.layoutRefs)&&(R=[...u.layoutRefs]),c.scope==="Layout"||c.scope==="Both")if(l&&l.length>0)l.forEach(L=>{let V=R.findIndex(A=>A.tableKey===L.tableKey);V>=0?R[V]=L:R.push(L);});else {let L={tableKey:o,layoutId:r||null},V=R.findIndex(A=>A.tableKey===o);V>=0?R[V]=L:R.push(L);}let v={appId:e,tableKey:o,...c,id:b,createdAt:new Date().toISOString(),filters:x,layout:s,layoutRefs:R};if(!(await fetch(`${i}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(v)})).ok)throw new Error("Failed to save variant");d&&d("Variant saved successfully"),await S(),f(b),n(v);}catch(u){console.error("Error saving variant",u),a&&a("Failed to save variant");}},onDelete:async c=>{try{if(!(await fetch(`${i}/api/variants/${c}`,{method:"DELETE"})).ok)throw new Error("Failed to delete variant");m===c&&f(""),S(),d&&d("Variant deleted successfully");}catch(u){console.error("Error deleting variant",u),a&&a("Failed to delete variant");}},onSetDefault:async c=>{try{let u=w.find(s=>s.id===c);if(!u)return;let b={appId:e,tableKey:o,...u,isDefault:!0};if(!(await fetch(`${i}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)})).ok)throw new Error("Failed to set default variant");await S(),d&&d("Default variant updated");}catch(u){console.error("Error setting default variant",u),a&&a("Failed to update default variant");}}})};Ee.extend(Pr);var Er=[null,null],uo="0.75rem",Lr=styled(PickersDay,{shouldForwardProp:e=>e!=="isInRange"&&e!=="isStart"&&e!=="isEnd"&&e!=="isHovered"})(({theme:e,isInRange:o,isStart:t,isEnd:r,isHovered:l})=>({...o&&{borderRadius:0,backgroundColor:e.palette.primary.light,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.main}},...l&&!o&&!t&&!r&&{borderRadius:0,backgroundColor:e.palette.action.hover,border:`1px dashed ${e.palette.primary.main}`},...t&&{borderRadius:"50% 0 0 50%",backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.dark}},...r&&{borderRadius:"0 50% 50% 0",backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.dark}},...t&&r&&{borderRadius:"50%"}})),un=({label:e="Date Range",value:o=Er,onChange:t})=>{let[r,l]=useState(null),[n,i]=useState(o),[a,d]=useState("start"),[T,k]=useState(null),[w,C]=useState(o[0]||Ee()),E=So__default.useRef(o);useEffect(()=>{let[b,x]=o,[s,R]=E.current,v=V=>V&&typeof V.isSame=="function",z=!(b===null&&s===null||v(b)&&v(s)&&b.isSame(s,"day")),L=!(x===null&&R===null||v(x)&&v(R)&&x.isSame(R,"day"));(z||L)&&(i(o),o[0]&&v(o[0])&&C(o[0])),E.current=o;},[o]);let M=b=>{l(b.currentTarget);},m=()=>{l(null),d("start"),k(null);},f=!!r,S=b=>{if(!b)return;let x=[...n];if(a==="start")x=[b,null],d("end");else {let s=x[0];s&&b.isBefore(s)?(x=[b,null],d("end")):(x=[s,b],d("start"));}i(x);},y=b=>{let x=Ee(),s=[null,null];switch(b){case "today":s=[x,x];break;case "week":s=[x.startOf("week"),x.endOf("week")];break;case "month":s=[x.startOf("month"),x.endOf("month")];break}i(s),d("start"),C(x);},g=()=>{i([null,null]),d("start"),C(Ee());},p=()=>{t&&t(n),m();},I=()=>{i(o),d("start"),m();},c=useCallback(b=>{let{day:x,...s}=b,[R,v]=n,z=R?x.isSame(R,"day"):false,L=v?x.isSame(v,"day"):false,V=R&&v?x.isBetween(R,v,"day","()"):false,A=false;return a==="end"&&R&&!v&&T&&x.isAfter(R,"day")&&x.isBefore(T.add(1,"day"),"day")&&(A=true),jsx(Lr,{...s,day:x,disableMargin:true,isStart:z,isEnd:L,isInRange:V||A,onMouseEnter:()=>k(x)})},[n,a,T]),u=b=>b?b.format("YYYY-MM-DD"):"";return jsxs(Box,{children:[jsx(TextField,{label:e,value:n[0]?`${u(n[0])} - ${u(n[1])}`:"",onClick:M,fullWidth:true,size:"small",InputLabelProps:{sx:{fontSize:uo}},InputProps:{readOnly:true,sx:{fontSize:uo,"& .MuiOutlinedInput-input":{fontSize:uo},paddingRight:"4px"},endAdornment:jsxs(InputAdornment,{position:"end",sx:{ml:0},children:[(n[0]||n[1])&&jsx(IconButton,{size:"small",onClick:b=>{b.stopPropagation(),g();},edge:"end",sx:{mr:.5,padding:"2px"},children:jsx(Rr,{sx:{fontSize:"1rem"}})}),jsx(IconButton,{size:"small",edge:"end",onClick:M,sx:{padding:"2px"},children:jsx(Mr,{sx:{fontSize:"1rem"},color:"action"})})]})}}),jsxs(Popover,{open:f,anchorEl:r,onClose:m,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},slotProps:{paper:{sx:{display:"flex",flexDirection:"column",p:0,minWidth:320}}},children:[jsx(Box,{sx:{p:2,bgcolor:"background.default",borderBottom:1,borderColor:"divider"},children:jsxs(Stack,{direction:"row",alignItems:"center",spacing:2,justifyContent:"space-between",children:[jsxs(Box,{sx:{p:1,border:1,borderColor:a==="start"?"primary.main":"divider",borderRadius:1,bgcolor:a==="start"?"action.hover":"transparent",flex:1,cursor:"pointer"},onClick:()=>d("start"),children:[jsx(Typography,{variant:"caption",color:"text.secondary",display:"block",children:"Start Date"}),jsx(Typography,{variant:"body2",fontWeight:500,children:n[0]?n[0].format("MMM DD, YYYY"):"Select..."})]}),jsx(Dr,{color:"action",fontSize:"small"}),jsxs(Box,{sx:{p:1,border:1,borderColor:a==="end"?"primary.main":"divider",borderRadius:1,bgcolor:a==="end"?"action.hover":"transparent",flex:1,cursor:"pointer"},onClick:()=>{n[0]&&d("end");},children:[jsx(Typography,{variant:"caption",color:"text.secondary",display:"block",children:"End Date"}),jsx(Typography,{variant:"body2",fontWeight:500,children:n[1]?n[1].format("MMM DD, YYYY"):"Select..."})]})]})}),jsx(Box,{sx:{p:2,pb:0},children:jsxs(Stack,{direction:"row",spacing:1,justifyContent:"center",children:[jsx(Chip,{label:"Today",onClick:()=>y("today"),clickable:true,size:"small",variant:"outlined"}),jsx(Chip,{label:"This Week",onClick:()=>y("week"),clickable:true,size:"small",variant:"outlined"}),jsx(Chip,{label:"This Month",onClick:()=>y("month"),clickable:true,size:"small",variant:"outlined"})]})}),jsx(DateCalendar,{value:null,referenceDate:w,onMonthChange:C,onYearChange:C,onChange:S,slots:{day:c},views:["day"],showDaysOutsideCurrentMonth:true,sx:{m:0}}),jsx(Divider,{}),jsxs(Stack,{direction:"row",justifyContent:"flex-end",spacing:1,sx:{p:2},children:[jsx(Button,{size:"small",onClick:I,color:"inherit",children:"Cancel"}),jsx(Button,{size:"small",variant:"contained",onClick:p,children:"Done"})]})]})]})};var It={equals:"=",contains:"\u2287",notContains:"\u2285",wildcard:"*","=":"=","!=":"!=",">":">","<":"<",">=":"\u2265","<=":"\u2264",between:"\u2194"},$r={equals:"Equals",contains:"Contains",notContains:"Does Not Contain",wildcard:"Wildcard Search","=":"Equals","!=":"Not Equals",">":"Greater Than","<":"Less Than",">=":"Greater Than or Equal","<=":"Less Than or Equal",between:"Between"},_r=["equals","contains","notContains","wildcard"],gn=["=","!=",">","<",">=","<=","between"],Z="0.75rem",jr=({field:e,value:o,onChange:t})=>{let[r,l]=useState(null),[n,i]=useState(null),[a,d]=useState(""),[T,k]=useState(""),[w,C]=useState(false),[E,M]=useState(""),[m,f]=useState("");useEffect(()=>{let s=setTimeout(()=>{f(E);},1e3);return ()=>clearTimeout(s)},[E]);let S=o?.operator||(e.type==="number"?"=":"equals"),y=o?.value,g=s=>$r[s]||s,p=s=>{l(s.currentTarget);},I=s=>{t({...o,operator:s,value:y}),l(null);},c={size:"small",fullWidth:true,variant:"outlined",InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}},SelectProps:{MenuProps:{PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,paddingTop:"4px",paddingBottom:"4px",minHeight:"auto"}}}}}},u=e.type||"text";if(u==="date"){let R=(v=>{if(!v)return [null,null];if(Array.isArray(v)&&v.length===2){let z=v[0]?Ee.isDayjs(v[0])?v[0]:Ee(v[0]):null,L=v[1]?Ee.isDayjs(v[1])?v[1]:Ee(v[1]):null;return [z,L]}return Ee.isDayjs(v)||typeof v=="string"?[Ee.isDayjs(v)?v:Ee(v),null]:[null,null]})(y);return jsx(un,{label:e.label,value:R,onChange:v=>t({value:v,operator:"between"})})}if(u==="number"&&S==="between"){let s=()=>{t({value:[a,T],operator:"between"}),i(null);},R=Array.isArray(y)?`${y[0]||""} - ${y[1]||""}`:"";return jsxs(Fragment,{children:[jsx(TextField,{...c,label:e.label,value:R,placeholder:"Min - Max",InputProps:{...c.InputProps,startAdornment:jsx(InputAdornment,{position:"start",children:jsx(Tooltip,{title:g("between"),children:jsx(IconButton,{size:"small",onClick:p,sx:{width:24,height:24,fontSize:Z},children:It.between})})}),readOnly:true},onClick:v=>i(v.currentTarget)}),jsx(Menu,{anchorEl:r,open:!!r,onClose:()=>l(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,minHeight:"auto",py:.5}}},children:gn.map(v=>jsxs(MenuItem,{selected:v===S,onClick:()=>I(v),children:[jsx(Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:It[v]}),jsx(ListItemText,{primary:g(v),primaryTypographyProps:{fontSize:Z}})]},v))}),jsx(Popover,{open:!!n,anchorEl:n,onClose:()=>i(null),anchorOrigin:{vertical:"bottom",horizontal:"left"},children:jsxs(Box,{sx:{p:2,display:"flex",gap:1,alignItems:"center"},children:[jsx(TextField,{size:"small",label:"Min",type:"number",value:a,onChange:v=>d(v.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}}}),jsx(Wr,{color:"action"}),jsx(TextField,{size:"small",label:"Max",type:"number",value:T,onChange:v=>k(v.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}}}),jsx(Button,{variant:"contained",size:"small",onClick:s,children:"OK"})]})})]})}if(u==="select")return jsxs(TextField,{...c,select:true,label:e.label,value:y||"",onChange:s=>t({...o,value:s.target.value,operator:"equals"}),children:[jsx(MenuItem,{value:"",children:jsx("em",{children:"None"})}),e.options?.map(s=>jsx(MenuItem,{value:s.value,children:s.label},s.value))]});if(u==="multi-select"){let s=Array.isArray(y)?y:[],R=e.options?.filter(v=>v.label.toLowerCase().includes(m.toLowerCase()))||[];return jsxs(TextField,{...c,select:true,label:e.label,value:s,onChange:v=>t({...o,value:v.target.value,operator:"anyOf"}),SelectProps:{...c.SelectProps,multiple:true,onClose:()=>{M(""),f("");},renderValue:v=>{if(!Array.isArray(v)||v.length===0)return jsx("em",{children:"None"});let z=V=>e.options?.find(A=>A.value===V)?.label||V,L=v.map(z);return L.length>2?`${L.slice(0,2).join(", ")} +${L.length-2}`:L.join(", ")}},children:[jsx(ListSubheader,{children:jsx(TextField,{size:"small",autoFocus:true,placeholder:"Search...",fullWidth:true,InputProps:{startAdornment:jsx(InputAdornment,{position:"start",children:jsx(mn,{fontSize:"small"})}),sx:{fontSize:Z}},value:E,onChange:v=>M(v.target.value),onKeyDown:v=>{v.key!=="Escape"&&v.stopPropagation();},onClick:v=>v.stopPropagation()})}),R.length>0?R.map(v=>jsxs(MenuItem,{value:v.value,children:[jsx(Checkbox,{checked:s.indexOf(v.value)>-1,size:"small"}),jsx(ListItemText,{primary:v.label,primaryTypographyProps:{fontSize:Z}})]},v.value)):jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"No options found",primaryTypographyProps:{fontSize:Z}})})]})}let b=u==="number"?gn:_r,x=w||y!==void 0&&y!==""&&y!==null||!!r;return jsxs(Fragment,{children:[jsx(TextField,{...c,label:e.label,sx:{minWidth:"120px"},value:y||"",type:u==="number"?"number":"text",onChange:s=>t({...o,value:s.target.value,operator:S}),onFocus:()=>C(true),onBlur:()=>C(false),InputProps:{...c.InputProps,startAdornment:x?jsx(InputAdornment,{position:"start",children:jsx(Tooltip,{title:g(S),children:jsx(IconButton,{size:"small",onClick:p,onMouseDown:s=>s.preventDefault(),sx:{width:24,height:24,fontSize:Z,fontWeight:"bold",color:"primary.main",bgcolor:"action.hover"},children:It[S]})})}):null,endAdornment:e.hasSearchIcon?jsx(InputAdornment,{position:"end",children:jsx(mn,{color:"action"})}):void 0}}),jsx(Menu,{anchorEl:r,open:!!r,onClose:()=>l(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,minHeight:"auto",py:.5}}},children:b.map(s=>jsxs(MenuItem,{selected:s===S,onClick:()=>I(s),children:[jsx(Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:It[s]}),jsx(ListItemText,{primary:g(s),primaryTypographyProps:{fontSize:Z}})]},s))})]})},Xe=({fields:e,filters:o,onFilterChange:t,variants:r=[],currentVariantId:l,onVariantLoad:n,onVariantSave:i,onVariantDelete:a,onVariantSetDefault:d,onSearch:T,loading:k=false,appId:w,tableKey:C,currentLayout:E,currentLayoutId:M,layoutRefs:m,variantService:f})=>{let[S,y]=useState(true),[g,p]=useState(null),[I,c]=useState(e.filter(s=>!s.hidden).map(s=>s.id)),u=(s,R)=>{t({...o,[s]:R});},b=s=>{I.includes(s)?c(I.filter(R=>R!==s)):c([...I,s]);};return jsxs(Paper,{sx:{mb:0,display:"flex",flexDirection:"column",overflow:"visible",position:"relative"},children:[jsxs(Box,{sx:{p:2,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[w?jsx(sn,{appId:w,tableKey:C,currentFilters:{values:o,visibleFields:I},currentLayout:E,currentLayoutId:M,layoutRefs:m,onLoad:s=>{if(!s.filters)return;let R=null;if(Array.isArray(s.filters)){let v=C||"default",z=s.filters.find(L=>L.scope===v);R=z?z.filters:null;}else R=s.filters;R&&(R.values||R.visibleFields?(R.visibleFields&&Array.isArray(R.visibleFields)&&c(R.visibleFields),R.values&&t(R.values)):t(R)),n&&n(s);},variantService:f,currentVariantId:l}):jsx(vt,{variants:r,currentVariantId:l,onLoad:n,onSave:s=>{i&&i({...s,filters:{values:o,visibleFields:I}});},onDelete:a,onSetDefault:d}),jsxs(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsx(Tooltip,{title:"Add Filters",children:jsx(Button,{onClick:s=>p(s.currentTarget),size:"small",color:"primary",startIcon:jsx(zr,{fontSize:"small"}),sx:{textTransform:"none",fontSize:Z},children:"Adapt Filters"})}),jsx(Button,{variant:"contained",size:"small",onClick:T,disabled:k,sx:{minWidth:"40px",fontWeight:"bold"},children:k?"...":"Go"}),jsxs(Menu,{anchorEl:g,open:!!g,onClose:()=>p(null),slotProps:{paper:{style:{maxHeight:400,width:"25ch"}}},children:[jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"Visible Filters"})}),jsx(Divider,{}),e.map(s=>jsxs(MenuItem,{onClick:()=>b(s.id),children:[jsx(Checkbox,{checked:I.includes(s.id),size:"small"}),jsx(ListItemText,{primary:s.label})]},s.id))]})]})]}),jsx(Collapse,{in:S,children:jsx(Box,{sx:{px:2,pb:2},children:jsx(Grid,{container:true,spacing:2,columns:{xs:2,sm:3,md:4,lg:6},children:e.filter(s=>I.includes(s.id)).map(s=>jsx(Grid,{size:1,children:jsx(jr,{field:s,value:o[s.id]||{value:"",operator:s.type==="number"?"=":"equals"},onChange:R=>u(s.id,R)})},s.id))})})}),jsx(Box,{sx:{position:"absolute",bottom:0,left:"50%",transform:"translate(-50%, 50%)",zIndex:10},children:jsx(IconButton,{size:"small",onClick:()=>y(!S),sx:{bgcolor:"background.paper",boxShadow:2,border:"1px solid",borderColor:"divider",width:20,height:20,minHeight:0,p:0,"&:hover":{bgcolor:"background.paper"}},children:S?jsx(Or,{sx:{fontSize:16},color:"action"}):jsx(Ra,{sx:{fontSize:16},color:"action"})})})]})};var Sn=({layouts:e,currentLayoutId:o,onLoad:t,onSave:r,onDelete:l,onSetDefault:n})=>{let[i,a]=useState(null),[d,T]=useState(false),[k,w]=useState(""),[C,E]=useState(""),[M,m]=useState({isDefault:false,isPublic:false}),f=e.find(c=>c.id===o),S=c=>{a(c.currentTarget);},y=()=>{a(null);},g=c=>{t(c),y();},p=()=>{w(""),E(""),m({isDefault:false,isPublic:false}),T(true),y();},I=()=>{k.trim()&&(r({name:k,description:C,...M}),T(false));};return jsxs(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsx(Tooltip,{title:"Save Layout",children:jsx(IconButton,{onClick:p,color:"primary",size:"small",children:jsx(vn,{})})}),jsx(Tooltip,{title:"Layout Options",children:jsx(IconButton,{onClick:S,color:f?"primary":"default",children:jsx(ni,{})})}),jsxs(Menu,{anchorEl:i,open:!!i,onClose:y,PaperProps:{sx:{width:320,maxHeight:400}},children:[jsx(MenuItem,{disabled:true,children:jsx(Typography,{variant:"caption",children:"Select Layout"})}),jsxs(MenuItem,{onClick:p,children:[jsx(ListItemIcon,{children:jsx(vn,{fontSize:"small"})}),jsx(ListItemText,{children:"Save Current Layout..."})]}),jsx(Divider,{}),e.length===0&&jsx(MenuItem,{disabled:true,children:jsx(Typography,{variant:"body2",color:"text.secondary",children:"No saved layouts"})}),e.map((c,u)=>jsx(MenuItem,{onClick:()=>g(c),selected:c.id===o,children:jsxs(Box,{sx:{display:"flex",alignItems:"center",width:"100%",justifyContent:"space-between"},children:[jsxs(Box,{sx:{display:"flex",flexDirection:"column",overflow:"hidden",mr:1},children:[jsx(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:jsx(Typography,{variant:"body2",fontWeight:c.id===o?"bold":"normal",noWrap:true,children:c.name})}),c.description&&jsx(Typography,{variant:"caption",color:"text.secondary",noWrap:true,children:c.description})]}),jsxs(Box,{sx:{display:"flex",alignItems:"center"},onClick:b=>b.stopPropagation(),children:[jsx(Tooltip,{title:c.isDefault?"Remove Default":"Set as Default",children:jsx(IconButton,{size:"small",onClick:b=>{b.stopPropagation(),n(c.id);},children:c.isDefault?jsx(pr,{fontSize:"small",color:"warning"}):jsx(oi,{fontSize:"small"})})}),jsx(Tooltip,{title:"Delete",children:jsx(IconButton,{size:"small",color:"error",onClick:b=>{b.stopPropagation(),l(c.id);},children:jsx(ei,{fontSize:"small"})})})]})]})},c.id||u))]}),jsxs(Dialog,{open:d,onClose:()=>T(false),maxWidth:"xs",fullWidth:true,children:[jsx(DialogTitle,{children:"Save Layout"}),jsx(DialogContent,{children:jsxs(Box,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[jsx(TextField,{label:"Layout Name",value:k,onChange:c=>w(c.target.value),fullWidth:true,autoFocus:true,size:"small",helperText:"e.g., 'Compact View'"}),e.some(c=>c.name===k)&&jsx(Typography,{variant:"caption",color:"warning.main",sx:{ml:1},children:"Warning: Existing layout will be overwritten"}),jsx(TextField,{label:"Description",value:C,onChange:c=>E(c.target.value),fullWidth:true,size:"small"}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:M.isDefault,onChange:c=>m({...M,isDefault:c.target.checked})}),label:"Use as Default Layout"}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:M.isPublic,onChange:c=>m({...M,isPublic:c.target.checked})}),label:"Public (Visible to all users)"})]})}),jsxs(DialogActions,{children:[jsx(Button,{onClick:()=>T(false),children:"Cancel"}),jsx(Button,{onClick:I,variant:"contained",disabled:!k,children:"Save"})]})]})]})};var ai="http://127.0.0.1:8515",wn=({appId:e,tableKey:o="default",currentLayoutData:t,onLayoutLoad:r,targetLayoutId:l,activeLayoutId:n,serviceUrl:i=ai,onError:a,onSuccess:d})=>{let[T,k]=useState([]),[w,C]=useState(""),E=`orbcafe.layouts.${e}.${o}`,M=u=>({id:u.layoutId,name:u.name,description:u.description??"",isDefault:!!u.isDefault,isPublic:!!u.isPublic,createdAt:u.createdAt??new Date().toISOString(),layoutData:u.layout??{}}),m=u=>({appId:e,tableKey:o,layoutId:u.id,name:u.name,description:u.description??"",isDefault:!!u.isDefault,isPublic:!!u.isPublic,createdAt:u.createdAt,layout:u.layoutData}),f=useCallback(()=>{try{let u=localStorage.getItem(E);if(!u)return [];let b=JSON.parse(u);return Array.isArray(b)?b:[]}catch{return []}},[E]),S=useCallback(u=>{try{localStorage.setItem(E,JSON.stringify(u));}catch{}},[E]);useEffect(()=>{n!==void 0&&C(n);},[n]),useEffect(()=>{if(l&&T.length>0){let u=T.find(b=>b.id===l);u&&(C(u.id),r(u));}},[l,T,r]);let y=useCallback(async()=>{if(e)try{let u=await fetch(`${i}/api/layouts?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!u.ok)throw new Error("Failed to fetch layouts");let x=(await u.json()).map(M);k(x);let s=x.find(R=>R.isDefault);s&&!w&&!l&&(C(s.id),r(s));}catch(u){console.error("Error fetching layouts",u);let b=f();k(b);let x=b.find(s=>s.isDefault);x&&!w&&!l&&(C(x.id),r(x)),a&&a("Failed to load layouts from backend, fallback to local storage");}},[e,o,i,a,w,r,l,f]);return useEffect(()=>{y();},[e,o]),jsx(Sn,{layouts:T,currentLayoutId:w,onLoad:u=>{C(u.id),r(u);},onSave:async u=>{let b=T.find(R=>R.name===u.name),x=b?b.id:Date.now().toString(),s={id:x,...u,createdAt:new Date().toISOString(),layoutData:t,isDefault:u.isDefault??false,isPublic:u.isPublic??false};try{if(!(await fetch(`${i}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(m(s))})).ok)throw new Error("Failed to save layout");d&&d("Layout saved successfully"),await y(),C(x),r(s);}catch(R){console.error("Error saving layout",R);let z=T.some(L=>L.id===x)?T.map(L=>L.id===x?s:L):[...T,s];k(z),S(z),C(x),r(s),d&&d("Layout saved to local storage"),a&&a("Backend unavailable, saved to local storage");}},onDelete:async u=>{try{if(!(await fetch(`${i}/api/layouts/${encodeURIComponent(u)}`,{method:"DELETE"})).ok)throw new Error("Failed to delete layout");w===u&&C(""),d&&d("Layout deleted successfully"),await y();}catch(b){console.error("Error deleting layout",b);let x=T.filter(s=>s.id!==u);k(x),S(x),w===u&&C(""),d&&d("Layout deleted from local storage"),a&&a("Backend unavailable, deleted from local storage");}},onSetDefault:async u=>{try{let b=T.find(s=>s.id===u);if(!b)return;if(!(await fetch(`${i}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(m({...b,isDefault:!0}))})).ok)throw new Error("Failed to set default layout");d&&d("Default layout set"),await y();}catch(b){console.error("Error setting default",b);let x=T.map(s=>({...s,isDefault:s.id===u}));k(x),S(x),d&&d("Default layout set in local storage"),a&&a("Backend unavailable, default saved to local storage");}}})};function kn(e,o,t){return o[t]<e[t]?-1:o[t]>e[t]?1:0}function ii(e,o){return e==="desc"?(t,r)=>kn(t,r,o):(t,r)=>-kn(t,r,o)}function li(e,o){let t=e.map((r,l)=>[r,l]);return t.sort((r,l)=>{let n=o(r[0],l[0]);return n!==0?n:r[1]-l[1]}),t.map(r=>r[0])}var Mn=e=>{let o=useCallback(h=>{let B=String(h?.label??h?.id??"").length*9+64,ee=typeof h?.minWidth=="number"?h.minWidth:0;return Math.max(100,ee,B)},[]),[t,r]=useState(""),[l,n]=useState(e.order||"asc"),[i,a]=useState(e.orderBy||""),[d,T]=useState(e.page||0),[k,w]=useState(e.rowsPerPage||20),[C,E]=useState(e.selected||[]),[M,m]=useState(e.columns?e.columns.map(h=>h.id):[]),[f,S]=useState(e.showSummary||false),[y,g]=useState([]),[p,I]=useState(new Set),[c,u]=useState(()=>{let h={};return (e.columns||[]).forEach(D=>{h[D.id]=o(D);}),h}),[b,x]=useState(null),[s,R]=useState(null),[v,z]=useState(null),[L,V]=useState(null),[A,N]=useState(false),[te,Oe]=useState("");useEffect(()=>{e.order!==void 0&&n(e.order),e.orderBy!==void 0&&a(e.orderBy);},[e.order,e.orderBy]),useEffect(()=>{e.selected!==void 0&&E(e.selected);},[e.selected]),useEffect(()=>{e.page!==void 0&&T(e.page);},[e.page]),useEffect(()=>{u(h=>{let D={...h};return (e.columns||[]).forEach(B=>{D[B.id]===void 0&&(D[B.id]=o(B));}),D});},[e.columns,o]);let oe=useMemo(()=>{let h=e.rows||[];return t&&(h=h.filter(D=>Object.keys(D).some(B=>String(D[B]).toLowerCase().includes(t.toLowerCase())))),h},[e.rows,t]),re=useMemo(()=>e.onSortChange||!i?oe:li(oe,ii(l,i)),[oe,l,i,e.onSortChange]),ie=useCallback(h=>{if(y.length===0)return h.map(Y=>({type:"row",data:Y,id:Y[e.rowKey||"id"]}));let D=[...h].sort((Y,q)=>{for(let $ of y){if(Y[$]<q[$])return -1;if(Y[$]>q[$])return 1}return 0}),B=(Y,q=0)=>{if(q>=y.length)return Y;let $=y[q],U={},fe=[];return Y.forEach(se=>{let Be=se[$],ce=`${$}:${Be}`;U[ce]||(U[ce]={key:ce,field:$,value:Be,children:[],count:0,level:q},fe.push(U[ce])),U[ce].children.push(se),U[ce].count++;}),fe.forEach(se=>{se.children&&(se.children=B(se.children,q+1));}),fe},ee=B(D),G=(Y,q="")=>{let $=[];return Y.forEach(U=>{if(U.children){let fe=q?`${q}>${U.key}`:U.key,se=p.has(fe);$.push({type:"group",id:fe,field:U.field,value:U.value,level:U.level,count:U.count,isExpanded:se,childIds:(function Be(ce){let Se=[];return ce.children.forEach($e=>{$e.children?Se=Se.concat(Be($e)):Se.push($e[e.rowKey||"id"]);}),Se})(U)}),se&&($=$.concat(G(U.children,fe)));}else $.push({type:"row",data:U,id:U[e.rowKey||"id"],level:y.length});}),$};return G(ee)},[y,p,e.rowKey]),De=useMemo(()=>ie(re),[re,ie]),nt=useMemo(()=>k>0?De.slice(d*k,d*k+k):De,[De,d,k]),at=h=>{let D=new Set(p);D.has(h)?D.delete(h):D.add(h),I(D);},Ge=h=>{at(h);},Ft=h=>{let D=new Set(p);Array.from(D).forEach(B=>{B.startsWith(h)&&D.delete(B);}),I(D);},Vt=h=>{h||I(new Set);},We=h=>{let D=i===h&&l==="asc",B=i===h&&l==="desc";if(e.onSortChange){D?e.onSortChange(h,"desc"):B?e.onSortChange("","asc"):e.onSortChange(h,"asc");return}D?(n("desc"),a(h)):B?(n("asc"),a("")):(n("asc"),a(h));},rt=(h,D)=>{u(B=>({...B,[h]:D}));},Nt=h=>{if(h.target.checked){let D=oe.map(B=>B[e.rowKey||"id"]);E(D),e.onSelectionChange&&e.onSelectionChange(D);return}E([]),e.onSelectionChange&&e.onSelectionChange([]);},Ht=(h,D)=>{let B=D[e.rowKey||"id"],ee=C.indexOf(B),G=[];ee===-1?G=G.concat(C,B):ee===0?G=G.concat(C.slice(1)):ee===C.length-1?G=G.concat(C.slice(0,-1)):ee>0&&(G=G.concat(C.slice(0,ee),C.slice(ee+1))),E(G),e.onSelectionChange&&e.onSelectionChange(G);},it=h=>{T(h),e.onPageChange&&e.onPageChange(h);},lt=h=>{w(h),T(0),e.onRowsPerPageChange&&e.onRowsPerPageChange(h);},zt=h=>{let D=M.indexOf(h),B=[...M];D===-1?B.push(h):B.splice(D,1),m(B);},st=h=>{let D=y.indexOf(h),B=[...y];D===-1?B.push(h):B.splice(D,1),g(B);},Ot=h=>{e.onLayoutSave&&e.onLayoutSave({visibleColumns:M,order:l,orderBy:i,grouping:y,columnWidths:c});},ct=h=>{h.layout&&(h.layout.visibleColumns&&m(h.layout.visibleColumns),h.layout.order&&n(h.layout.order),h.layout.orderBy&&a(h.layout.orderBy),h.layout.grouping&&g(h.layout.grouping),h.layout.columnWidths&&u(h.layout.columnWidths));},Gt=h=>{let D=h?.layoutData||h?.layout||h||{};D.visibleColumns&&m(D.visibleColumns),D.order&&n(D.order),D.orderBy!==void 0&&a(D.orderBy),D.grouping&&g(D.grouping),D.columnWidths&&u(D.columnWidths),D.showSummary!==void 0&&S(!!D.showSummary),I(new Set),T(0),h?.id&&Oe(h.id);};useEffect(()=>{e.layout&&ct({layout:e.layout});},[e.layout]);let Wt=h=>{h.preventDefault(),V(L===null?{mouseX:h.clientX+2,mouseY:h.clientY-6}:null);},$t=()=>{V(null);},dt=useMemo(()=>{if(!f)return {};let h={};e.columns.forEach(B=>{if(B.numeric){let ee=oe.reduce((G,Y)=>{let q=parseFloat(Y[B.id]);return G+(isNaN(q)?0:q)},0);h[B.id]=ee.toFixed(2);}else h[B.id]="";});let D=e.columns.find(B=>M.includes(B.id));return D&&!D.numeric&&(h[D.id]="Total"),h},[oe,e.columns,f,M]),_t=()=>{if(!e.columns||!oe)return;let h=e.columns.map(Y=>Y.label).join(","),D=oe.map(Y=>e.columns.map(q=>{let $=Y[q.id];return `"${($==null?"":String($)).replace(/"/g,'""')}"`}).join(",")).join(`
2
+ `),B=`data:text/csv;charset=utf-8,${h}
3
+ ${D}`,ee=encodeURI(B),G=document.createElement("a");G.setAttribute("href",ee),G.setAttribute("download",`${e.title||"export"}.csv`),document.body.appendChild(G),G.click(),document.body.removeChild(G);},jt=()=>{N(true);},Ut=()=>{N(false);};return {isMobile:false,columns:e.columns,order:l,orderBy:i,filterText:t,setFilterText:r,visibleColumns:M,setVisibleColumns:m,showSummary:f,setShowSummary:S,summaryColumns:[],grouping:y,setGrouping:g,expandedGroups:p,setExpandedGroups:I,groupAnchorEl:s,setGroupAnchorEl:R,summaryAnchorEl:v,setSummaryAnchorEl:z,columnWidths:c,setColumnWidths:u,anchorEl:b,setAnchorEl:x,contextMenu:L,setContextMenu:V,sensors:void 0,sortedAndFilteredRows:re,visibleRows:nt,summaryRow:dt,page:d,setPage:it,rowsPerPage:k,setRowsPerPage:lt,selected:C,setSelected:E,isAllExpanded:false,handleColumnResize:rt,handleRequestSort:We,handleSelectAllClick:Nt,handleClick:Ht,toggleSummaryColumn:()=>{},handleDragEnd:()=>{},handleExport:_t,handleContextMenu:Wt,handleCloseContextMenu:$t,toggleColumnVisibility:zt,toggleGroupExpand:at,toggleGroupField:st,handleToggleAll:Vt,handleExpandGroupRecursively:Ge,handleCollapseGroupRecursively:Ft,handleLayoutLoad:Gt,handleVariantLoad:ct,handleLayoutSave:Ot,effectiveAppId:e.appId||"",currentLayoutData:{visibleColumns:M,order:l,orderBy:i,grouping:y,columnWidths:c},currentLayoutId:te,layoutIdToLoad:"",onPageChange:it,onRowsPerPageChange:lt,graphReportOpen:A,handleOpenGraphReport:jt,handleCloseGraphReport:Ut}};var zc=e=>jsx(di,{...e}),Oc=e=>jsx(Bo,{...e}),Gc=e=>jsx(Rn,{...e}),Wc=e=>jsx(xa,{...e}),$c=e=>jsx(Ca,{...e}),Dt=e=>{let{title:o="Data Table",showToolbar:t=true,selectionMode:r,selected:l=[],onSelectionChange:n,actions:i,extraTools:a,fitContainer:d=false,fullWidth:T=false,maxHeight:k,loading:w=false,page:C=0,rowsPerPage:E=20,rowsPerPageOptions:M=[20,50,100,-1],count:m=0,onPageChange:f,onRowsPerPageChange:S,onLayoutSave:y,filterConfig:g,rowKey:p,tableKey:I="default",graphReport:c}=e,{isMobile:u,columns:b,order:x,orderBy:s,filterText:R,setFilterText:v,visibleColumns:z,showSummary:L,setShowSummary:V,summaryColumns:A,grouping:N,setGrouping:te,expandedGroups:Oe,groupAnchorEl:oe,setGroupAnchorEl:re,summaryAnchorEl:ie,setSummaryAnchorEl:De,columnWidths:nt,anchorEl:at,setAnchorEl:Ge,contextMenu:Ft,sensors:Vt,sortedAndFilteredRows:We,summaryRow:rt,visibleRows:Nt,isAllExpanded:Ht,handleColumnResize:it,handleRequestSort:lt,handleSelectAllClick:zt,handleClick:st,toggleSummaryColumn:Ot,handleDragEnd:ct,handleExport:Gt,handleContextMenu:Wt,handleCloseContextMenu:$t,toggleColumnVisibility:dt,toggleGroupExpand:_t,toggleGroupField:jt,handleToggleAll:Ut,handleExpandGroupRecursively:h,handleCollapseGroupRecursively:D,handleLayoutLoad:B,handleVariantLoad:ee,handleLayoutSave:G,effectiveAppId:Y,currentLayoutData:q,currentLayoutId:$,layoutIdToLoad:U,graphReportOpen:fe,handleOpenGraphReport:se,handleCloseGraphReport:Be}=Mn(e),ce=c?.enabled??false,{model:Se}=en({rows:We,config:{...c,title:c?.title||`${o} Graphic Report`}}),$e=Se.table.columns.map(ut=>({id:ut.id,label:ut.label,align:ut.align||"left",minWidth:120,numeric:ut.align==="right"})),Gn=Y?jsx(wn,{appId:Y,tableKey:I,currentLayoutData:q,onLayoutLoad:B,targetLayoutId:U,activeLayoutId:$,serviceUrl:(g?.variantService,void 0)}):null,Co=jsxs(Fragment,{children:[jsx(_o,{groupAnchorEl:oe,setGroupAnchorEl:re,grouping:N,setGrouping:te,columns:b,toggleGroupField:jt}),jsx(jo,{anchorEl:at,setAnchorEl:Ge,columns:b,visibleColumns:z,toggleColumnVisibility:dt}),jsx(Uo,{anchorEl:ie,setAnchorEl:De,showSummary:L,setShowSummary:V,columns:b,summaryColumns:A,toggleSummaryColumn:Ot}),jsx(Ko,{contextMenu:Ft,handleCloseContextMenu:$t,columns:b,visibleColumns:z,toggleColumnVisibility:dt})]});return u?jsxs(bo,{sx:{display:"flex",flexDirection:"column",gap:2,height:"100%"},children:[g&&jsx(Xe,{fields:g.fields,filters:g.filters,onFilterChange:g.onFilterChange,onSearch:g.onSearch,variants:g.variants||[],currentVariantId:g.currentVariantId,onVariantLoad:g.onVariantLoad,onVariantSave:g.onVariantSave,onVariantDelete:g.onVariantDelete,onVariantSetDefault:g.onVariantSetDefault,appId:g.appId,tableKey:I,currentLayout:[{tableKey:I,layoutData:q}],variantService:g.variantService}),jsx(Wo,{title:o,loading:w,showSummary:L,setShowSummary:V,setAnchorEl:Ge,setSummaryAnchorEl:De,filterText:R,setFilterText:v,sortedAndFilteredRows:We,selected:l,columns:b,visibleColumns:z,summaryRow:rt,handleClick:st,selectionMode:r}),Co]}):jsxs(bo,{sx:{width:T?"100%":"auto",mb:d?0:2,...d?{flex:1,display:"flex",flexDirection:"column",minHeight:0,height:"100%"}:{}},children:[g&&jsx(bo,{sx:{mb:2},children:jsx(Xe,{fields:g.fields,filters:g.filters,onFilterChange:g.onFilterChange,onSearch:g.onSearch,variants:g.variants||[],currentVariantId:g.currentVariantId,onVariantLoad:ee,onVariantSave:g.onVariantSave,onVariantDelete:g.onVariantDelete,onVariantSetDefault:g.onVariantSetDefault,loading:w,appId:g.appId,tableKey:I,currentLayout:[{tableKey:I,layoutData:q}],currentLayoutId:$,layoutRefs:[{tableKey:I,layoutId:$}],variantService:g.variantService})}),jsxs(si,{sx:{width:T?"100%":"auto",mb:d?0:2,display:"flex",flexDirection:"column",overflow:"hidden",...k?{height:k}:d?{flex:1,minHeight:0}:{}},children:[t&&jsx(Lo,{filterText:R,setFilterText:v,onRowsPerPageChange:S,rowsPerPage:E,rowsPerPageOptions:M,page:C,count:m,onPageChange:f,actions:i,extraTools:a,grouping:N,setGroupAnchorEl:re,showSummary:L,setShowSummary:V,setAnchorEl:Ge,setSummaryAnchorEl:De,handleExport:Gt,onLayoutSave:y||g?.variantService&&g?.appId?G:void 0,loading:w,layoutManager:Gn,onOpenGraphReport:ce?se:void 0}),jsx(Rn,{sx:{flex:1,maxHeight:k||"calc(100vh - 320px)",overflowY:"auto",overflowX:"auto",position:"relative",minHeight:0},children:jsx(DndContext,{sensors:Vt,collisionDetection:closestCenter,onDragEnd:ct,modifiers:[restrictToHorizontalAxis],children:jsxs(ci,{sx:{minWidth:T?750:"auto",width:T?"100%":"auto",tableLayout:Object.keys(nt).length>0?"fixed":"auto",borderCollapse:"separate",borderSpacing:0},"aria-labelledby":"tableTitle",size:"small",stickyHeader:true,children:[jsx(Vo,{columns:b,visibleColumns:z,order:x,orderBy:s,onRequestSort:lt,onContextMenu:Wt,selectionMode:r,grouping:N,isAllExpanded:Ht,handleToggleAll:Ut,rowCount:We.length,numSelected:l.length,onSelectAllClick:zt,columnWidths:nt,onColumnResize:it}),jsx(Ho,{visibleRows:Nt,columns:b,visibleColumns:z,selectionMode:r,selected:l,orderBy:s,loading:w,expandedGroups:Oe,toggleGroupExpand:_t,handleExpandGroupRecursively:h,handleCollapseGroupRecursively:D,handleClick:st,onSelectionChange:n,grouping:N,rowKeyProp:p,page:C,rowsPerPage:E}),L&&jsx(Oo,{showSummary:L,columns:b,visibleColumns:z,summaryRow:rt,selectionMode:r?.toString(),orderBy:s,zIndex:3})]})})})]}),Co,ce&&jsx(Zo,{open:fe,onClose:Be,model:Se,tableContent:jsx(Dt,{title:"Data Body",columns:$e,rows:Se.table.rows,rowKey:"id",fullWidth:true,maxHeight:"420px",rowsPerPage:20,rowsPerPageOptions:[20,50,100],graphReport:{enabled:false}})})]})},_c=Dt;var Jc=({title:e,hideHeader:o=true,filterConfig:t,tableProps:r,children:l,spacing:n=1})=>jsxs(Po,{title:e,hideHeader:o,children:[jsxs(Stack,{spacing:n,sx:{height:"100%",overflow:"hidden"},children:[t&&jsx(Box,{sx:{flexShrink:0},children:jsx(Xe,{...t})}),jsx(Box,{sx:{flex:1,minHeight:0,overflow:"hidden"},children:jsx(Dt,{...r,fitContainer:true,filterConfig:void 0})})]}),l]});var td=({metadata:e,fetchData:o})=>{let[t,r]=useState(false),[l,n]=useState([]),[i,a]=useState({}),[d,T]=useState(e.variants||[]),[k,w]=useState(e.layout||null),[C,E]=useState(0),[M,m]=useState(0),[f,S]=useState(10),[y,g]=useState([]),[p,I]=useState("asc"),[c,u]=useState("");useEffect(()=>{let A={};e.filters.forEach(N=>{N.defaultValue!==void 0&&(A[N.id]=N.defaultValue);}),a(A);},[e.filters]);let b=useCallback(async(A,N,te,Oe,oe)=>{r(true);try{let re={...A,page:N+1,limit:te,sort:oe,order:Oe},ie;o?ie=await o(re):typeof e.api=="function"?ie=await e.api(re):e.api&&typeof e.api=="object"?(console.log("Fetching from URL:",e.api.url,re),ie={rows:[],total:0}):(console.warn("No API configured for report"),ie={rows:[],total:0}),ie&&(n(ie.rows||[]),E(ie.total||0));}catch(re){console.error("Failed to fetch report data",re);}finally{r(false);}},[e.api,o]);useEffect(()=>{b(i,M,f,p,c);},[b,M,f,p,c]);let x=()=>{m(0),b(i,0,f,p,c);},s=(A,N)=>{I(N),u(A);},R=A=>{a(A);},v=A=>{if(A.filters){let N=A.filters.find(te=>te.scope==="default"||te.scope===e.id);N&&(a(N.filters),b(N.filters,0,f));}A.layout&&w(A.layout);},z=A=>{let N={...A,id:Date.now().toString(),createdAt:new Date().toISOString()};T(te=>[...te,N]);},L=A=>{w(A);};return {pageProps:{title:e.title,filterConfig:{appId:e.id,fields:e.filters,filters:i,onFilterChange:R,onSearch:x,onVariantLoad:v,onVariantSave:z,onVariantDelete:A=>T(N=>N.filter(te=>te.id!==A)),onVariantSetDefault:A=>{T(N=>N.map(te=>({...te,isDefault:te.id===A})));},variants:d},tableProps:{appId:e.id,columns:e.columns,rows:l,loading:t,rowKey:"id",count:C,page:M,rowsPerPage:f,rowsPerPageOptions:[10,25,50,100],onPageChange:m,onRowsPerPageChange:S,selectionMode:"multiple",selected:y,onSelectionChange:g,onLayoutSave:L,layout:k,title:e.title,showSummary:true,order:p,orderBy:c,onSortChange:s,graphReport:e.graphReport||{enabled:true,title:`${e.title} Graphic Report`}}},filters:i,rows:l,loading:t,refresh:x}};var Nn=64,Ai="#E9EDF2",Fi="linear-gradient(90deg, #F5F7FA 0%, #E9EDF2 50%, #F5F7FA 100%)",Hn=({appTitle:e,logo:o,mode:t="dark",onToggleMode:r,localeLabel:l="EN",searchPlaceholder:n="Ask me...",onSearch:i,user:a,leftSlot:d,rightSlot:T})=>{let w=useTheme().palette.mode==="dark",[C,E]=useState(""),[M,m]=useState(null),f=p=>{p.preventDefault(),i&&i(C.trim());},S=t==="system"?jsx(Di,{fontSize:"small"}):t==="dark"?jsx(Pi,{fontSize:"small"}):jsx(Ei,{fontSize:"small"}),y=t==="system"?"Theme: System":t==="dark"?"Theme: Dark":"Theme: Light",g=!!M;return jsxs(AppBar,{position:"sticky",elevation:0,sx:p=>({top:0,zIndex:p.zIndex.drawer+10,height:Nn,backgroundColor:p.palette.mode==="dark"?"#0D0D0D":Ai,backgroundImage:p.palette.mode==="dark"?["radial-gradient(circle at 18% 22%, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0) 45%)","radial-gradient(circle at 78% 32%, rgba(144,202,249,0.14) 0%, rgba(144,202,249,0) 42%)","linear-gradient(90deg, #0A0A0A 0%, #151515 50%, #0A0A0A 100%)","linear-gradient(rgba(255,255,255,0.04) 1px, transparent 1px)","linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px)"].join(","):["radial-gradient(circle at 22% 22%, rgba(255,255,255,0.7) 0%, rgba(255,255,255,0) 48%)","radial-gradient(circle at 76% 24%, rgba(203,213,225,0.45) 0%, rgba(203,213,225,0) 42%)",Fi,"linear-gradient(rgba(15,23,42,0.05) 1px, transparent 1px)","linear-gradient(90deg, rgba(15,23,42,0.04) 1px, transparent 1px)"].join(","),backgroundSize:"auto, auto, auto, 24px 24px, 24px 24px",borderBottom:"1px solid",borderColor:p.palette.mode==="dark"?"rgba(255,255,255,0.12)":"rgba(15,23,42,0.12)"}),children:[jsxs(Toolbar,{sx:{minHeight:`${Nn}px !important`,px:2,gap:2},children:[jsxs(Stack,{direction:"row",alignItems:"center",spacing:1.5,sx:{minWidth:220},children:[o||jsx(Box,{component:"img",src:"/orbcafe.png",alt:"ORBCAFE Logo",sx:{width:44,height:44,display:"block",objectFit:"contain",flexShrink:0}}),e&&jsx(Typography,{variant:"h6",sx:{fontWeight:700,color:w?"common.white":"#111827"},children:e}),d]}),jsx(Box,{sx:{flex:1,display:"flex",justifyContent:"center",minWidth:0},children:jsx(Box,{component:"form",onSubmit:f,sx:{width:"100%",maxWidth:540},children:jsx(TextField,{size:"small",fullWidth:true,value:C,onChange:p=>E(p.target.value),placeholder:n,InputProps:{startAdornment:jsx(InputAdornment,{position:"start",children:jsx(mn,{sx:{color:w?"rgba(255,255,255,0.7)":"rgba(15,23,42,0.55)",fontSize:18}})}),sx:{color:w?"common.white":"rgba(17,24,39,0.9)",bgcolor:w?"rgba(255,255,255,0.08)":"#ffffff",borderRadius:999,"& .MuiOutlinedInput-notchedOutline":{borderColor:w?"rgba(255,255,255,0.15)":"rgba(15,23,42,0.2)"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:w?"rgba(255,255,255,0.35)":"rgba(15,23,42,0.35)"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:w?"rgba(255,255,255,0.5)":"rgba(15,23,42,0.55)"}}},inputProps:{style:{color:w?"white":"#111827"}}})})}),jsxs(Stack,{direction:"row",alignItems:"center",spacing:1.5,children:[jsxs(Stack,{direction:"row",alignItems:"center",spacing:.5,children:[jsx(Ri,{sx:{color:w?"common.white":"#111827",fontSize:18}}),jsx(Typography,{variant:"caption",sx:{color:w?"common.white":"#111827",fontWeight:500},children:l})]}),jsx(IconButton,{size:"small",sx:{color:w?"common.white":"#111827"},onClick:r,title:y,children:S}),a&&jsxs(Stack,{direction:"row",alignItems:"center",spacing:1,children:[jsxs(Box,{sx:{textAlign:"right",minWidth:0},children:[jsx(Typography,{variant:"body2",sx:{color:w?"common.white":"#111827",fontWeight:700,lineHeight:1.15},children:a.name}),a.subtitle&&jsx(Typography,{variant:"caption",sx:{display:"block",mt:.25,color:w?"rgba(255,255,255,0.72)":"rgba(17,24,39,0.62)",fontSize:"0.72rem",lineHeight:1.1,letterSpacing:"0.01em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:220},title:a.subtitle,children:a.subtitle})]}),jsx(IconButton,{size:"small",onClick:p=>m(p.currentTarget),sx:{p:0},children:jsx(Avatar,{src:a.avatarSrc,imgProps:{style:{objectFit:"cover"}},sx:{width:34,height:34,bgcolor:"grey.100",color:"grey.700",fontSize:"0.85rem"},children:a.avatarText||a.name.slice(0,1).toUpperCase()})})]}),T]})]}),jsxs(Menu,{anchorEl:M,open:g,onClose:()=>m(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},slotProps:{paper:{sx:{minWidth:160,"& .MuiMenuItem-root":{minHeight:34,py:.5,px:1.25}}}},children:[jsxs(MenuItem,{onClick:()=>m(null),children:[jsx(ListItemIcon,{children:jsx(zr,{sx:{fontSize:18}})}),jsx(ListItemText,{primary:"Setting",slotProps:{primary:{sx:{fontSize:"0.86rem",fontWeight:500}}}})]}),jsxs(MenuItem,{onClick:()=>m(null),children:[jsx(ListItemIcon,{children:jsx(Bi,{sx:{fontSize:18}})}),jsx(ListItemText,{primary:"Logout",slotProps:{primary:{sx:{fontSize:"0.86rem",fontWeight:500}}}})]})]})]})};var zn=({menuData:e=[],initialNavigationCollapsed:o=false}={})=>{let{navigationIslandProps:t}=Do({initialCollapsed:o,content:e}),[r,l]=useState(900);useEffect(()=>{let i=()=>l(window.innerHeight);return i(),window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)},[]);let n=useMemo(()=>Math.max(280,r-100),[r]);return {navigationIslandProps:t,navigationMaxHeight:n}};var Td=({appTitle:e,menuData:o=[],children:t,showNavigation:r=true,localeLabel:l,user:n,logo:i,onSearch:a,rightHeaderSlot:d,leftHeaderSlot:T,contentSx:k})=>{let[w,C]=useState("system"),[E,M]=useState("light"),[m,f]=useState(false),S=w==="system"?m?E:"light":w;useEffect(()=>{f(true);let I=window.matchMedia("(prefers-color-scheme: dark)"),c=()=>{M(I.matches?"dark":"light");};return c(),I.addEventListener("change",c),()=>I.removeEventListener("change",c)},[]);let y=useMemo(()=>createTheme({palette:{mode:S}}),[S]),{navigationIslandProps:g,navigationMaxHeight:p}=zn({menuData:o,initialNavigationCollapsed:false});return jsx(ThemeProvider,{theme:y,children:jsxs(Box,{sx:I=>({minHeight:"100vh",display:"flex",flexDirection:"column",background:I.palette.mode==="dark"?"linear-gradient(180deg, #0A0A0A 0%, #141414 55%, #1A1A1A 100%)":I.palette.background.default}),children:[jsx(Hn,{appTitle:e,logo:i,mode:w,onToggleMode:()=>C(I=>I==="system"?"dark":I==="dark"?"light":"system"),localeLabel:l,user:n,onSearch:a,leftSlot:T,rightSlot:d}),jsxs(Box,{sx:{flex:1,minHeight:0,display:"flex"},children:[r&&jsx(Box,{sx:{p:1.5,display:"flex",alignItems:"flex-start",flexShrink:0},children:jsx(Mo,{...g,maxHeight:p,colorMode:S})}),jsx(Box,{sx:{flex:1,minWidth:0,minHeight:0,overflow:"auto",p:1.5,...k},children:t})]})]})})};export{Yt as Button,Hn as CAppHeader,Td as CAppPageLayout,Sn as CLayoutManagement,wn as CLayoutManager,Po as CPageLayout,Xe as CSmartFilter,_c as CSmartTable,Jc as CStandardPage,Dt as CTable,zc as CTableBody,Oc as CTableCell,Gc as CTableContainer,Wc as CTableHead,$c as CTableRow,vt as CVariantManagement,sn as CVariantManager,Mo as NavigationIsland,Xt as TreeMenu,Un as buttonVariants,Do as useNavigationIsland,zn as usePageLayout,td as useStandardReport};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orbcafe-ui",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Awesome UI components with Glassmorphism",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -9,7 +9,8 @@
9
9
  "build": "tsup",
10
10
  "prepublishOnly": "npm run build",
11
11
  "pack:check": "npm_config_cache=/tmp/.npm-cache npm pack --dry-run",
12
- "publish:npm": "npm publish --access public"
12
+ "publish:npm": "npm publish --access public",
13
+ "publish:npm:token": "./scripts/publish-npm.sh"
13
14
  },
14
15
  "keywords": [
15
16
  "react",