orbcafe-ui 1.0.2 → 1.0.4
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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -3
- package/dist/index.mjs +3 -3
- package/package.json +8 -7
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
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&<({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,${
|
|
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 Eo=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'),ho=require('@mui/material/Box'),ni=require('@mui/material/Paper'),ri=require('@mui/material/Table'),ii=require('@mui/material/TableBody'),Ao=require('@mui/material/TableCell'),Ra=require('@mui/material/TableContainer'),fn=require('@mui/material/TableHead'),yn=require('@mui/material/TableRow'),core=require('@dnd-kit/core'),modifiers=require('@dnd-kit/modifiers'),ma=require('@mui/icons-material/Search'),rn=require('@mui/icons-material/ViewColumn'),va=require('@mui/icons-material/Save'),sn=require('@mui/icons-material/Download'),cn=require('@mui/icons-material/AccountTree'),dn=require('@mui/icons-material/Functions'),un=require('@mui/icons-material/Insights'),hn=require('@mui/material/Checkbox'),bn=require('@mui/material/TableSortLabel'),Tn=require('@mui/icons-material/KeyboardArrowRight'),wn=require('@mui/icons-material/KeyboardArrowDown'),Vn=require('@mui/icons-material/Check'),Nn=require('@mui/icons-material/ClearAll'),qn=require('@mui/icons-material/Close'),Fr=require('@mui/icons-material/Settings'),Vr=require('@mui/icons-material/KeyboardArrowUp'),Hr=require('@mui/icons-material/ArrowRightAlt'),sr=require('@mui/icons-material/Star'),DateCalendar=require('@mui/x-date-pickers/DateCalendar'),PickersDay=require('@mui/x-date-pickers/PickersDay'),Tr=require('@mui/icons-material/CalendarMonth'),wr=require('@mui/icons-material/Clear'),Ir=require('@mui/icons-material/ArrowForward'),Pe=require('dayjs'),kr=require('dayjs/plugin/isBetween'),Xr=require('@mui/icons-material/Delete'),Zr=require('@mui/icons-material/StarBorder'),Qr=require('@mui/icons-material/ViewQuilt'),Ii=require('@mui/icons-material/Language'),ki=require('@mui/icons-material/DesktopWindows'),Mi=require('@mui/icons-material/DarkMode'),Ri=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 Eo__namespace=/*#__PURE__*/_interopNamespace(Eo);var ho__default=/*#__PURE__*/_interopDefault(ho);var ni__default=/*#__PURE__*/_interopDefault(ni);var ri__default=/*#__PURE__*/_interopDefault(ri);var ii__default=/*#__PURE__*/_interopDefault(ii);var Ao__default=/*#__PURE__*/_interopDefault(Ao);var Ra__default=/*#__PURE__*/_interopDefault(Ra);var fn__default=/*#__PURE__*/_interopDefault(fn);var yn__default=/*#__PURE__*/_interopDefault(yn);var ma__default=/*#__PURE__*/_interopDefault(ma);var rn__default=/*#__PURE__*/_interopDefault(rn);var va__default=/*#__PURE__*/_interopDefault(va);var sn__default=/*#__PURE__*/_interopDefault(sn);var cn__default=/*#__PURE__*/_interopDefault(cn);var dn__default=/*#__PURE__*/_interopDefault(dn);var un__default=/*#__PURE__*/_interopDefault(un);var hn__default=/*#__PURE__*/_interopDefault(hn);var bn__default=/*#__PURE__*/_interopDefault(bn);var Tn__default=/*#__PURE__*/_interopDefault(Tn);var wn__default=/*#__PURE__*/_interopDefault(wn);var Vn__default=/*#__PURE__*/_interopDefault(Vn);var Nn__default=/*#__PURE__*/_interopDefault(Nn);var qn__default=/*#__PURE__*/_interopDefault(qn);var Fr__default=/*#__PURE__*/_interopDefault(Fr);var Vr__default=/*#__PURE__*/_interopDefault(Vr);var Hr__default=/*#__PURE__*/_interopDefault(Hr);var sr__default=/*#__PURE__*/_interopDefault(sr);var Tr__default=/*#__PURE__*/_interopDefault(Tr);var wr__default=/*#__PURE__*/_interopDefault(wr);var Ir__default=/*#__PURE__*/_interopDefault(Ir);var Pe__default=/*#__PURE__*/_interopDefault(Pe);var kr__default=/*#__PURE__*/_interopDefault(kr);var Xr__default=/*#__PURE__*/_interopDefault(Xr);var Zr__default=/*#__PURE__*/_interopDefault(Zr);var Qr__default=/*#__PURE__*/_interopDefault(Qr);var Ii__default=/*#__PURE__*/_interopDefault(Ii);var ki__default=/*#__PURE__*/_interopDefault(ki);var Mi__default=/*#__PURE__*/_interopDefault(Mi);var Ri__default=/*#__PURE__*/_interopDefault(Ri);function le(...e){return tailwindMerge.twMerge(clsx.clsx(e))}var jt={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 Ga=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-[${jt.primary}] hover:bg-[${jt.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"}}),Ut=Eo__namespace.forwardRef(({className:e,variant:o,size:t,asChild:r=false,...a},n)=>jsxRuntime.jsx(r?reactSlot.Slot:"button",{className:le(Ga({variant:o,size:t,className:e})),ref:n,...a}));Ut.displayName="Button";function Yt({items:e,onItemClick:o,className:t="",level:r=0,expandedIds:a,onToggleExpand:n,colorMode:l="light"}){let i=l==="dark",d=navigation.usePathname(),[T,k]=Eo.useState(new Set),w=a!==void 0&&n!==void 0,v=w?a:T,E=p=>{if(w)n(p);else {let g=new Set(T);g.has(p)?g.delete(p):g.add(p),k(g);}},D=p=>{p.children&&p.children.length>0&&E(p.id),o&&o(p);};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(p=>{let g=v.has(p.id)||p.isExpanded,b=p.children&&p.children.length>0,h=p.appurl||p.href,m=h?d===h:false;return jsxRuntime.jsxs("div",{className:"tree-menu-item relative",children:[m&&jsxRuntime.jsx("div",{className:le("absolute left-0 top-2 bottom-2 w-[3px] rounded-r-full z-10",i?"bg-[#90caf9]":"bg-[#1976d2]")}),jsxRuntime.jsxs(Ut,{variant:"ghost",className:le("w-full justify-start gap-2 h-auto py-2 relative overflow-hidden group",`ml-${r*4}`,m?i?"bg-transparent text-[#90caf9] hover:bg-gray-800/35":"bg-transparent text-[#1976d2] hover:bg-gray-100/60":i?"hover:bg-gray-800/50 text-gray-300":"hover:bg-gray-100/50 text-gray-700"),onClick:()=>D(p),children:[b&&jsxRuntime.jsx("div",{className:le("flex-shrink-0 transition-transform duration-200",g&&"rotate-90",m?i?"text-[#90caf9]":"text-[#1976d2]":i?"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"})}),!b&&jsxRuntime.jsx("div",{className:"w-4 h-4 flex-shrink-0"}),p.icon&&jsxRuntime.jsx("div",{className:le("flex-shrink-0 transition-colors duration-200",m?i?"text-[#90caf9]":"text-[#1976d2]":i?"text-gray-500 group-hover:text-gray-300":"text-gray-400 group-hover:text-gray-600"),children:p.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",m?"font-semibold":"font-medium"),children:p.title||p.label}),p.description&&jsxRuntime.jsx("div",{className:le("text-xs truncate transition-colors duration-200",m?i?"text-[#90caf9]/70":"text-[#1976d2]/75":i?"text-gray-400":"text-gray-500"),title:p.description,children:p.description})]})]}),b&&jsxRuntime.jsx("div",{className:le("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(Yt,{items:p.children,onItemClick:o,level:r+1,expandedIds:a,onToggleExpand:n,colorMode:l})})})]},p.id)})})}var Mo=({collapsed:e,onToggle:o,className:t="",maxHeight:r,menuData:a=[],colorMode:n="light"})=>{let l=n==="dark",i=navigation.useRouter(),[d,T]=Eo.useState(""),[k,w]=Eo.useState(new Set);Eo.useEffect(()=>{e&&w(new Set);},[e]);let v=Eo.useCallback(g=>{let b=[],h=m=>{m.forEach(y=>{b.push(y.id),y.children&&h(y.children);});};return h(g),b},[]),E=Eo.useMemo(()=>{if(!d.trim())return a;let g=b=>b.reduce((h,m)=>{let y=m.title?.toLowerCase().includes(d.toLowerCase())||m.description?.toLowerCase().includes(d.toLowerCase()),I=m.children?g(m.children):[];return (y||I.length>0)&&h.push({...m,children:I.length>0?I:m.children}),h},[]);return g(a)},[d,a]),D=Eo.useMemo(()=>d.trim()?new Set(v(a)):k,[d,a,k,v]),p=Eo.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{i.push("/chat?new=true");}catch(h){console.error("\u274C \u65E0\u6CD5\u8DF3\u8F6C\u5230\u65B0\u804A\u5929\u89C6\u56FE:",h),i.push("/chat");}return}let b=g.appurl||g.href;b&&(b.startsWith("http://")||b.startsWith("https://")?window.open(b,"_blank"):i.push(b));},[i]);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: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 ${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:d,onChange:g=>T(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: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(Yt,{items:E,onItemClick:p,className:"space-y-1",expandedIds:D,colorMode:n,onToggleExpand:g=>{let b=new Set(k);E.some(m=>m.id===g)?b.has(g)?b.delete(g):(E.forEach(m=>{m.id!==g&&b.has(m.id)&&b.delete(m.id);}),b.add(g)):b.has(g)?b.delete(g):b.add(g),w(b);}})}),e&&jsxRuntime.jsx("div",{className:"space-y-2",children:a.map(g=>jsxRuntime.jsx("div",{className:"space-y-1",children:jsxRuntime.jsx("button",{onClick:()=>{o();let b=new Set([g.id]);w(b);},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 Do=(e={})=>{let{initialCollapsed:o=false,content:t=[]}=e,[r,a]=Eo.useState(o),[n,l]=Eo.useState(t),i=Eo.useCallback(()=>{a(T=>!T);},[]),d=Eo.useMemo(()=>({collapsed:r,onToggle:i,menuData:n}),[r,i,n]);return {collapsed:r,setCollapsed:a,toggleCollapsed:i,menuData:n,setMenuData:l,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]:[];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"}),t.length>0&&jsxRuntime.jsx(material.Box,{sx:{display:"flex",gap:1,alignItems:"center",mr:1},children:t.map((a,n)=>jsxRuntime.jsx(Eo__namespace.default.Fragment,{children:a},`toolbar-action-${n}`))}),jsxRuntime.jsxs(material.Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsxRuntime.jsx(material.TextField,{size:"small",placeholder:"Search...",value:e.filterText,onChange:a=>e.setFilterText(a.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(ma__default.default,{fontSize:"small"})})},sx:{width:300}}),jsxRuntime.jsx(material.Tooltip,{title:"Group By",children:jsxRuntime.jsx(material.IconButton,{onClick:a=>e.setGroupAnchorEl(a.currentTarget),children:jsxRuntime.jsx(material.Badge,{badgeContent:e.grouping?.length,color:"primary",children:jsxRuntime.jsx(cn__default.default,{})})})}),jsxRuntime.jsx(material.Tooltip,{title:"Summary",children:jsxRuntime.jsx(material.IconButton,{onClick:a=>e.setSummaryAnchorEl(a.currentTarget),color:e.showSummary?"primary":"default",children:jsxRuntime.jsx(dn__default.default,{})})}),jsxRuntime.jsx(material.Tooltip,{title:"Columns",children:jsxRuntime.jsx(material.IconButton,{onClick:a=>e.setAnchorEl(a.currentTarget),children:jsxRuntime.jsx(rn__default.default,{})})}),jsxRuntime.jsx(material.Tooltip,{title:"Export",children:jsxRuntime.jsx(material.IconButton,{onClick:e.handleExport,children:jsxRuntime.jsx(sn__default.default,{})})}),e.onOpenGraphReport&&jsxRuntime.jsx(material.Tooltip,{title:"Graphic Report",children:jsxRuntime.jsx(material.IconButton,{onClick:e.onOpenGraphReport,children:jsxRuntime.jsx(un__default.default,{})})}),e.onLayoutSave&&!e.layoutManager&&jsxRuntime.jsx(material.Tooltip,{title:"Save Layout",children:jsxRuntime.jsx(material.IconButton,{onClick:a=>e.onLayoutSave(a),children:jsxRuntime.jsx(va__default.default,{})})}),e.layoutManager,r.length>0&&jsxRuntime.jsx(material.Box,{sx:{display:"flex",gap:1,alignItems:"center",ml:.5},children:r.map((a,n)=>jsxRuntime.jsx(Eo__namespace.default.Fragment,{children:a},`toolbar-extra-${n}`))})]})]})};var No=e=>{let{onSelectAllClick:o,order:t,orderBy:r,numSelected:a=0,rowCount:n=0,onRequestSort:l,columns:i,visibleColumns:d,selectionMode:T,onColumnResize:k,columnWidths:w}=e,[v,E]=Eo.useState(null),D=Eo.useRef(null),p=y=>I=>{v||l(y);},g=(y,I,c)=>{y.preventDefault(),y.stopPropagation(),E(I),D.current={startX:y.clientX,startWidth:c,colId:I},document.addEventListener("mousemove",b),document.addEventListener("mouseup",h),document.body.style.cursor="col-resize";},b=y=>{if(!D.current)return;let{startX:I,startWidth:c,colId:u}=D.current,x=y.clientX-I,C=Math.max(50,c+x);k&&k(u,C);},h=()=>{E(null),D.current=null,document.removeEventListener("mousemove",b),document.removeEventListener("mouseup",h),document.body.style.cursor="";};return Eo.useEffect(()=>()=>{document.removeEventListener("mousemove",b),document.removeEventListener("mouseup",h);},[]),jsxRuntime.jsx(fn__default.default,{children:jsxRuntime.jsxs(yn__default.default,{children:[(T==="multiple"||T==="single")&&jsxRuntime.jsx(Ao__default.default,{padding:"checkbox",sx:y=>({width:48,backgroundColor:y.palette.mode==="dark"?"#000000":"#f5f5f5",color:y.palette.mode==="dark"?"#ffffff":y.palette.text.primary}),children:jsxRuntime.jsx(hn__default.default,{color:"primary",indeterminate:a>0&&a<n,checked:n>0&&a===n,onChange:o,disabled:T==="single"})}),i.filter(y=>d.includes(y.id)).map(y=>{let I=w?.[y.id]||y.minWidth||100;return jsxRuntime.jsxs(Ao__default.default,{align:"left",padding:y.disablePadding?"none":"normal",sortDirection:r===y.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(bn__default.default,{active:r===y.id,direction:r===y.id?t:"asc",onClick:p(y.id),sx:c=>({"&.MuiTableSortLabel-root":{width:"100%"},"& .MuiTableSortLabel-icon":{color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary,opacity:r===y.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(ho__default.default,{component:"span",sx:{overflow:"visible",textOverflow:"clip",whiteSpace:"normal",lineHeight:1.2,wordBreak:"break-word",pr:1},children:y.label})}),jsxRuntime.jsx(ho__default.default,{onMouseDown:c=>g(c,y.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}})]},y.id)})]})})};var Oo=e=>{let{visibleRows:o,visibleColumns:t,selected:r=[],handleClick:a,columns:n,toggleGroupExpand:l,expandedGroups:i=new Set,selectionMode:d}=e,T=v=>r.indexOf(v)!==-1,k=d==="multiple"||d==="single",w=t.length+(k?1:0);return jsxRuntime.jsxs(material.TableBody,{children:[o.map((v,E)=>{if(v.type==="group"){let D=i.has(v.id),p=v.childIds||[],g=p.filter(y=>T(y)).length,b=p.length>0&&g===p.length,h=g>0&&g<p.length,m=y=>{if(y.stopPropagation(),!!e.onSelectionChange)if(b){let I=r.filter(c=>!p.includes(c));e.onSelectionChange(I);}else {let I=Array.from(new Set([...r,...p]));e.onSelectionChange(I);}};return jsxRuntime.jsx(material.TableRow,{sx:y=>({backgroundColor:y.palette.mode==="dark"?"#111111":"#f5f5f5","& .MuiTableCell-root":{color:y.palette.text.primary,borderBottomColor:y.palette.divider},"& .MuiIconButton-root":{color:y.palette.text.primary},"& .MuiCheckbox-root":{color:y.palette.text.secondary},"& .MuiCheckbox-root.Mui-checked, & .MuiCheckbox-root.MuiCheckbox-indeterminate":{color:y.palette.primary.main}}),children:jsxRuntime.jsx(material.TableCell,{colSpan:w,sx:{py:1,pl:v.level*4+2},children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center"},children:[jsxRuntime.jsx(material.IconButton,{size:"small",onClick:()=>l&&l(v.id),sx:{mr:1},children:D?jsxRuntime.jsx(wn__default.default,{}):jsxRuntime.jsx(Tn__default.default,{})}),k&&jsxRuntime.jsx(material.Checkbox,{size:"small",checked:b,indeterminate:h,onChange:m,onClick:y=>y.stopPropagation(),sx:{mr:1,p:.5}}),jsxRuntime.jsxs(material.Typography,{variant:"body2",fontWeight:"bold",color:"text.primary",children:[v.field,": ",v.value," (",v.count,")"]})]})})},v.id)}else {let D=v.data||v,p=v.id||D.id||E,g=T(p),b=`enhanced-table-checkbox-${E}`,m=(v.level!==void 0?v.level:0)*4;return jsxRuntime.jsxs(material.TableRow,{hover:true,onClick:y=>a&&a(y,D),role:"checkbox","aria-checked":g,tabIndex:-1,selected:g,sx:{cursor:"pointer"},children:[k&&jsxRuntime.jsx(material.TableCell,{padding:"checkbox",sx:{pl:m>0?m+1:void 0},children:jsxRuntime.jsx(material.Checkbox,{color:"primary",checked:g,inputProps:{"aria-labelledby":b}})}),n.filter(y=>t.includes(y.id)).map((y,I)=>{let u=!k&&I===0&&m>0?{pl:m+2}:{};return jsxRuntime.jsx(material.TableCell,{align:"left",sx:u,children:y.render?y.render(D[y.id],D):(function(){let C=D[y.id];if(y.numeric){if(typeof C=="number")return C.toLocaleString();if(typeof C=="string"&&C.trim()!==""&&!isNaN(Number(C)))return Number(C).toLocaleString()}return C})()},y.id)})]},p)}}),o.length===0&&jsxRuntime.jsx(material.TableRow,{children:jsxRuntime.jsx(material.TableCell,{colSpan:w,align:"center",children:"No data"})})]})};var Go=e=>{let{visibleColumns:o,summaryRow:t,selectionMode:r}=e;if(!e.showSummary)return null;let a=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:[a&&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 i=t[n];return i==null||i===""?"":typeof i=="number"?i.toLocaleString():typeof i=="string"&&i.trim()!==""&&!isNaN(Number(i))?Number(i).toLocaleString():i})()},n))]})})};var $o=e=>jsxRuntime.jsx(material.Box,{sx:{p:2},children:jsxRuntime.jsx(material.Typography,{children:"Mobile View Not Implemented"})});var jo=({groupAnchorEl:e,setGroupAnchorEl:o,grouping:t,setGrouping:r,columns:a,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(Nn__default.default,{}),children:"Clear All"})]}),jsxRuntime.jsx(material.Divider,{}),a.map(l=>{let i=t.includes(l.id),d=t.indexOf(l.id)+1;return jsxRuntime.jsx(material.MenuItem,{onClick:()=>n(l.id),children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsxRuntime.jsx(material.Checkbox,{checked:i,size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:l.label}),i&&jsxRuntime.jsx(material.Badge,{badgeContent:d,color:"primary",sx:{mr:2}})]})},l.id)})]}),Uo=({anchorEl:e,setAnchorEl:o,columns:t,visibleColumns:r,toggleColumnVisibility:a})=>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:()=>a(n.id),children:[jsxRuntime.jsx(material.Checkbox,{checked:r.includes(n.id),size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:n.label})]},n.id))]}),Ko=({anchorEl:e,setAnchorEl:o,showSummary:t,setShowSummary:r,columns:a,summaryColumns:n,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:i=>r(i.target.checked),size:"small"}),label:"Show Summary Row"})}),jsxRuntime.jsx(material.Divider,{}),a.filter(i=>i.numeric).map(i=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>l(i.id),disabled:!t,children:[jsxRuntime.jsx(material.Checkbox,{checked:n.includes(i.id),size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:i.label})]},i.id)),a.filter(i=>i.numeric).length===0&&jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.ListItemText,{primary:"No numeric columns"})})]}),Yo=({contextMenu:e,handleCloseContextMenu:o,columns:t,visibleColumns:r,toggleColumnVisibility:a})=>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:()=>a(n.id),children:[jsxRuntime.jsx(material.ListItemIcon,{children:r.includes(n.id)&&jsxRuntime.jsx(Vn__default.default,{fontSize:"small"})}),jsxRuntime.jsx(material.ListItemText,{children:n.label})]},n.id))]});var _e=(e,o=2)=>e.toLocaleString(void 0,{maximumFractionDigits:o}),Xo=({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 ht=["#1E88E5","#1ABC9C","#FBC02D","#EF5350","#7E57C2","#78909C"],Wn=({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))})},$n=({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))})},_n=({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((a,n)=>{let l=o;return o+=a.percent,`${ht[n%ht.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: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((a,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:ht[n%ht.length]}}),jsxRuntime.jsx(material.Typography,{variant:"caption",sx:{flex:1},children:a.name}),jsxRuntime.jsxs(material.Typography,{variant:"caption",sx:{fontWeight:700},children:[a.percent.toFixed(0),"%"]})]},a.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]}),Jo=({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(Wn,{data:e})}),jsxRuntime.jsx(ao,{title:"Efficiency by Person",subtitle:"Lowest efficiency first",children:jsxRuntime.jsx($n,{data:o})}),jsxRuntime.jsx(ao,{title:"Status Distribution",subtitle:"Record ratio by status",children:jsxRuntime.jsx(_n,{data:t})})]});var Qo=({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(qn__default.default,{})})]})}),jsxRuntime.jsxs(material.Box,{sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,overflow:"auto",minHeight:0},children:[jsxRuntime.jsx(Xo,{kpis:t.kpis}),jsxRuntime.jsx(Jo,{billableByPrimary:t.charts.billableByPrimary,efficiencyBySecondary:t.charts.efficiencyBySecondary,statusDistribution:t.charts.statusDistribution}),r]})]})});var we={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"]},Xn=5,ea=e=>e.toLowerCase().replace(/[\s_-]/g,""),Ie=(e,o,t,r)=>{if(o)return o;if(e.length===0)return r;let a=Object.keys(e[0]),n=new Map(a.map(l=>[ea(l),l]));for(let l of t){let i=n.get(ea(l));if(i)return i}return a[0]||r},be=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},xe=(e,o)=>e==null||e===""?o:String(e),Jn=(e,o,t,r)=>{let a=new Map;return e.forEach(n=>{let l=xe(n[o],"Unassigned");a.set(l,(a.get(l)||0)+be(n[t]));}),Array.from(a.entries()).map(([n,l])=>({name:n,value:l})).sort((n,l)=>l.value-n.value).slice(0,r)},Zn=(e,o,t,r,a)=>{let n=new Map;return e.forEach(l=>{let i=xe(l[o],"Unassigned"),d=n.get(i)||{report:0,billable:0};d.report+=be(l[t]),d.billable+=be(l[r]),n.set(i,d);}),Array.from(n.entries()).map(([l,i])=>({name:l,value:i.report>0?i.billable/i.report*100:0})).sort((l,i)=>l.value-i.value).slice(0,a)},Qn=(e,o)=>{let t=e.length;if(t===0)return [];let r=new Map;return e.forEach(a=>{let n=xe(a[o],"Unassigned");r.set(n,(r.get(n)||0)+1);}),Array.from(r.entries()).map(([a,n])=>({name:a,value:n,percent:n/t*100}))},ta=({rows:e,config:o})=>{let t=Eo.useMemo(()=>{let d=o?.fieldMapping;return {primaryDimension:Ie(e,d?.primaryDimension,we.primaryDimension,"Category"),secondaryDimension:Ie(e,d?.secondaryDimension,we.secondaryDimension,"Owner"),status:Ie(e,d?.status,we.status,"Status"),date:Ie(e,d?.date,we.date,"Date"),description:Ie(e,d?.description,we.description,"Description"),reportHours:Ie(e,d?.reportHours,we.reportHours,"ReportHours"),billableHours:Ie(e,d?.billableHours,we.billableHours,"BillableHours"),amount:Ie(e,d?.amount,we.amount,"Amount")}},[e,o?.fieldMapping]),r=Eo.useMemo(()=>e.map((d,T)=>{let k=be(d[t.reportHours]),w=be(d[t.billableHours]),v=be(d[t.amount]),E=k>0?w/k*100:0;return {id:`graph-row-${T}`,Date:xe(d[t.date],""),Primary:xe(d[t.primaryDimension],"Unassigned"),Secondary:xe(d[t.secondaryDimension],"Unassigned"),Description:xe(d[t.description],""),ReportHours:k,BillableHours:w,Amount:v,Efficiency:E,Status:xe(d[t.status],"Unassigned")}}),[e,t]),a=Eo.useMemo(()=>{let d=r.length,T=r.reduce((p,g)=>p+be(g.ReportHours),0),k=r.reduce((p,g)=>p+be(g.BillableHours),0),w=r.reduce((p,g)=>p+be(g.Amount),0),v=T>0?k/T*100:0,E=o?.statusFlagValues||["flag","flagged","warning","risk"],D=r.filter(p=>E.includes(xe(p.Status,"").toLowerCase())).length;return {totalRecords:d,totalReportHours:T,totalBillableHours:k,efficiency:v,totalAmount:w,flaggedCount:D}},[r,o?.statusFlagValues]),n=o?.topN||Xn,l=Eo.useMemo(()=>({billableByPrimary:Jn(r,"Primary","BillableHours",n),efficiencyBySecondary:Zn(r,"Secondary","ReportHours","BillableHours",n),statusDistribution:Qn(r,"Status")}),[r,n]),i=Eo.useMemo(()=>({title:o?.title||"Graphic Report",kpis:a,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:r}}),[l,o?.title,t,a,r]);return {fieldMapping:t,model:i}};var Ct=({variants:e,currentVariantId:o,onLoad:t,onSave:r,onDelete:a,onSetDefault:n})=>{let l="0.75rem",[i,d]=Eo.useState(false),[T,k]=Eo.useState(""),[w,v]=Eo.useState(false),[E,D]=Eo.useState(false),p=e.find(h=>h.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:h=>h.name+(h.isDefault?" (Default)":""),value:p||null,onChange:(h,m)=>{m&&t(m);},renderInput:h=>jsxRuntime.jsx(material.TextField,{...h,variant:"outlined",size:"small",InputProps:{...h.InputProps,sx:{fontSize:l}},placeholder:"Select Variant"}),renderOption:(h,m)=>jsxRuntime.jsx("li",{...h,children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsxRuntime.jsx(material.Typography,{sx:{flex:1,fontSize:l},children:m.name}),m.isDefault&&jsxRuntime.jsx(sr__default.default,{fontSize:"small",color:"action"})]})})}),jsxRuntime.jsx(material.Tooltip,{title:"Save View",children:jsxRuntime.jsx(material.IconButton,{onClick:()=>{k(p?.name||"New Variant"),v(p?.isDefault||false),D(p?.isPublic||false),d(true);},size:"small",color:"primary",children:jsxRuntime.jsx(va__default.default,{})})}),jsxRuntime.jsxs(material.Dialog,{open:i,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:h=>k(h.target.value)}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:w,onChange:h=>v(h.target.checked)}),label:"Set as Default"}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:E,onChange:h=>D(h.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 ur="http://127.0.0.1:8515",sa=({appId:e,tableKey:o="default",currentFilters:t,currentLayoutId:r,layoutRefs:a,onLoad:n,serviceUrl:l=ur,onError:i,onSuccess:d,currentVariantId:T,onVariantChange:k})=>{let[w,v]=Eo.useState([]),[E,D]=Eo.useState(""),p=T!==void 0?T:E,g=c=>{T===void 0&&D(c),k&&k(c);},b=Eo.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 u=await c.json();v(u);let x=u.find(C=>C.isDefault);return x&&!p&&(g(x.id),n(x)),u}catch(c){return console.error("Error fetching variants",c),i&&i("Failed to load variants"),[]}},[e,o,l,i,p,n]);return Eo.useEffect(()=>{b();},[e,o]),jsxRuntime.jsx(Ct,{variants:w,currentVariantId:p,onLoad:c=>{g(c.id),n(c);},onSave:async c=>{try{let u=w.find(B=>B.name===c.name),x=u?u.id:Date.now().toString(),C=[];if(u&&(Array.isArray(u.filters)?C=[...u.filters]:u.filters&&(C=[{scope:"default",filters:u.filters}])),c.scope==="Search"||c.scope==="Both"){let B=(Array.isArray(t),t);if(B)if(Array.isArray(B)&&B.length>0&&B[0].scope)B.forEach(V=>{let A=C.findIndex(N=>N.scope===V.scope);A>=0?C[A]=V:C.push(V);});else {let V={scope:o,filters:B},A=C.findIndex(N=>N.scope===o);A>=0?C[A]=V:C.push(V);}}let s=u?.layout||{},M=[];if(u&&Array.isArray(u.layoutRefs)&&(M=[...u.layoutRefs]),c.scope==="Layout"||c.scope==="Both")if(a&&a.length>0)a.forEach(B=>{let V=M.findIndex(A=>A.tableKey===B.tableKey);V>=0?M[V]=B:M.push(B);});else {let B={tableKey:o,layoutId:r||null},V=M.findIndex(A=>A.tableKey===o);V>=0?M[V]=B:M.push(B);}let S={appId:e,tableKey:o,...c,id:x,createdAt:new Date().toISOString(),filters:C,layout:s,layoutRefs:M};if(!(await fetch(`${l}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(S)})).ok)throw new Error("Failed to save variant");d&&d("Variant saved successfully"),await b(),g(x),n(S);}catch(u){console.error("Error saving variant",u),i&&i("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");p===c&&g(""),b(),d&&d("Variant deleted successfully");}catch(u){console.error("Error deleting variant",u),i&&i("Failed to delete variant");}},onSetDefault:async c=>{try{let u=w.find(s=>s.id===c);if(!u)return;let x={appId:e,tableKey:o,...u,isDefault:!0};if(!(await fetch(`${l}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(x)})).ok)throw new Error("Failed to set default variant");await b(),d&&d("Default variant updated");}catch(u){console.error("Error setting default variant",u),i&&i("Failed to update default variant");}}})};Pe__default.default.extend(kr__default.default);var Mr=[null,null],co="0.75rem",Rr=material.styled(PickersDay.PickersDay,{shouldForwardProp:e=>e!=="isInRange"&&e!=="isStart"&&e!=="isEnd"&&e!=="isHovered"})(({theme:e,isInRange:o,isStart:t,isEnd:r,isHovered:a})=>({...o&&{borderRadius:0,backgroundColor:e.palette.primary.light,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.main}},...a&&!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%"}})),ua=({label:e="Date Range",value:o=Mr,onChange:t})=>{let[r,a]=Eo.useState(null),[n,l]=Eo.useState(o),[i,d]=Eo.useState("start"),[T,k]=Eo.useState(null),[w,v]=Eo.useState(o[0]||Pe__default.default()),E=Eo__namespace.default.useRef(o);Eo.useEffect(()=>{let[x,C]=o,[s,M]=E.current,S=V=>V&&typeof V.isSame=="function",z=!(x===null&&s===null||S(x)&&S(s)&&x.isSame(s,"day")),B=!(C===null&&M===null||S(C)&&S(M)&&C.isSame(M,"day"));(z||B)&&(l(o),o[0]&&S(o[0])&&v(o[0])),E.current=o;},[o]);let D=x=>{a(x.currentTarget);},p=()=>{a(null),d("start"),k(null);},g=!!r,b=x=>{if(!x)return;let C=[...n];if(i==="start")C=[x,null],d("end");else {let s=C[0];s&&x.isBefore(s)?(C=[x,null],d("end")):(C=[s,x],d("start"));}l(C);},h=x=>{let C=Pe__default.default(),s=[null,null];switch(x){case "today":s=[C,C];break;case "week":s=[C.startOf("week"),C.endOf("week")];break;case "month":s=[C.startOf("month"),C.endOf("month")];break}l(s),d("start"),v(C);},m=()=>{l([null,null]),d("start"),v(Pe__default.default());},y=()=>{t&&t(n),p();},I=()=>{l(o),d("start"),p();},c=Eo.useCallback(x=>{let{day:C,...s}=x,[M,S]=n,z=M?C.isSame(M,"day"):false,B=S?C.isSame(S,"day"):false,V=M&&S?C.isBetween(M,S,"day","()"):false,A=false;return i==="end"&&M&&!S&&T&&C.isAfter(M,"day")&&C.isBefore(T.add(1,"day"),"day")&&(A=true),jsxRuntime.jsx(Rr,{...s,day:C,disableMargin:true,isStart:z,isEnd:B,isInRange:V||A,onMouseEnter:()=>k(C)})},[n,i,T]),u=x=>x?x.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:D,fullWidth:true,size:"small",InputLabelProps:{sx:{fontSize:co}},InputProps:{readOnly:true,sx:{fontSize:co,"& .MuiOutlinedInput-input":{fontSize:co},paddingRight:"4px"},endAdornment:jsxRuntime.jsxs(material.InputAdornment,{position:"end",sx:{ml:0},children:[(n[0]||n[1])&&jsxRuntime.jsx(material.IconButton,{size:"small",onClick:x=>{x.stopPropagation(),m();},edge:"end",sx:{mr:.5,padding:"2px"},children:jsxRuntime.jsx(wr__default.default,{sx:{fontSize:"1rem"}})}),jsxRuntime.jsx(material.IconButton,{size:"small",edge:"end",onClick:D,sx:{padding:"2px"},children:jsxRuntime.jsx(Tr__default.default,{sx:{fontSize:"1rem"},color:"action"})})]})}}),jsxRuntime.jsxs(material.Popover,{open:g,anchorEl:r,onClose:p,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:i==="start"?"primary.main":"divider",borderRadius:1,bgcolor:i==="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(Ir__default.default,{color:"action",fontSize:"small"}),jsxRuntime.jsxs(material.Box,{sx:{p:1,border:1,borderColor:i==="end"?"primary.main":"divider",borderRadius:1,bgcolor:i==="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:()=>h("today"),clickable:true,size:"small",variant:"outlined"}),jsxRuntime.jsx(material.Chip,{label:"This Week",onClick:()=>h("week"),clickable:true,size:"small",variant:"outlined"}),jsxRuntime.jsx(material.Chip,{label:"This Month",onClick:()=>h("month"),clickable:true,size:"small",variant:"outlined"})]})}),jsxRuntime.jsx(DateCalendar.DateCalendar,{value:null,referenceDate:w,onMonthChange:v,onYearChange:v,onChange:b,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:y,children:"Done"})]})]})]})};var wt={equals:"=",contains:"\u2287",notContains:"\u2285",wildcard:"*","=":"=","!=":"!=",">":">","<":"<",">=":"\u2265","<=":"\u2264",between:"\u2194"},Or={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"},zr=["equals","contains","notContains","wildcard"],ga=["=","!=",">","<",">=","<=","between"],J="0.75rem",Gr=({field:e,value:o,onChange:t})=>{let[r,a]=Eo.useState(null),[n,l]=Eo.useState(null),[i,d]=Eo.useState(""),[T,k]=Eo.useState(""),[w,v]=Eo.useState(false),[E,D]=Eo.useState(""),[p,g]=Eo.useState("");Eo.useEffect(()=>{let s=setTimeout(()=>{g(E);},1e3);return ()=>clearTimeout(s)},[E]);let b=o?.operator||(e.type==="number"?"=":"equals"),h=o?.value,m=s=>Or[s]||s,y=s=>{a(s.currentTarget);},I=s=>{t({...o,operator:s,value:h}),a(null);},c={size:"small",fullWidth:true,variant:"outlined",InputLabelProps:{sx:{fontSize:J}},InputProps:{sx:{fontSize:J}},SelectProps:{MenuProps:{PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:J,paddingTop:"4px",paddingBottom:"4px",minHeight:"auto"}}}}}},u=e.type||"text";if(u==="date"){let M=(S=>{if(!S)return [null,null];if(Array.isArray(S)&&S.length===2){let z=S[0]?Pe__default.default.isDayjs(S[0])?S[0]:Pe__default.default(S[0]):null,B=S[1]?Pe__default.default.isDayjs(S[1])?S[1]:Pe__default.default(S[1]):null;return [z,B]}return Pe__default.default.isDayjs(S)||typeof S=="string"?[Pe__default.default.isDayjs(S)?S:Pe__default.default(S),null]:[null,null]})(h);return jsxRuntime.jsx(ua,{label:e.label,value:M,onChange:S=>t({value:S,operator:"between"})})}if(u==="number"&&b==="between"){let s=()=>{t({value:[i,T],operator:"between"}),l(null);},M=Array.isArray(h)?`${h[0]||""} - ${h[1]||""}`:"";return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(material.TextField,{...c,label:e.label,value:M,placeholder:"Min - Max",InputProps:{...c.InputProps,startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(material.Tooltip,{title:m("between"),children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:y,sx:{width:24,height:24,fontSize:J},children:wt.between})})}),readOnly:true},onClick:S=>l(S.currentTarget)}),jsxRuntime.jsx(material.Menu,{anchorEl:r,open:!!r,onClose:()=>a(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:J,minHeight:"auto",py:.5}}},children:ga.map(S=>jsxRuntime.jsxs(material.MenuItem,{selected:S===b,onClick:()=>I(S),children:[jsxRuntime.jsx(material.Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:wt[S]}),jsxRuntime.jsx(material.ListItemText,{primary:m(S),primaryTypographyProps:{fontSize:J}})]},S))}),jsxRuntime.jsx(material.Popover,{open:!!n,anchorEl:n,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:i,onChange:S=>d(S.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:J}},InputProps:{sx:{fontSize:J}}}),jsxRuntime.jsx(Hr__default.default,{color:"action"}),jsxRuntime.jsx(material.TextField,{size:"small",label:"Max",type:"number",value:T,onChange:S=>k(S.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:J}},InputProps:{sx:{fontSize:J}}}),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:h||"",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(h)?h:[],M=e.options?.filter(S=>S.label.toLowerCase().includes(p.toLowerCase()))||[];return jsxRuntime.jsxs(material.TextField,{...c,select:true,label:e.label,value:s,onChange:S=>t({...o,value:S.target.value,operator:"anyOf"}),SelectProps:{...c.SelectProps,multiple:true,onClose:()=>{D(""),g("");},renderValue:S=>{if(!Array.isArray(S)||S.length===0)return jsxRuntime.jsx("em",{children:"None"});let z=V=>e.options?.find(A=>A.value===V)?.label||V,B=S.map(z);return B.length>2?`${B.slice(0,2).join(", ")} +${B.length-2}`:B.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(ma__default.default,{fontSize:"small"})}),sx:{fontSize:J}},value:E,onChange:S=>D(S.target.value),onKeyDown:S=>{S.key!=="Escape"&&S.stopPropagation();},onClick:S=>S.stopPropagation()})}),M.length>0?M.map(S=>jsxRuntime.jsxs(material.MenuItem,{value:S.value,children:[jsxRuntime.jsx(material.Checkbox,{checked:s.indexOf(S.value)>-1,size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:S.label,primaryTypographyProps:{fontSize:J}})]},S.value)):jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.ListItemText,{primary:"No options found",primaryTypographyProps:{fontSize:J}})})]})}let x=u==="number"?ga:zr,C=w||h!==void 0&&h!==""&&h!==null||!!r;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(material.TextField,{...c,label:e.label,sx:{minWidth:"120px"},value:h||"",type:u==="number"?"number":"text",onChange:s=>t({...o,value:s.target.value,operator:b}),onFocus:()=>v(true),onBlur:()=>v(false),InputProps:{...c.InputProps,startAdornment:C?jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(material.Tooltip,{title:m(b),children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:y,onMouseDown:s=>s.preventDefault(),sx:{width:24,height:24,fontSize:J,fontWeight:"bold",color:"primary.main",bgcolor:"action.hover"},children:wt[b]})})}):null,endAdornment:e.hasSearchIcon?jsxRuntime.jsx(material.InputAdornment,{position:"end",children:jsxRuntime.jsx(ma__default.default,{color:"action"})}):void 0}}),jsxRuntime.jsx(material.Menu,{anchorEl:r,open:!!r,onClose:()=>a(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:J,minHeight:"auto",py:.5}}},children:x.map(s=>jsxRuntime.jsxs(material.MenuItem,{selected:s===b,onClick:()=>I(s),children:[jsxRuntime.jsx(material.Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:wt[s]}),jsxRuntime.jsx(material.ListItemText,{primary:m(s),primaryTypographyProps:{fontSize:J}})]},s))})]})},qe=({fields:e,filters:o,onFilterChange:t,variants:r=[],currentVariantId:a,onVariantLoad:n,onVariantSave:l,onVariantDelete:i,onVariantSetDefault:d,onSearch:T,loading:k=false,appId:w,tableKey:v,currentLayout:E,currentLayoutId:D,layoutRefs:p,variantService:g})=>{let[b,h]=Eo.useState(true),[m,y]=Eo.useState(null),[I,c]=Eo.useState(e.filter(s=>!s.hidden).map(s=>s.id)),u=(s,M)=>{t({...o,[s]:M});},x=s=>{I.includes(s)?c(I.filter(M=>M!==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(sa,{appId:w,tableKey:v,currentFilters:{values:o,visibleFields:I},currentLayout:E,currentLayoutId:D,layoutRefs:p,onLoad:s=>{if(!s.filters)return;let M=null;if(Array.isArray(s.filters)){let S=v||"default",z=s.filters.find(B=>B.scope===S);M=z?z.filters:null;}else M=s.filters;M&&(M.values||M.visibleFields?(M.visibleFields&&Array.isArray(M.visibleFields)&&c(M.visibleFields),M.values&&t(M.values)):t(M)),n&&n(s);},variantService:g,currentVariantId:a}):jsxRuntime.jsx(Ct,{variants:r,currentVariantId:a,onLoad:n,onSave:s=>{l&&l({...s,filters:{values:o,visibleFields:I}});},onDelete:i,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=>y(s.currentTarget),size:"small",color:"primary",startIcon:jsxRuntime.jsx(Fr__default.default,{fontSize:"small"}),sx:{textTransform:"none",fontSize:J},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:m,open:!!m,onClose:()=>y(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:()=>x(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:b,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(Gr,{field:s,value:o[s.id]||{value:"",operator:s.type==="number"?"=":"equals"},onChange:M=>u(s.id,M)})},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:()=>h(!b),sx:{bgcolor:"background.paper",boxShadow:2,border:"1px solid",borderColor:"divider",width:20,height:20,minHeight:0,p:0,"&:hover":{bgcolor:"background.paper"}},children:b?jsxRuntime.jsx(Vr__default.default,{sx:{fontSize:16},color:"action"}):jsxRuntime.jsx(wn__default.default,{sx:{fontSize:16},color:"action"})})})]})};var Sa=({layouts:e,currentLayoutId:o,onLoad:t,onSave:r,onDelete:a,onSetDefault:n})=>{let[l,i]=Eo.useState(null),[d,T]=Eo.useState(false),[k,w]=Eo.useState(""),[v,E]=Eo.useState(""),[D,p]=Eo.useState({isDefault:false,isPublic:false}),g=e.find(c=>c.id===o),b=c=>{i(c.currentTarget);},h=()=>{i(null);},m=c=>{t(c),h();},y=()=>{w(""),E(""),p({isDefault:false,isPublic:false}),T(true),h();},I=()=>{k.trim()&&(r({name:k,description:v,...D}),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:y,color:"primary",size:"small",children:jsxRuntime.jsx(va__default.default,{})})}),jsxRuntime.jsx(material.Tooltip,{title:"Layout Options",children:jsxRuntime.jsx(material.IconButton,{onClick:b,color:g?"primary":"default",children:jsxRuntime.jsx(Qr__default.default,{})})}),jsxRuntime.jsxs(material.Menu,{anchorEl:l,open:!!l,onClose:h,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:y,children:[jsxRuntime.jsx(material.ListItemIcon,{children:jsxRuntime.jsx(va__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:()=>m(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:x=>x.stopPropagation(),children:[jsxRuntime.jsx(material.Tooltip,{title:c.isDefault?"Remove Default":"Set as Default",children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:x=>{x.stopPropagation(),n(c.id);},children:c.isDefault?jsxRuntime.jsx(sr__default.default,{fontSize:"small",color:"warning"}):jsxRuntime.jsx(Zr__default.default,{fontSize:"small"})})}),jsxRuntime.jsx(material.Tooltip,{title:"Delete",children:jsxRuntime.jsx(material.IconButton,{size:"small",color:"error",onClick:x=>{x.stopPropagation(),a(c.id);},children:jsxRuntime.jsx(Xr__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:v,onChange:c=>E(c.target.value),fullWidth:true,size:"small"}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:D.isDefault,onChange:c=>p({...D,isDefault:c.target.checked})}),label:"Use as Default Layout"}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:D.isPublic,onChange:c=>p({...D,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 ei="http://127.0.0.1:8515",wa=({appId:e,tableKey:o="default",currentLayoutData:t,onLayoutLoad:r,targetLayoutId:a,activeLayoutId:n,serviceUrl:l=ei,onError:i,onSuccess:d})=>{let[T,k]=Eo.useState([]),[w,v]=Eo.useState(""),E=`orbcafe.layouts.${e}.${o}`,D=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??{}}),p=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}),g=Eo.useCallback(()=>{try{let u=localStorage.getItem(E);if(!u)return [];let x=JSON.parse(u);return Array.isArray(x)?x:[]}catch{return []}},[E]),b=Eo.useCallback(u=>{try{localStorage.setItem(E,JSON.stringify(u));}catch{}},[E]);Eo.useEffect(()=>{n!==void 0&&v(n);},[n]),Eo.useEffect(()=>{if(a&&T.length>0){let u=T.find(x=>x.id===a);u&&(v(u.id),r(u));}},[a,T,r]);let h=Eo.useCallback(async()=>{if(e)try{let u=await fetch(`${l}/api/layouts?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!u.ok)throw new Error("Failed to fetch layouts");let C=(await u.json()).map(D);k(C);let s=C.find(M=>M.isDefault);s&&!w&&!a&&(v(s.id),r(s));}catch(u){console.error("Error fetching layouts",u);let x=g();k(x);let C=x.find(s=>s.isDefault);C&&!w&&!a&&(v(C.id),r(C)),i&&i("Failed to load layouts from backend, fallback to local storage");}},[e,o,l,i,w,r,a,g]);return Eo.useEffect(()=>{h();},[e,o]),jsxRuntime.jsx(Sa,{layouts:T,currentLayoutId:w,onLoad:u=>{v(u.id),r(u);},onSave:async u=>{let x=T.find(M=>M.name===u.name),C=x?x.id:Date.now().toString(),s={id:C,...u,createdAt:new Date().toISOString(),layoutData:t,isDefault:u.isDefault??false,isPublic:u.isPublic??false};try{if(!(await fetch(`${l}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(p(s))})).ok)throw new Error("Failed to save layout");d&&d("Layout saved successfully"),await h(),v(C),r(s);}catch(M){console.error("Error saving layout",M);let z=T.some(B=>B.id===C)?T.map(B=>B.id===C?s:B):[...T,s];k(z),b(z),v(C),r(s),d&&d("Layout saved to local storage"),i&&i("Backend unavailable, saved to local storage");}},onDelete:async u=>{try{if(!(await fetch(`${l}/api/layouts/${encodeURIComponent(u)}`,{method:"DELETE"})).ok)throw new Error("Failed to delete layout");w===u&&v(""),d&&d("Layout deleted successfully"),await h();}catch(x){console.error("Error deleting layout",x);let C=T.filter(s=>s.id!==u);k(C),b(C),w===u&&v(""),d&&d("Layout deleted from local storage"),i&&i("Backend unavailable, deleted from local storage");}},onSetDefault:async u=>{try{let x=T.find(s=>s.id===u);if(!x)return;if(!(await fetch(`${l}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(p({...x,isDefault:!0}))})).ok)throw new Error("Failed to set default layout");d&&d("Default layout set"),await h();}catch(x){console.error("Error setting default",x);let C=T.map(s=>({...s,isDefault:s.id===u}));k(C),b(C),d&&d("Default layout set in local storage"),i&&i("Backend unavailable, default saved to local storage");}}})};function ka(e,o,t){return o[t]<e[t]?-1:o[t]>e[t]?1:0}function oi(e,o){return e==="desc"?(t,r)=>ka(t,r,o):(t,r)=>-ka(t,r,o)}function ai(e,o){let t=e.map((r,a)=>[r,a]);return t.sort((r,a)=>{let n=o(r[0],a[0]);return n!==0?n:r[1]-a[1]}),t.map(r=>r[0])}var Ma=e=>{let o=Eo.useCallback(f=>{let L=String(f?.label??f?.id??"").length*9+64,ee=typeof f?.minWidth=="number"?f.minWidth:0;return Math.max(100,ee,L)},[]),[t,r]=Eo.useState(""),[a,n]=Eo.useState(e.order||"asc"),[l,i]=Eo.useState(e.orderBy||""),[d,T]=Eo.useState(e.page||0),[k,w]=Eo.useState(e.rowsPerPage||20),[v,E]=Eo.useState(e.selected||[]),[D,p]=Eo.useState(e.columns?e.columns.map(f=>f.id):[]),[g,b]=Eo.useState(e.showSummary||false),[h,m]=Eo.useState([]),[y,I]=Eo.useState(new Set),[c,u]=Eo.useState(()=>{let f={};return (e.columns||[]).forEach(R=>{f[R.id]=o(R);}),f}),[x,C]=Eo.useState(null),[s,M]=Eo.useState(null),[S,z]=Eo.useState(null),[B,V]=Eo.useState(null),[A,N]=Eo.useState(false),[te,Oe]=Eo.useState("");Eo.useEffect(()=>{e.order!==void 0&&n(e.order),e.orderBy!==void 0&&i(e.orderBy);},[e.order,e.orderBy]),Eo.useEffect(()=>{e.selected!==void 0&&E(e.selected);},[e.selected]),Eo.useEffect(()=>{e.page!==void 0&&T(e.page);},[e.page]),Eo.useEffect(()=>{u(f=>{let R={...f};return (e.columns||[]).forEach(L=>{R[L.id]===void 0&&(R[L.id]=o(L));}),R});},[e.columns,o]);let oe=Eo.useMemo(()=>{let f=e.rows||[];return t&&(f=f.filter(R=>Object.keys(R).some(L=>String(R[L]).toLowerCase().includes(t.toLowerCase())))),f},[e.rows,t]),re=Eo.useMemo(()=>e.onSortChange||!l?oe:ai(oe,oi(a,l)),[oe,a,l,e.onSortChange]),ie=Eo.useCallback(f=>{if(h.length===0)return f.map(K=>({type:"row",data:K,id:K[e.rowKey||"id"]}));let R=[...f].sort((K,Y)=>{for(let W of h){if(K[W]<Y[W])return -1;if(K[W]>Y[W])return 1}return 0}),L=(K,Y=0)=>{if(Y>=h.length)return K;let W=h[Y],j={},ge=[];return K.forEach(se=>{let Be=se[W],ce=`${W}:${Be}`;j[ce]||(j[ce]={key:ce,field:W,value:Be,children:[],count:0,level:Y},ge.push(j[ce])),j[ce].children.push(se),j[ce].count++;}),ge.forEach(se=>{se.children&&(se.children=L(se.children,Y+1));}),ge},ee=L(R),G=(K,Y="")=>{let W=[];return K.forEach(j=>{if(j.children){let ge=Y?`${Y}>${j.key}`:j.key,se=y.has(ge);W.push({type:"group",id:ge,field:j.field,value:j.value,level:j.level,count:j.count,isExpanded:se,childIds:(function Be(ce){let ve=[];return ce.children.forEach(We=>{We.children?ve=ve.concat(Be(We)):ve.push(We[e.rowKey||"id"]);}),ve})(j)}),se&&(W=W.concat(G(j.children,ge)));}else W.push({type:"row",data:j,id:j[e.rowKey||"id"],level:h.length});}),W};return G(ee)},[h,y,e.rowKey]),Re=Eo.useMemo(()=>ie(re),[re,ie]),at=Eo.useMemo(()=>k>0?Re.slice(d*k,d*k+k):Re,[Re,d,k]),nt=f=>{let R=new Set(y);R.has(f)?R.delete(f):R.add(f),I(R);},ze=f=>{nt(f);},Lt=f=>{let R=new Set(y);Array.from(R).forEach(L=>{L.startsWith(f)&&R.delete(L);}),I(R);},At=f=>{f||I(new Set);},Ge=f=>{let R=l===f&&a==="asc",L=l===f&&a==="desc";if(e.onSortChange){R?e.onSortChange(f,"desc"):L?e.onSortChange("","asc"):e.onSortChange(f,"asc");return}R?(n("desc"),i(f)):L?(n("asc"),i("")):(n("asc"),i(f));},rt=(f,R)=>{u(L=>({...L,[f]:R}));},Ft=f=>{if(f.target.checked){let R=oe.map(L=>L[e.rowKey||"id"]);E(R),e.onSelectionChange&&e.onSelectionChange(R);return}E([]),e.onSelectionChange&&e.onSelectionChange([]);},Vt=(f,R)=>{let L=R[e.rowKey||"id"],ee=v.indexOf(L),G=[];ee===-1?G=G.concat(v,L):ee===0?G=G.concat(v.slice(1)):ee===v.length-1?G=G.concat(v.slice(0,-1)):ee>0&&(G=G.concat(v.slice(0,ee),v.slice(ee+1))),E(G),e.onSelectionChange&&e.onSelectionChange(G);},it=f=>{T(f),e.onPageChange&&e.onPageChange(f);},lt=f=>{w(f),T(0),e.onRowsPerPageChange&&e.onRowsPerPageChange(f);},Nt=f=>{let R=D.indexOf(f),L=[...D];R===-1?L.push(f):L.splice(R,1),p(L);},st=f=>{let R=h.indexOf(f),L=[...h];R===-1?L.push(f):L.splice(R,1),m(L);},Ht=f=>{e.onLayoutSave&&e.onLayoutSave({visibleColumns:D,order:a,orderBy:l,grouping:h,columnWidths:c});},ct=f=>{f.layout&&(f.layout.visibleColumns&&p(f.layout.visibleColumns),f.layout.order&&n(f.layout.order),f.layout.orderBy&&i(f.layout.orderBy),f.layout.grouping&&m(f.layout.grouping),f.layout.columnWidths&&u(f.layout.columnWidths));},Ot=f=>{let R=f?.layoutData||f?.layout||f||{};R.visibleColumns&&p(R.visibleColumns),R.order&&n(R.order),R.orderBy!==void 0&&i(R.orderBy),R.grouping&&m(R.grouping),R.columnWidths&&u(R.columnWidths),R.showSummary!==void 0&&b(!!R.showSummary),I(new Set),T(0),f?.id&&Oe(f.id);};Eo.useEffect(()=>{e.layout&&ct({layout:e.layout});},[e.layout]);let zt=f=>{f.preventDefault(),V(B===null?{mouseX:f.clientX+2,mouseY:f.clientY-6}:null);},Gt=()=>{V(null);},dt=Eo.useMemo(()=>{if(!g)return {};let f={};e.columns.forEach(L=>{if(L.numeric){let ee=oe.reduce((G,K)=>{let Y=parseFloat(K[L.id]);return G+(isNaN(Y)?0:Y)},0);f[L.id]=ee.toFixed(2);}else f[L.id]="";});let R=e.columns.find(L=>D.includes(L.id));return R&&!R.numeric&&(f[R.id]="Total"),f},[oe,e.columns,g,D]),Wt=()=>{if(!e.columns||!oe)return;let f=e.columns.map(K=>K.label).join(","),R=oe.map(K=>e.columns.map(Y=>{let W=K[Y.id];return `"${(W==null?"":String(W)).replace(/"/g,'""')}"`}).join(",")).join(`
|
|
2
|
+
`),L=`data:text/csv;charset=utf-8,${f}
|
|
3
|
+
${R}`,ee=encodeURI(L),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);},$t=()=>{N(true);},_t=()=>{N(false);};return {isMobile:false,columns:e.columns,order:a,orderBy:l,filterText:t,setFilterText:r,visibleColumns:D,setVisibleColumns:p,showSummary:g,setShowSummary:b,summaryColumns:[],grouping:h,setGrouping:m,expandedGroups:y,setExpandedGroups:I,groupAnchorEl:s,setGroupAnchorEl:M,summaryAnchorEl:S,setSummaryAnchorEl:z,columnWidths:c,setColumnWidths:u,anchorEl:x,setAnchorEl:C,contextMenu:B,setContextMenu:V,sensors:void 0,sortedAndFilteredRows:re,visibleRows:at,summaryRow:dt,page:d,setPage:it,rowsPerPage:k,setRowsPerPage:lt,selected:v,setSelected:E,isAllExpanded:false,handleColumnResize:rt,handleRequestSort:Ge,handleSelectAllClick:Ft,handleClick:Vt,toggleSummaryColumn:()=>{},handleDragEnd:()=>{},handleExport:Wt,handleContextMenu:zt,handleCloseContextMenu:Gt,toggleColumnVisibility:Nt,toggleGroupExpand:nt,toggleGroupField:st,handleToggleAll:At,handleExpandGroupRecursively:ze,handleCollapseGroupRecursively:Lt,handleLayoutLoad:Ot,handleVariantLoad:ct,handleLayoutSave:Ht,effectiveAppId:e.appId||"",currentLayoutData:{visibleColumns:D,order:a,orderBy:l,grouping:h,columnWidths:c},currentLayoutId:te,layoutIdToLoad:"",onPageChange:it,onRowsPerPageChange:lt,graphReportOpen:A,handleOpenGraphReport:$t,handleCloseGraphReport:_t}};var Ac=e=>jsxRuntime.jsx(ii__default.default,{...e}),Fc=e=>jsxRuntime.jsx(Ao__default.default,{...e}),Vc=e=>jsxRuntime.jsx(Ra__default.default,{...e}),Nc=e=>jsxRuntime.jsx(fn__default.default,{...e}),Hc=e=>jsxRuntime.jsx(yn__default.default,{...e}),Rt=e=>{let{title:o="Data Table",showToolbar:t=true,selectionMode:r,selected:a=[],onSelectionChange:n,actions:l,extraTools:i,fitContainer:d=false,fullWidth:T=false,maxHeight:k,loading:w=false,page:v=0,rowsPerPage:E=20,rowsPerPageOptions:D=[20,50,100,-1],count:p=0,onPageChange:g,onRowsPerPageChange:b,onLayoutSave:h,filterConfig:m,rowKey:y,tableKey:I="default",graphReport:c}=e,{isMobile:u,columns:x,order:C,orderBy:s,filterText:M,setFilterText:S,visibleColumns:z,showSummary:B,setShowSummary:V,summaryColumns:A,grouping:N,setGrouping:te,expandedGroups:Oe,groupAnchorEl:oe,setGroupAnchorEl:re,summaryAnchorEl:ie,setSummaryAnchorEl:Re,columnWidths:at,anchorEl:nt,setAnchorEl:ze,contextMenu:Lt,sensors:At,sortedAndFilteredRows:Ge,summaryRow:rt,visibleRows:Ft,isAllExpanded:Vt,handleColumnResize:it,handleRequestSort:lt,handleSelectAllClick:Nt,handleClick:st,toggleSummaryColumn:Ht,handleDragEnd:ct,handleExport:Ot,handleContextMenu:zt,handleCloseContextMenu:Gt,toggleColumnVisibility:dt,toggleGroupExpand:Wt,toggleGroupField:$t,handleToggleAll:_t,handleExpandGroupRecursively:f,handleCollapseGroupRecursively:R,handleLayoutLoad:L,handleVariantLoad:ee,handleLayoutSave:G,effectiveAppId:K,currentLayoutData:Y,currentLayoutId:W,layoutIdToLoad:j,graphReportOpen:ge,handleOpenGraphReport:se,handleCloseGraphReport:Be}=Ma(e),ce=c?.enabled??false,{model:ve}=ta({rows:Ge,config:{...c,title:c?.title||`${o} Graphic Report`}}),We=ve.table.columns.map(ut=>({id:ut.id,label:ut.label,align:ut.align||"left",minWidth:120,numeric:ut.align==="right"})),Va=K?jsxRuntime.jsx(wa,{appId:K,tableKey:I,currentLayoutData:Y,onLayoutLoad:L,targetLayoutId:j,activeLayoutId:W,serviceUrl:(m?.variantService,void 0)}):null,Co=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(jo,{groupAnchorEl:oe,setGroupAnchorEl:re,grouping:N,setGrouping:te,columns:x,toggleGroupField:$t}),jsxRuntime.jsx(Uo,{anchorEl:nt,setAnchorEl:ze,columns:x,visibleColumns:z,toggleColumnVisibility:dt}),jsxRuntime.jsx(Ko,{anchorEl:ie,setAnchorEl:Re,showSummary:B,setShowSummary:V,columns:x,summaryColumns:A,toggleSummaryColumn:Ht}),jsxRuntime.jsx(Yo,{contextMenu:Lt,handleCloseContextMenu:Gt,columns:x,visibleColumns:z,toggleColumnVisibility:dt})]});return u?jsxRuntime.jsxs(ho__default.default,{sx:{display:"flex",flexDirection:"column",gap:2,height:"100%"},children:[m&&jsxRuntime.jsx(qe,{fields:m.fields,filters:m.filters,onFilterChange:m.onFilterChange,onSearch:m.onSearch,variants:m.variants||[],currentVariantId:m.currentVariantId,onVariantLoad:m.onVariantLoad,onVariantSave:m.onVariantSave,onVariantDelete:m.onVariantDelete,onVariantSetDefault:m.onVariantSetDefault,appId:m.appId,tableKey:I,currentLayout:[{tableKey:I,layoutData:Y}],variantService:m.variantService}),jsxRuntime.jsx($o,{title:o,loading:w,showSummary:B,setShowSummary:V,setAnchorEl:ze,setSummaryAnchorEl:Re,filterText:M,setFilterText:S,sortedAndFilteredRows:Ge,selected:a,columns:x,visibleColumns:z,summaryRow:rt,handleClick:st,selectionMode:r}),Co]}):jsxRuntime.jsxs(ho__default.default,{sx:{width:T?"100%":"auto",mb:d?0:2,...d?{flex:1,display:"flex",flexDirection:"column",minHeight:0,height:"100%"}:{}},children:[m&&jsxRuntime.jsx(ho__default.default,{sx:{mb:2},children:jsxRuntime.jsx(qe,{fields:m.fields,filters:m.filters,onFilterChange:m.onFilterChange,onSearch:m.onSearch,variants:m.variants||[],currentVariantId:m.currentVariantId,onVariantLoad:ee,onVariantSave:m.onVariantSave,onVariantDelete:m.onVariantDelete,onVariantSetDefault:m.onVariantSetDefault,loading:w,appId:m.appId,tableKey:I,currentLayout:[{tableKey:I,layoutData:Y}],currentLayoutId:W,layoutRefs:[{tableKey:I,layoutId:W}],variantService:m.variantService})}),jsxRuntime.jsxs(ni__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:M,setFilterText:S,onRowsPerPageChange:b,rowsPerPage:E,rowsPerPageOptions:D,page:v,count:p,onPageChange:g,actions:l,extraTools:i,grouping:N,setGroupAnchorEl:re,showSummary:B,setShowSummary:V,setAnchorEl:ze,setSummaryAnchorEl:Re,handleExport:Ot,onLayoutSave:h||m?.variantService&&m?.appId?G:void 0,loading:w,layoutManager:Va,onOpenGraphReport:ce?se:void 0}),jsxRuntime.jsx(Ra__default.default,{sx:{flex:1,maxHeight:k||"calc(100vh - 320px)",overflowY:"auto",overflowX:"auto",position:"relative",minHeight:0},children:jsxRuntime.jsx(core.DndContext,{sensors:At,collisionDetection:core.closestCenter,onDragEnd:ct,modifiers:[modifiers.restrictToHorizontalAxis],children:jsxRuntime.jsxs(ri__default.default,{sx:{minWidth:T?750:"auto",width:T?"100%":"auto",tableLayout:Object.keys(at).length>0?"fixed":"auto",borderCollapse:"separate",borderSpacing:0},"aria-labelledby":"tableTitle",size:"small",stickyHeader:true,children:[jsxRuntime.jsx(No,{columns:x,visibleColumns:z,order:C,orderBy:s,onRequestSort:lt,onContextMenu:zt,selectionMode:r,grouping:N,isAllExpanded:Vt,handleToggleAll:_t,rowCount:Ge.length,numSelected:a.length,onSelectAllClick:Nt,columnWidths:at,onColumnResize:it}),jsxRuntime.jsx(Oo,{visibleRows:Ft,columns:x,visibleColumns:z,selectionMode:r,selected:a,orderBy:s,loading:w,expandedGroups:Oe,toggleGroupExpand:Wt,handleExpandGroupRecursively:f,handleCollapseGroupRecursively:R,handleClick:st,onSelectionChange:n,grouping:N,rowKeyProp:y,page:v,rowsPerPage:E}),B&&jsxRuntime.jsx(Go,{showSummary:B,columns:x,visibleColumns:z,summaryRow:rt,selectionMode:r?.toString(),orderBy:s,zIndex:3})]})})})]}),Co,ce&&jsxRuntime.jsx(Qo,{open:ge,onClose:Be,model:ve,tableContent:jsxRuntime.jsx(Rt,{title:"Data Body",columns:We,rows:ve.table.rows,rowKey:"id",fullWidth:true,maxHeight:"420px",rowsPerPage:20,rowsPerPageOptions:[20,50,100],graphReport:{enabled:false}})})]})},Oc=Rt;var Uc=({title:e,hideHeader:o=true,filterConfig:t,tableProps:r,children:a,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(qe,{...t})}),jsxRuntime.jsx(material.Box,{sx:{flex:1,minHeight:0,overflow:"hidden"},children:jsxRuntime.jsx(Rt,{...r,fitContainer:true,filterConfig:void 0})})]}),a]});var Xc=({metadata:e,fetchData:o})=>{let[t,r]=Eo.useState(false),[a,n]=Eo.useState([]),[l,i]=Eo.useState({}),[d,T]=Eo.useState(e.variants||[]),[k,w]=Eo.useState(e.layout||null),[v,E]=Eo.useState(0),[D,p]=Eo.useState(0),[g,b]=Eo.useState(10),[h,m]=Eo.useState([]),[y,I]=Eo.useState("asc"),[c,u]=Eo.useState("");Eo.useEffect(()=>{let A={};e.filters.forEach(N=>{N.defaultValue!==void 0&&(A[N.id]=N.defaultValue);}),i(A);},[e.filters]);let x=Eo.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]);Eo.useEffect(()=>{x(l,D,g,y,c);},[x,D,g,y,c]);let C=()=>{p(0),x(l,0,g,y,c);},s=(A,N)=>{I(N),u(A);},M=A=>{i(A);},S=A=>{if(A.filters){let N=A.filters.find(te=>te.scope==="default"||te.scope===e.id);N&&(i(N.filters),x(N.filters,0,g));}A.layout&&w(A.layout);},z=A=>{let N={...A,id:Date.now().toString(),createdAt:new Date().toISOString()};T(te=>[...te,N]);},B=A=>{w(A);};return {pageProps:{title:e.title,filterConfig:{appId:e.id,fields:e.filters,filters:l,onFilterChange:M,onSearch:C,onVariantLoad:S,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:a,loading:t,rowKey:"id",count:v,page:D,rowsPerPage:g,rowsPerPageOptions:[10,25,50,100],onPageChange:p,onRowsPerPageChange:b,selectionMode:"multiple",selected:h,onSelectionChange:m,onLayoutSave:B,layout:k,title:e.title,showSummary:true,order:y,orderBy:c,onSortChange:s,graphReport:e.graphReport||{enabled:true,title:`${e.title} Graphic Report`}}},filters:l,rows:a,loading:t,refresh:C}};var Ba=64,Di="#E9EDF2",Pi="linear-gradient(90deg, #F5F7FA 0%, #E9EDF2 50%, #F5F7FA 100%)",La=({appTitle:e,logo:o,mode:t="dark",onToggleMode:r,localeLabel:a="EN",searchPlaceholder:n="Ask me...",onSearch:l,user:i,leftSlot:d,rightSlot:T})=>{let w=material.useTheme().palette.mode==="dark",[v,E]=Eo.useState(""),D=b=>{b.preventDefault(),l&&l(v.trim());},p=t==="system"?jsxRuntime.jsx(ki__default.default,{fontSize:"small"}):t==="dark"?jsxRuntime.jsx(Mi__default.default,{fontSize:"small"}):jsxRuntime.jsx(Ri__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:b=>({top:0,zIndex:b.zIndex.drawer+10,height:Ba,backgroundColor:b.palette.mode==="dark"?"#0D0D0D":Di,backgroundImage:b.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%)",Pi,"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:b.palette.mode==="dark"?"rgba(255,255,255,0.12)":"rgba(15,23,42,0.12)"}),children:jsxRuntime.jsxs(material.Toolbar,{sx:{minHeight:`${Ba}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:D,sx:{width:"100%",maxWidth:540},children:jsxRuntime.jsx(material.TextField,{size:"small",fullWidth:true,value:v,onChange:b=>E(b.target.value),placeholder:n,InputProps:{startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(ma__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(Ii__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:a})]}),jsxRuntime.jsx(material.IconButton,{size:"small",sx:{color:w?"common.white":"#111827"},onClick:r,title:g,children:p}),i&&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:w?"common.white":"#111827",fontWeight:600,lineHeight:1.2},children:i.name})}),jsxRuntime.jsx(material.Avatar,{src:i.avatarSrc,imgProps:{style:{objectFit:"cover"}},sx:{width:34,height:34,bgcolor:"grey.100",color:"grey.700",fontSize:"0.85rem"},children:i.avatarText||i.name.slice(0,1).toUpperCase()})]}),T]})]})})};var Aa=({menuData:e=[],initialNavigationCollapsed:o=false}={})=>{let{navigationIslandProps:t}=Do({initialCollapsed:o,content:e}),[r,a]=Eo.useState(900);Eo.useEffect(()=>{let l=()=>a(window.innerHeight);return l(),window.addEventListener("resize",l),()=>window.removeEventListener("resize",l)},[]);let n=Eo.useMemo(()=>Math.max(280,r-100),[r]);return {navigationIslandProps:t,navigationMaxHeight:n}};var yd=({appTitle:e,menuData:o=[],children:t,showNavigation:r=true,localeLabel:a,user:n,logo:l,onSearch:i,rightHeaderSlot:d,leftHeaderSlot:T,contentSx:k})=>{let[w,v]=Eo.useState("system"),[E,D]=Eo.useState("light"),[p,g]=Eo.useState(false),b=w==="system"?p?E:"light":w;Eo.useEffect(()=>{g(true);let I=window.matchMedia("(prefers-color-scheme: dark)"),c=()=>{D(I.matches?"dark":"light");};return c(),I.addEventListener("change",c),()=>I.removeEventListener("change",c)},[]);let h=Eo.useMemo(()=>material.createTheme({palette:{mode:b}}),[b]),{navigationIslandProps:m,navigationMaxHeight:y}=Aa({menuData:o,initialNavigationCollapsed:false});return jsxRuntime.jsx(material.ThemeProvider,{theme:h,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(La,{appTitle:e,logo:l,mode:w,onToggleMode:()=>v(I=>I==="system"?"dark":I==="dark"?"light":"system"),localeLabel:a,user:n,onSearch:i,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,{...m,maxHeight:y,colorMode:b})}),jsxRuntime.jsx(material.Box,{sx:{flex:1,minWidth:0,minHeight:0,overflow:"auto",p:1.5,...k},children:t})]})]})})};exports.Button=Ut;exports.CAppHeader=La;exports.CAppPageLayout=yd;exports.CLayoutManagement=Sa;exports.CLayoutManager=wa;exports.CPageLayout=Po;exports.CSmartFilter=qe;exports.CSmartTable=Oc;exports.CStandardPage=Uc;exports.CTable=Rt;exports.CTableBody=Ac;exports.CTableCell=Fc;exports.CTableContainer=Vc;exports.CTableHead=Nc;exports.CTableRow=Hc;exports.CVariantManagement=Ct;exports.CVariantManager=sa;exports.NavigationIsland=Mo;exports.TreeMenu=Yt;exports.buttonVariants=Ga;exports.useNavigationIsland=Do;exports.usePageLayout=Aa;exports.useStandardReport=Xc;
|
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&<({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,${
|
|
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 Eo from'react';import Eo__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 ho from'@mui/material/Box';import ni from'@mui/material/Paper';import ri from'@mui/material/Table';import ii from'@mui/material/TableBody';import Ao from'@mui/material/TableCell';import Ra from'@mui/material/TableContainer';import fn from'@mui/material/TableHead';import yn from'@mui/material/TableRow';import {DndContext,closestCenter}from'@dnd-kit/core';import {restrictToHorizontalAxis}from'@dnd-kit/modifiers';import ma from'@mui/icons-material/Search';import rn from'@mui/icons-material/ViewColumn';import va from'@mui/icons-material/Save';import sn from'@mui/icons-material/Download';import cn from'@mui/icons-material/AccountTree';import dn from'@mui/icons-material/Functions';import un from'@mui/icons-material/Insights';import hn from'@mui/material/Checkbox';import bn from'@mui/material/TableSortLabel';import Tn from'@mui/icons-material/KeyboardArrowRight';import wn from'@mui/icons-material/KeyboardArrowDown';import Vn from'@mui/icons-material/Check';import Nn from'@mui/icons-material/ClearAll';import qn from'@mui/icons-material/Close';import Fr from'@mui/icons-material/Settings';import Vr from'@mui/icons-material/KeyboardArrowUp';import Hr from'@mui/icons-material/ArrowRightAlt';import sr from'@mui/icons-material/Star';import {DateCalendar}from'@mui/x-date-pickers/DateCalendar';import {PickersDay}from'@mui/x-date-pickers/PickersDay';import Tr from'@mui/icons-material/CalendarMonth';import wr from'@mui/icons-material/Clear';import Ir from'@mui/icons-material/ArrowForward';import Pe from'dayjs';import kr from'dayjs/plugin/isBetween';import Xr from'@mui/icons-material/Delete';import Zr from'@mui/icons-material/StarBorder';import Qr from'@mui/icons-material/ViewQuilt';import Ii from'@mui/icons-material/Language';import ki from'@mui/icons-material/DesktopWindows';import Mi from'@mui/icons-material/DarkMode';import Ri from'@mui/icons-material/LightMode';function le(...e){return twMerge(clsx(e))}var jt={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 Ga=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-[${jt.primary}] hover:bg-[${jt.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"}}),Ut=Eo.forwardRef(({className:e,variant:o,size:t,asChild:r=false,...a},n)=>jsx(r?Slot:"button",{className:le(Ga({variant:o,size:t,className:e})),ref:n,...a}));Ut.displayName="Button";function Yt({items:e,onItemClick:o,className:t="",level:r=0,expandedIds:a,onToggleExpand:n,colorMode:l="light"}){let i=l==="dark",d=usePathname(),[T,k]=useState(new Set),w=a!==void 0&&n!==void 0,v=w?a:T,E=p=>{if(w)n(p);else {let g=new Set(T);g.has(p)?g.delete(p):g.add(p),k(g);}},D=p=>{p.children&&p.children.length>0&&E(p.id),o&&o(p);};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(p=>{let g=v.has(p.id)||p.isExpanded,b=p.children&&p.children.length>0,h=p.appurl||p.href,m=h?d===h:false;return jsxs("div",{className:"tree-menu-item relative",children:[m&&jsx("div",{className:le("absolute left-0 top-2 bottom-2 w-[3px] rounded-r-full z-10",i?"bg-[#90caf9]":"bg-[#1976d2]")}),jsxs(Ut,{variant:"ghost",className:le("w-full justify-start gap-2 h-auto py-2 relative overflow-hidden group",`ml-${r*4}`,m?i?"bg-transparent text-[#90caf9] hover:bg-gray-800/35":"bg-transparent text-[#1976d2] hover:bg-gray-100/60":i?"hover:bg-gray-800/50 text-gray-300":"hover:bg-gray-100/50 text-gray-700"),onClick:()=>D(p),children:[b&&jsx("div",{className:le("flex-shrink-0 transition-transform duration-200",g&&"rotate-90",m?i?"text-[#90caf9]":"text-[#1976d2]":i?"text-gray-500 group-hover:text-gray-300":"text-gray-400 group-hover:text-gray-600"),children:jsx(ChevronRight,{className:"h-4 w-4"})}),!b&&jsx("div",{className:"w-4 h-4 flex-shrink-0"}),p.icon&&jsx("div",{className:le("flex-shrink-0 transition-colors duration-200",m?i?"text-[#90caf9]":"text-[#1976d2]":i?"text-gray-500 group-hover:text-gray-300":"text-gray-400 group-hover:text-gray-600"),children:p.icon}),jsxs("div",{className:"flex-1 text-left overflow-hidden z-10",children:[jsx("div",{className:le("text-sm truncate transition-colors duration-200",m?"font-semibold":"font-medium"),children:p.title||p.label}),p.description&&jsx("div",{className:le("text-xs truncate transition-colors duration-200",m?i?"text-[#90caf9]/70":"text-[#1976d2]/75":i?"text-gray-400":"text-gray-500"),title:p.description,children:p.description})]})]}),b&&jsx("div",{className:le("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(Yt,{items:p.children,onItemClick:o,level:r+1,expandedIds:a,onToggleExpand:n,colorMode:l})})})]},p.id)})})}var Mo=({collapsed:e,onToggle:o,className:t="",maxHeight:r,menuData:a=[],colorMode:n="light"})=>{let l=n==="dark",i=useRouter(),[d,T]=useState(""),[k,w]=useState(new Set);useEffect(()=>{e&&w(new Set);},[e]);let v=useCallback(g=>{let b=[],h=m=>{m.forEach(y=>{b.push(y.id),y.children&&h(y.children);});};return h(g),b},[]),E=useMemo(()=>{if(!d.trim())return a;let g=b=>b.reduce((h,m)=>{let y=m.title?.toLowerCase().includes(d.toLowerCase())||m.description?.toLowerCase().includes(d.toLowerCase()),I=m.children?g(m.children):[];return (y||I.length>0)&&h.push({...m,children:I.length>0?I:m.children}),h},[]);return g(a)},[d,a]),D=useMemo(()=>d.trim()?new Set(v(a)):k,[d,a,k,v]),p=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{i.push("/chat?new=true");}catch(h){console.error("\u274C \u65E0\u6CD5\u8DF3\u8F6C\u5230\u65B0\u804A\u5929\u89C6\u56FE:",h),i.push("/chat");}return}let b=g.appurl||g.href;b&&(b.startsWith("http://")||b.startsWith("https://")?window.open(b,"_blank"):i.push(b));},[i]);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: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 ${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:d,onChange:g=>T(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: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(Yt,{items:E,onItemClick:p,className:"space-y-1",expandedIds:D,colorMode:n,onToggleExpand:g=>{let b=new Set(k);E.some(m=>m.id===g)?b.has(g)?b.delete(g):(E.forEach(m=>{m.id!==g&&b.has(m.id)&&b.delete(m.id);}),b.add(g)):b.has(g)?b.delete(g):b.add(g),w(b);}})}),e&&jsx("div",{className:"space-y-2",children:a.map(g=>jsx("div",{className:"space-y-1",children:jsx("button",{onClick:()=>{o();let b=new Set([g.id]);w(b);},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 Do=(e={})=>{let{initialCollapsed:o=false,content:t=[]}=e,[r,a]=useState(o),[n,l]=useState(t),i=useCallback(()=>{a(T=>!T);},[]),d=useMemo(()=>({collapsed:r,onToggle:i,menuData:n}),[r,i,n]);return {collapsed:r,setCollapsed:a,toggleCollapsed:i,menuData:n,setMenuData:l,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]:[];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"}),t.length>0&&jsx(Box,{sx:{display:"flex",gap:1,alignItems:"center",mr:1},children:t.map((a,n)=>jsx(Eo__default.Fragment,{children:a},`toolbar-action-${n}`))}),jsxs(Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsx(TextField,{size:"small",placeholder:"Search...",value:e.filterText,onChange:a=>e.setFilterText(a.target.value),InputProps:{sx:{fontSize:o,"& .MuiInputBase-input":{fontSize:o},"& .MuiInputBase-input::placeholder":{fontSize:o,opacity:1}},startAdornment:jsx(InputAdornment,{position:"start",children:jsx(ma,{fontSize:"small"})})},sx:{width:300}}),jsx(Tooltip,{title:"Group By",children:jsx(IconButton,{onClick:a=>e.setGroupAnchorEl(a.currentTarget),children:jsx(Badge,{badgeContent:e.grouping?.length,color:"primary",children:jsx(cn,{})})})}),jsx(Tooltip,{title:"Summary",children:jsx(IconButton,{onClick:a=>e.setSummaryAnchorEl(a.currentTarget),color:e.showSummary?"primary":"default",children:jsx(dn,{})})}),jsx(Tooltip,{title:"Columns",children:jsx(IconButton,{onClick:a=>e.setAnchorEl(a.currentTarget),children:jsx(rn,{})})}),jsx(Tooltip,{title:"Export",children:jsx(IconButton,{onClick:e.handleExport,children:jsx(sn,{})})}),e.onOpenGraphReport&&jsx(Tooltip,{title:"Graphic Report",children:jsx(IconButton,{onClick:e.onOpenGraphReport,children:jsx(un,{})})}),e.onLayoutSave&&!e.layoutManager&&jsx(Tooltip,{title:"Save Layout",children:jsx(IconButton,{onClick:a=>e.onLayoutSave(a),children:jsx(va,{})})}),e.layoutManager,r.length>0&&jsx(Box,{sx:{display:"flex",gap:1,alignItems:"center",ml:.5},children:r.map((a,n)=>jsx(Eo__default.Fragment,{children:a},`toolbar-extra-${n}`))})]})]})};var No=e=>{let{onSelectAllClick:o,order:t,orderBy:r,numSelected:a=0,rowCount:n=0,onRequestSort:l,columns:i,visibleColumns:d,selectionMode:T,onColumnResize:k,columnWidths:w}=e,[v,E]=useState(null),D=useRef(null),p=y=>I=>{v||l(y);},g=(y,I,c)=>{y.preventDefault(),y.stopPropagation(),E(I),D.current={startX:y.clientX,startWidth:c,colId:I},document.addEventListener("mousemove",b),document.addEventListener("mouseup",h),document.body.style.cursor="col-resize";},b=y=>{if(!D.current)return;let{startX:I,startWidth:c,colId:u}=D.current,x=y.clientX-I,C=Math.max(50,c+x);k&&k(u,C);},h=()=>{E(null),D.current=null,document.removeEventListener("mousemove",b),document.removeEventListener("mouseup",h),document.body.style.cursor="";};return useEffect(()=>()=>{document.removeEventListener("mousemove",b),document.removeEventListener("mouseup",h);},[]),jsx(fn,{children:jsxs(yn,{children:[(T==="multiple"||T==="single")&&jsx(Ao,{padding:"checkbox",sx:y=>({width:48,backgroundColor:y.palette.mode==="dark"?"#000000":"#f5f5f5",color:y.palette.mode==="dark"?"#ffffff":y.palette.text.primary}),children:jsx(hn,{color:"primary",indeterminate:a>0&&a<n,checked:n>0&&a===n,onChange:o,disabled:T==="single"})}),i.filter(y=>d.includes(y.id)).map(y=>{let I=w?.[y.id]||y.minWidth||100;return jsxs(Ao,{align:"left",padding:y.disablePadding?"none":"normal",sortDirection:r===y.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(bn,{active:r===y.id,direction:r===y.id?t:"asc",onClick:p(y.id),sx:c=>({"&.MuiTableSortLabel-root":{width:"100%"},"& .MuiTableSortLabel-icon":{color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary,opacity:r===y.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(ho,{component:"span",sx:{overflow:"visible",textOverflow:"clip",whiteSpace:"normal",lineHeight:1.2,wordBreak:"break-word",pr:1},children:y.label})}),jsx(ho,{onMouseDown:c=>g(c,y.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}})]},y.id)})]})})};var Oo=e=>{let{visibleRows:o,visibleColumns:t,selected:r=[],handleClick:a,columns:n,toggleGroupExpand:l,expandedGroups:i=new Set,selectionMode:d}=e,T=v=>r.indexOf(v)!==-1,k=d==="multiple"||d==="single",w=t.length+(k?1:0);return jsxs(TableBody,{children:[o.map((v,E)=>{if(v.type==="group"){let D=i.has(v.id),p=v.childIds||[],g=p.filter(y=>T(y)).length,b=p.length>0&&g===p.length,h=g>0&&g<p.length,m=y=>{if(y.stopPropagation(),!!e.onSelectionChange)if(b){let I=r.filter(c=>!p.includes(c));e.onSelectionChange(I);}else {let I=Array.from(new Set([...r,...p]));e.onSelectionChange(I);}};return jsx(TableRow,{sx:y=>({backgroundColor:y.palette.mode==="dark"?"#111111":"#f5f5f5","& .MuiTableCell-root":{color:y.palette.text.primary,borderBottomColor:y.palette.divider},"& .MuiIconButton-root":{color:y.palette.text.primary},"& .MuiCheckbox-root":{color:y.palette.text.secondary},"& .MuiCheckbox-root.Mui-checked, & .MuiCheckbox-root.MuiCheckbox-indeterminate":{color:y.palette.primary.main}}),children:jsx(TableCell,{colSpan:w,sx:{py:1,pl:v.level*4+2},children:jsxs(Box,{sx:{display:"flex",alignItems:"center"},children:[jsx(IconButton,{size:"small",onClick:()=>l&&l(v.id),sx:{mr:1},children:D?jsx(wn,{}):jsx(Tn,{})}),k&&jsx(Checkbox,{size:"small",checked:b,indeterminate:h,onChange:m,onClick:y=>y.stopPropagation(),sx:{mr:1,p:.5}}),jsxs(Typography,{variant:"body2",fontWeight:"bold",color:"text.primary",children:[v.field,": ",v.value," (",v.count,")"]})]})})},v.id)}else {let D=v.data||v,p=v.id||D.id||E,g=T(p),b=`enhanced-table-checkbox-${E}`,m=(v.level!==void 0?v.level:0)*4;return jsxs(TableRow,{hover:true,onClick:y=>a&&a(y,D),role:"checkbox","aria-checked":g,tabIndex:-1,selected:g,sx:{cursor:"pointer"},children:[k&&jsx(TableCell,{padding:"checkbox",sx:{pl:m>0?m+1:void 0},children:jsx(Checkbox,{color:"primary",checked:g,inputProps:{"aria-labelledby":b}})}),n.filter(y=>t.includes(y.id)).map((y,I)=>{let u=!k&&I===0&&m>0?{pl:m+2}:{};return jsx(TableCell,{align:"left",sx:u,children:y.render?y.render(D[y.id],D):(function(){let C=D[y.id];if(y.numeric){if(typeof C=="number")return C.toLocaleString();if(typeof C=="string"&&C.trim()!==""&&!isNaN(Number(C)))return Number(C).toLocaleString()}return C})()},y.id)})]},p)}}),o.length===0&&jsx(TableRow,{children:jsx(TableCell,{colSpan:w,align:"center",children:"No data"})})]})};var Go=e=>{let{visibleColumns:o,summaryRow:t,selectionMode:r}=e;if(!e.showSummary)return null;let a=r==="multiple"||r==="single";return jsx(TableFooter,{sx:{position:"sticky",bottom:0,zIndex:e.zIndex,bgcolor:"background.paper"},children:jsxs(TableRow,{children:[a&&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 i=t[n];return i==null||i===""?"":typeof i=="number"?i.toLocaleString():typeof i=="string"&&i.trim()!==""&&!isNaN(Number(i))?Number(i).toLocaleString():i})()},n))]})})};var $o=e=>jsx(Box,{sx:{p:2},children:jsx(Typography,{children:"Mobile View Not Implemented"})});var jo=({groupAnchorEl:e,setGroupAnchorEl:o,grouping:t,setGrouping:r,columns:a,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(Nn,{}),children:"Clear All"})]}),jsx(Divider,{}),a.map(l=>{let i=t.includes(l.id),d=t.indexOf(l.id)+1;return jsx(MenuItem,{onClick:()=>n(l.id),children:jsxs(Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsx(Checkbox,{checked:i,size:"small"}),jsx(ListItemText,{primary:l.label}),i&&jsx(Badge,{badgeContent:d,color:"primary",sx:{mr:2}})]})},l.id)})]}),Uo=({anchorEl:e,setAnchorEl:o,columns:t,visibleColumns:r,toggleColumnVisibility:a})=>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:()=>a(n.id),children:[jsx(Checkbox,{checked:r.includes(n.id),size:"small"}),jsx(ListItemText,{primary:n.label})]},n.id))]}),Ko=({anchorEl:e,setAnchorEl:o,showSummary:t,setShowSummary:r,columns:a,summaryColumns:n,toggleSummaryColumn:l})=>jsxs(Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsx(MenuItem,{children:jsx(FormControlLabel,{control:jsx(Switch,{checked:t,onChange:i=>r(i.target.checked),size:"small"}),label:"Show Summary Row"})}),jsx(Divider,{}),a.filter(i=>i.numeric).map(i=>jsxs(MenuItem,{onClick:()=>l(i.id),disabled:!t,children:[jsx(Checkbox,{checked:n.includes(i.id),size:"small"}),jsx(ListItemText,{primary:i.label})]},i.id)),a.filter(i=>i.numeric).length===0&&jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"No numeric columns"})})]}),Yo=({contextMenu:e,handleCloseContextMenu:o,columns:t,visibleColumns:r,toggleColumnVisibility:a})=>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:()=>a(n.id),children:[jsx(ListItemIcon,{children:r.includes(n.id)&&jsx(Vn,{fontSize:"small"})}),jsx(ListItemText,{children:n.label})]},n.id))]});var _e=(e,o=2)=>e.toLocaleString(void 0,{maximumFractionDigits:o}),Xo=({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 ht=["#1E88E5","#1ABC9C","#FBC02D","#EF5350","#7E57C2","#78909C"],Wn=({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))})},$n=({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))})},_n=({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((a,n)=>{let l=o;return o+=a.percent,`${ht[n%ht.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: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((a,n)=>jsxs(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsx(Box,{sx:{width:10,height:10,borderRadius:"50%",bgcolor:ht[n%ht.length]}}),jsx(Typography,{variant:"caption",sx:{flex:1},children:a.name}),jsxs(Typography,{variant:"caption",sx:{fontWeight:700},children:[a.percent.toFixed(0),"%"]})]},a.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]}),Jo=({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(Wn,{data:e})}),jsx(ao,{title:"Efficiency by Person",subtitle:"Lowest efficiency first",children:jsx($n,{data:o})}),jsx(ao,{title:"Status Distribution",subtitle:"Record ratio by status",children:jsx(_n,{data:t})})]});var Qo=({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(qn,{})})]})}),jsxs(Box,{sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,overflow:"auto",minHeight:0},children:[jsx(Xo,{kpis:t.kpis}),jsx(Jo,{billableByPrimary:t.charts.billableByPrimary,efficiencyBySecondary:t.charts.efficiencyBySecondary,statusDistribution:t.charts.statusDistribution}),r]})]})});var we={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"]},Xn=5,ea=e=>e.toLowerCase().replace(/[\s_-]/g,""),Ie=(e,o,t,r)=>{if(o)return o;if(e.length===0)return r;let a=Object.keys(e[0]),n=new Map(a.map(l=>[ea(l),l]));for(let l of t){let i=n.get(ea(l));if(i)return i}return a[0]||r},be=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},xe=(e,o)=>e==null||e===""?o:String(e),Jn=(e,o,t,r)=>{let a=new Map;return e.forEach(n=>{let l=xe(n[o],"Unassigned");a.set(l,(a.get(l)||0)+be(n[t]));}),Array.from(a.entries()).map(([n,l])=>({name:n,value:l})).sort((n,l)=>l.value-n.value).slice(0,r)},Zn=(e,o,t,r,a)=>{let n=new Map;return e.forEach(l=>{let i=xe(l[o],"Unassigned"),d=n.get(i)||{report:0,billable:0};d.report+=be(l[t]),d.billable+=be(l[r]),n.set(i,d);}),Array.from(n.entries()).map(([l,i])=>({name:l,value:i.report>0?i.billable/i.report*100:0})).sort((l,i)=>l.value-i.value).slice(0,a)},Qn=(e,o)=>{let t=e.length;if(t===0)return [];let r=new Map;return e.forEach(a=>{let n=xe(a[o],"Unassigned");r.set(n,(r.get(n)||0)+1);}),Array.from(r.entries()).map(([a,n])=>({name:a,value:n,percent:n/t*100}))},ta=({rows:e,config:o})=>{let t=useMemo(()=>{let d=o?.fieldMapping;return {primaryDimension:Ie(e,d?.primaryDimension,we.primaryDimension,"Category"),secondaryDimension:Ie(e,d?.secondaryDimension,we.secondaryDimension,"Owner"),status:Ie(e,d?.status,we.status,"Status"),date:Ie(e,d?.date,we.date,"Date"),description:Ie(e,d?.description,we.description,"Description"),reportHours:Ie(e,d?.reportHours,we.reportHours,"ReportHours"),billableHours:Ie(e,d?.billableHours,we.billableHours,"BillableHours"),amount:Ie(e,d?.amount,we.amount,"Amount")}},[e,o?.fieldMapping]),r=useMemo(()=>e.map((d,T)=>{let k=be(d[t.reportHours]),w=be(d[t.billableHours]),v=be(d[t.amount]),E=k>0?w/k*100:0;return {id:`graph-row-${T}`,Date:xe(d[t.date],""),Primary:xe(d[t.primaryDimension],"Unassigned"),Secondary:xe(d[t.secondaryDimension],"Unassigned"),Description:xe(d[t.description],""),ReportHours:k,BillableHours:w,Amount:v,Efficiency:E,Status:xe(d[t.status],"Unassigned")}}),[e,t]),a=useMemo(()=>{let d=r.length,T=r.reduce((p,g)=>p+be(g.ReportHours),0),k=r.reduce((p,g)=>p+be(g.BillableHours),0),w=r.reduce((p,g)=>p+be(g.Amount),0),v=T>0?k/T*100:0,E=o?.statusFlagValues||["flag","flagged","warning","risk"],D=r.filter(p=>E.includes(xe(p.Status,"").toLowerCase())).length;return {totalRecords:d,totalReportHours:T,totalBillableHours:k,efficiency:v,totalAmount:w,flaggedCount:D}},[r,o?.statusFlagValues]),n=o?.topN||Xn,l=useMemo(()=>({billableByPrimary:Jn(r,"Primary","BillableHours",n),efficiencyBySecondary:Zn(r,"Secondary","ReportHours","BillableHours",n),statusDistribution:Qn(r,"Status")}),[r,n]),i=useMemo(()=>({title:o?.title||"Graphic Report",kpis:a,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:r}}),[l,o?.title,t,a,r]);return {fieldMapping:t,model:i}};var Ct=({variants:e,currentVariantId:o,onLoad:t,onSave:r,onDelete:a,onSetDefault:n})=>{let l="0.75rem",[i,d]=useState(false),[T,k]=useState(""),[w,v]=useState(false),[E,D]=useState(false),p=e.find(h=>h.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:h=>h.name+(h.isDefault?" (Default)":""),value:p||null,onChange:(h,m)=>{m&&t(m);},renderInput:h=>jsx(TextField,{...h,variant:"outlined",size:"small",InputProps:{...h.InputProps,sx:{fontSize:l}},placeholder:"Select Variant"}),renderOption:(h,m)=>jsx("li",{...h,children:jsxs(Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsx(Typography,{sx:{flex:1,fontSize:l},children:m.name}),m.isDefault&&jsx(sr,{fontSize:"small",color:"action"})]})})}),jsx(Tooltip,{title:"Save View",children:jsx(IconButton,{onClick:()=>{k(p?.name||"New Variant"),v(p?.isDefault||false),D(p?.isPublic||false),d(true);},size:"small",color:"primary",children:jsx(va,{})})}),jsxs(Dialog,{open:i,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:h=>k(h.target.value)}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:w,onChange:h=>v(h.target.checked)}),label:"Set as Default"}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:E,onChange:h=>D(h.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 ur="http://127.0.0.1:8515",sa=({appId:e,tableKey:o="default",currentFilters:t,currentLayoutId:r,layoutRefs:a,onLoad:n,serviceUrl:l=ur,onError:i,onSuccess:d,currentVariantId:T,onVariantChange:k})=>{let[w,v]=useState([]),[E,D]=useState(""),p=T!==void 0?T:E,g=c=>{T===void 0&&D(c),k&&k(c);},b=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 u=await c.json();v(u);let x=u.find(C=>C.isDefault);return x&&!p&&(g(x.id),n(x)),u}catch(c){return console.error("Error fetching variants",c),i&&i("Failed to load variants"),[]}},[e,o,l,i,p,n]);return useEffect(()=>{b();},[e,o]),jsx(Ct,{variants:w,currentVariantId:p,onLoad:c=>{g(c.id),n(c);},onSave:async c=>{try{let u=w.find(B=>B.name===c.name),x=u?u.id:Date.now().toString(),C=[];if(u&&(Array.isArray(u.filters)?C=[...u.filters]:u.filters&&(C=[{scope:"default",filters:u.filters}])),c.scope==="Search"||c.scope==="Both"){let B=(Array.isArray(t),t);if(B)if(Array.isArray(B)&&B.length>0&&B[0].scope)B.forEach(V=>{let A=C.findIndex(N=>N.scope===V.scope);A>=0?C[A]=V:C.push(V);});else {let V={scope:o,filters:B},A=C.findIndex(N=>N.scope===o);A>=0?C[A]=V:C.push(V);}}let s=u?.layout||{},M=[];if(u&&Array.isArray(u.layoutRefs)&&(M=[...u.layoutRefs]),c.scope==="Layout"||c.scope==="Both")if(a&&a.length>0)a.forEach(B=>{let V=M.findIndex(A=>A.tableKey===B.tableKey);V>=0?M[V]=B:M.push(B);});else {let B={tableKey:o,layoutId:r||null},V=M.findIndex(A=>A.tableKey===o);V>=0?M[V]=B:M.push(B);}let S={appId:e,tableKey:o,...c,id:x,createdAt:new Date().toISOString(),filters:C,layout:s,layoutRefs:M};if(!(await fetch(`${l}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(S)})).ok)throw new Error("Failed to save variant");d&&d("Variant saved successfully"),await b(),g(x),n(S);}catch(u){console.error("Error saving variant",u),i&&i("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");p===c&&g(""),b(),d&&d("Variant deleted successfully");}catch(u){console.error("Error deleting variant",u),i&&i("Failed to delete variant");}},onSetDefault:async c=>{try{let u=w.find(s=>s.id===c);if(!u)return;let x={appId:e,tableKey:o,...u,isDefault:!0};if(!(await fetch(`${l}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(x)})).ok)throw new Error("Failed to set default variant");await b(),d&&d("Default variant updated");}catch(u){console.error("Error setting default variant",u),i&&i("Failed to update default variant");}}})};Pe.extend(kr);var Mr=[null,null],co="0.75rem",Rr=styled(PickersDay,{shouldForwardProp:e=>e!=="isInRange"&&e!=="isStart"&&e!=="isEnd"&&e!=="isHovered"})(({theme:e,isInRange:o,isStart:t,isEnd:r,isHovered:a})=>({...o&&{borderRadius:0,backgroundColor:e.palette.primary.light,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.main}},...a&&!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%"}})),ua=({label:e="Date Range",value:o=Mr,onChange:t})=>{let[r,a]=useState(null),[n,l]=useState(o),[i,d]=useState("start"),[T,k]=useState(null),[w,v]=useState(o[0]||Pe()),E=Eo__default.useRef(o);useEffect(()=>{let[x,C]=o,[s,M]=E.current,S=V=>V&&typeof V.isSame=="function",z=!(x===null&&s===null||S(x)&&S(s)&&x.isSame(s,"day")),B=!(C===null&&M===null||S(C)&&S(M)&&C.isSame(M,"day"));(z||B)&&(l(o),o[0]&&S(o[0])&&v(o[0])),E.current=o;},[o]);let D=x=>{a(x.currentTarget);},p=()=>{a(null),d("start"),k(null);},g=!!r,b=x=>{if(!x)return;let C=[...n];if(i==="start")C=[x,null],d("end");else {let s=C[0];s&&x.isBefore(s)?(C=[x,null],d("end")):(C=[s,x],d("start"));}l(C);},h=x=>{let C=Pe(),s=[null,null];switch(x){case "today":s=[C,C];break;case "week":s=[C.startOf("week"),C.endOf("week")];break;case "month":s=[C.startOf("month"),C.endOf("month")];break}l(s),d("start"),v(C);},m=()=>{l([null,null]),d("start"),v(Pe());},y=()=>{t&&t(n),p();},I=()=>{l(o),d("start"),p();},c=useCallback(x=>{let{day:C,...s}=x,[M,S]=n,z=M?C.isSame(M,"day"):false,B=S?C.isSame(S,"day"):false,V=M&&S?C.isBetween(M,S,"day","()"):false,A=false;return i==="end"&&M&&!S&&T&&C.isAfter(M,"day")&&C.isBefore(T.add(1,"day"),"day")&&(A=true),jsx(Rr,{...s,day:C,disableMargin:true,isStart:z,isEnd:B,isInRange:V||A,onMouseEnter:()=>k(C)})},[n,i,T]),u=x=>x?x.format("YYYY-MM-DD"):"";return jsxs(Box,{children:[jsx(TextField,{label:e,value:n[0]?`${u(n[0])} - ${u(n[1])}`:"",onClick:D,fullWidth:true,size:"small",InputLabelProps:{sx:{fontSize:co}},InputProps:{readOnly:true,sx:{fontSize:co,"& .MuiOutlinedInput-input":{fontSize:co},paddingRight:"4px"},endAdornment:jsxs(InputAdornment,{position:"end",sx:{ml:0},children:[(n[0]||n[1])&&jsx(IconButton,{size:"small",onClick:x=>{x.stopPropagation(),m();},edge:"end",sx:{mr:.5,padding:"2px"},children:jsx(wr,{sx:{fontSize:"1rem"}})}),jsx(IconButton,{size:"small",edge:"end",onClick:D,sx:{padding:"2px"},children:jsx(Tr,{sx:{fontSize:"1rem"},color:"action"})})]})}}),jsxs(Popover,{open:g,anchorEl:r,onClose:p,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:i==="start"?"primary.main":"divider",borderRadius:1,bgcolor:i==="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(Ir,{color:"action",fontSize:"small"}),jsxs(Box,{sx:{p:1,border:1,borderColor:i==="end"?"primary.main":"divider",borderRadius:1,bgcolor:i==="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:()=>h("today"),clickable:true,size:"small",variant:"outlined"}),jsx(Chip,{label:"This Week",onClick:()=>h("week"),clickable:true,size:"small",variant:"outlined"}),jsx(Chip,{label:"This Month",onClick:()=>h("month"),clickable:true,size:"small",variant:"outlined"})]})}),jsx(DateCalendar,{value:null,referenceDate:w,onMonthChange:v,onYearChange:v,onChange:b,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:y,children:"Done"})]})]})]})};var wt={equals:"=",contains:"\u2287",notContains:"\u2285",wildcard:"*","=":"=","!=":"!=",">":">","<":"<",">=":"\u2265","<=":"\u2264",between:"\u2194"},Or={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"},zr=["equals","contains","notContains","wildcard"],ga=["=","!=",">","<",">=","<=","between"],J="0.75rem",Gr=({field:e,value:o,onChange:t})=>{let[r,a]=useState(null),[n,l]=useState(null),[i,d]=useState(""),[T,k]=useState(""),[w,v]=useState(false),[E,D]=useState(""),[p,g]=useState("");useEffect(()=>{let s=setTimeout(()=>{g(E);},1e3);return ()=>clearTimeout(s)},[E]);let b=o?.operator||(e.type==="number"?"=":"equals"),h=o?.value,m=s=>Or[s]||s,y=s=>{a(s.currentTarget);},I=s=>{t({...o,operator:s,value:h}),a(null);},c={size:"small",fullWidth:true,variant:"outlined",InputLabelProps:{sx:{fontSize:J}},InputProps:{sx:{fontSize:J}},SelectProps:{MenuProps:{PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:J,paddingTop:"4px",paddingBottom:"4px",minHeight:"auto"}}}}}},u=e.type||"text";if(u==="date"){let M=(S=>{if(!S)return [null,null];if(Array.isArray(S)&&S.length===2){let z=S[0]?Pe.isDayjs(S[0])?S[0]:Pe(S[0]):null,B=S[1]?Pe.isDayjs(S[1])?S[1]:Pe(S[1]):null;return [z,B]}return Pe.isDayjs(S)||typeof S=="string"?[Pe.isDayjs(S)?S:Pe(S),null]:[null,null]})(h);return jsx(ua,{label:e.label,value:M,onChange:S=>t({value:S,operator:"between"})})}if(u==="number"&&b==="between"){let s=()=>{t({value:[i,T],operator:"between"}),l(null);},M=Array.isArray(h)?`${h[0]||""} - ${h[1]||""}`:"";return jsxs(Fragment,{children:[jsx(TextField,{...c,label:e.label,value:M,placeholder:"Min - Max",InputProps:{...c.InputProps,startAdornment:jsx(InputAdornment,{position:"start",children:jsx(Tooltip,{title:m("between"),children:jsx(IconButton,{size:"small",onClick:y,sx:{width:24,height:24,fontSize:J},children:wt.between})})}),readOnly:true},onClick:S=>l(S.currentTarget)}),jsx(Menu,{anchorEl:r,open:!!r,onClose:()=>a(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:J,minHeight:"auto",py:.5}}},children:ga.map(S=>jsxs(MenuItem,{selected:S===b,onClick:()=>I(S),children:[jsx(Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:wt[S]}),jsx(ListItemText,{primary:m(S),primaryTypographyProps:{fontSize:J}})]},S))}),jsx(Popover,{open:!!n,anchorEl:n,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:i,onChange:S=>d(S.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:J}},InputProps:{sx:{fontSize:J}}}),jsx(Hr,{color:"action"}),jsx(TextField,{size:"small",label:"Max",type:"number",value:T,onChange:S=>k(S.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:J}},InputProps:{sx:{fontSize:J}}}),jsx(Button,{variant:"contained",size:"small",onClick:s,children:"OK"})]})})]})}if(u==="select")return jsxs(TextField,{...c,select:true,label:e.label,value:h||"",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(h)?h:[],M=e.options?.filter(S=>S.label.toLowerCase().includes(p.toLowerCase()))||[];return jsxs(TextField,{...c,select:true,label:e.label,value:s,onChange:S=>t({...o,value:S.target.value,operator:"anyOf"}),SelectProps:{...c.SelectProps,multiple:true,onClose:()=>{D(""),g("");},renderValue:S=>{if(!Array.isArray(S)||S.length===0)return jsx("em",{children:"None"});let z=V=>e.options?.find(A=>A.value===V)?.label||V,B=S.map(z);return B.length>2?`${B.slice(0,2).join(", ")} +${B.length-2}`:B.join(", ")}},children:[jsx(ListSubheader,{children:jsx(TextField,{size:"small",autoFocus:true,placeholder:"Search...",fullWidth:true,InputProps:{startAdornment:jsx(InputAdornment,{position:"start",children:jsx(ma,{fontSize:"small"})}),sx:{fontSize:J}},value:E,onChange:S=>D(S.target.value),onKeyDown:S=>{S.key!=="Escape"&&S.stopPropagation();},onClick:S=>S.stopPropagation()})}),M.length>0?M.map(S=>jsxs(MenuItem,{value:S.value,children:[jsx(Checkbox,{checked:s.indexOf(S.value)>-1,size:"small"}),jsx(ListItemText,{primary:S.label,primaryTypographyProps:{fontSize:J}})]},S.value)):jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"No options found",primaryTypographyProps:{fontSize:J}})})]})}let x=u==="number"?ga:zr,C=w||h!==void 0&&h!==""&&h!==null||!!r;return jsxs(Fragment,{children:[jsx(TextField,{...c,label:e.label,sx:{minWidth:"120px"},value:h||"",type:u==="number"?"number":"text",onChange:s=>t({...o,value:s.target.value,operator:b}),onFocus:()=>v(true),onBlur:()=>v(false),InputProps:{...c.InputProps,startAdornment:C?jsx(InputAdornment,{position:"start",children:jsx(Tooltip,{title:m(b),children:jsx(IconButton,{size:"small",onClick:y,onMouseDown:s=>s.preventDefault(),sx:{width:24,height:24,fontSize:J,fontWeight:"bold",color:"primary.main",bgcolor:"action.hover"},children:wt[b]})})}):null,endAdornment:e.hasSearchIcon?jsx(InputAdornment,{position:"end",children:jsx(ma,{color:"action"})}):void 0}}),jsx(Menu,{anchorEl:r,open:!!r,onClose:()=>a(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:J,minHeight:"auto",py:.5}}},children:x.map(s=>jsxs(MenuItem,{selected:s===b,onClick:()=>I(s),children:[jsx(Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:wt[s]}),jsx(ListItemText,{primary:m(s),primaryTypographyProps:{fontSize:J}})]},s))})]})},qe=({fields:e,filters:o,onFilterChange:t,variants:r=[],currentVariantId:a,onVariantLoad:n,onVariantSave:l,onVariantDelete:i,onVariantSetDefault:d,onSearch:T,loading:k=false,appId:w,tableKey:v,currentLayout:E,currentLayoutId:D,layoutRefs:p,variantService:g})=>{let[b,h]=useState(true),[m,y]=useState(null),[I,c]=useState(e.filter(s=>!s.hidden).map(s=>s.id)),u=(s,M)=>{t({...o,[s]:M});},x=s=>{I.includes(s)?c(I.filter(M=>M!==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(sa,{appId:w,tableKey:v,currentFilters:{values:o,visibleFields:I},currentLayout:E,currentLayoutId:D,layoutRefs:p,onLoad:s=>{if(!s.filters)return;let M=null;if(Array.isArray(s.filters)){let S=v||"default",z=s.filters.find(B=>B.scope===S);M=z?z.filters:null;}else M=s.filters;M&&(M.values||M.visibleFields?(M.visibleFields&&Array.isArray(M.visibleFields)&&c(M.visibleFields),M.values&&t(M.values)):t(M)),n&&n(s);},variantService:g,currentVariantId:a}):jsx(Ct,{variants:r,currentVariantId:a,onLoad:n,onSave:s=>{l&&l({...s,filters:{values:o,visibleFields:I}});},onDelete:i,onSetDefault:d}),jsxs(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsx(Tooltip,{title:"Add Filters",children:jsx(Button,{onClick:s=>y(s.currentTarget),size:"small",color:"primary",startIcon:jsx(Fr,{fontSize:"small"}),sx:{textTransform:"none",fontSize:J},children:"Adapt Filters"})}),jsx(Button,{variant:"contained",size:"small",onClick:T,disabled:k,sx:{minWidth:"40px",fontWeight:"bold"},children:k?"...":"Go"}),jsxs(Menu,{anchorEl:m,open:!!m,onClose:()=>y(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:()=>x(s.id),children:[jsx(Checkbox,{checked:I.includes(s.id),size:"small"}),jsx(ListItemText,{primary:s.label})]},s.id))]})]})]}),jsx(Collapse,{in:b,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(Gr,{field:s,value:o[s.id]||{value:"",operator:s.type==="number"?"=":"equals"},onChange:M=>u(s.id,M)})},s.id))})})}),jsx(Box,{sx:{position:"absolute",bottom:0,left:"50%",transform:"translate(-50%, 50%)",zIndex:10},children:jsx(IconButton,{size:"small",onClick:()=>h(!b),sx:{bgcolor:"background.paper",boxShadow:2,border:"1px solid",borderColor:"divider",width:20,height:20,minHeight:0,p:0,"&:hover":{bgcolor:"background.paper"}},children:b?jsx(Vr,{sx:{fontSize:16},color:"action"}):jsx(wn,{sx:{fontSize:16},color:"action"})})})]})};var Sa=({layouts:e,currentLayoutId:o,onLoad:t,onSave:r,onDelete:a,onSetDefault:n})=>{let[l,i]=useState(null),[d,T]=useState(false),[k,w]=useState(""),[v,E]=useState(""),[D,p]=useState({isDefault:false,isPublic:false}),g=e.find(c=>c.id===o),b=c=>{i(c.currentTarget);},h=()=>{i(null);},m=c=>{t(c),h();},y=()=>{w(""),E(""),p({isDefault:false,isPublic:false}),T(true),h();},I=()=>{k.trim()&&(r({name:k,description:v,...D}),T(false));};return jsxs(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsx(Tooltip,{title:"Save Layout",children:jsx(IconButton,{onClick:y,color:"primary",size:"small",children:jsx(va,{})})}),jsx(Tooltip,{title:"Layout Options",children:jsx(IconButton,{onClick:b,color:g?"primary":"default",children:jsx(Qr,{})})}),jsxs(Menu,{anchorEl:l,open:!!l,onClose:h,PaperProps:{sx:{width:320,maxHeight:400}},children:[jsx(MenuItem,{disabled:true,children:jsx(Typography,{variant:"caption",children:"Select Layout"})}),jsxs(MenuItem,{onClick:y,children:[jsx(ListItemIcon,{children:jsx(va,{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:()=>m(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:x=>x.stopPropagation(),children:[jsx(Tooltip,{title:c.isDefault?"Remove Default":"Set as Default",children:jsx(IconButton,{size:"small",onClick:x=>{x.stopPropagation(),n(c.id);},children:c.isDefault?jsx(sr,{fontSize:"small",color:"warning"}):jsx(Zr,{fontSize:"small"})})}),jsx(Tooltip,{title:"Delete",children:jsx(IconButton,{size:"small",color:"error",onClick:x=>{x.stopPropagation(),a(c.id);},children:jsx(Xr,{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:v,onChange:c=>E(c.target.value),fullWidth:true,size:"small"}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:D.isDefault,onChange:c=>p({...D,isDefault:c.target.checked})}),label:"Use as Default Layout"}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:D.isPublic,onChange:c=>p({...D,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 ei="http://127.0.0.1:8515",wa=({appId:e,tableKey:o="default",currentLayoutData:t,onLayoutLoad:r,targetLayoutId:a,activeLayoutId:n,serviceUrl:l=ei,onError:i,onSuccess:d})=>{let[T,k]=useState([]),[w,v]=useState(""),E=`orbcafe.layouts.${e}.${o}`,D=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??{}}),p=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}),g=useCallback(()=>{try{let u=localStorage.getItem(E);if(!u)return [];let x=JSON.parse(u);return Array.isArray(x)?x:[]}catch{return []}},[E]),b=useCallback(u=>{try{localStorage.setItem(E,JSON.stringify(u));}catch{}},[E]);useEffect(()=>{n!==void 0&&v(n);},[n]),useEffect(()=>{if(a&&T.length>0){let u=T.find(x=>x.id===a);u&&(v(u.id),r(u));}},[a,T,r]);let h=useCallback(async()=>{if(e)try{let u=await fetch(`${l}/api/layouts?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!u.ok)throw new Error("Failed to fetch layouts");let C=(await u.json()).map(D);k(C);let s=C.find(M=>M.isDefault);s&&!w&&!a&&(v(s.id),r(s));}catch(u){console.error("Error fetching layouts",u);let x=g();k(x);let C=x.find(s=>s.isDefault);C&&!w&&!a&&(v(C.id),r(C)),i&&i("Failed to load layouts from backend, fallback to local storage");}},[e,o,l,i,w,r,a,g]);return useEffect(()=>{h();},[e,o]),jsx(Sa,{layouts:T,currentLayoutId:w,onLoad:u=>{v(u.id),r(u);},onSave:async u=>{let x=T.find(M=>M.name===u.name),C=x?x.id:Date.now().toString(),s={id:C,...u,createdAt:new Date().toISOString(),layoutData:t,isDefault:u.isDefault??false,isPublic:u.isPublic??false};try{if(!(await fetch(`${l}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(p(s))})).ok)throw new Error("Failed to save layout");d&&d("Layout saved successfully"),await h(),v(C),r(s);}catch(M){console.error("Error saving layout",M);let z=T.some(B=>B.id===C)?T.map(B=>B.id===C?s:B):[...T,s];k(z),b(z),v(C),r(s),d&&d("Layout saved to local storage"),i&&i("Backend unavailable, saved to local storage");}},onDelete:async u=>{try{if(!(await fetch(`${l}/api/layouts/${encodeURIComponent(u)}`,{method:"DELETE"})).ok)throw new Error("Failed to delete layout");w===u&&v(""),d&&d("Layout deleted successfully"),await h();}catch(x){console.error("Error deleting layout",x);let C=T.filter(s=>s.id!==u);k(C),b(C),w===u&&v(""),d&&d("Layout deleted from local storage"),i&&i("Backend unavailable, deleted from local storage");}},onSetDefault:async u=>{try{let x=T.find(s=>s.id===u);if(!x)return;if(!(await fetch(`${l}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(p({...x,isDefault:!0}))})).ok)throw new Error("Failed to set default layout");d&&d("Default layout set"),await h();}catch(x){console.error("Error setting default",x);let C=T.map(s=>({...s,isDefault:s.id===u}));k(C),b(C),d&&d("Default layout set in local storage"),i&&i("Backend unavailable, default saved to local storage");}}})};function ka(e,o,t){return o[t]<e[t]?-1:o[t]>e[t]?1:0}function oi(e,o){return e==="desc"?(t,r)=>ka(t,r,o):(t,r)=>-ka(t,r,o)}function ai(e,o){let t=e.map((r,a)=>[r,a]);return t.sort((r,a)=>{let n=o(r[0],a[0]);return n!==0?n:r[1]-a[1]}),t.map(r=>r[0])}var Ma=e=>{let o=useCallback(f=>{let L=String(f?.label??f?.id??"").length*9+64,ee=typeof f?.minWidth=="number"?f.minWidth:0;return Math.max(100,ee,L)},[]),[t,r]=useState(""),[a,n]=useState(e.order||"asc"),[l,i]=useState(e.orderBy||""),[d,T]=useState(e.page||0),[k,w]=useState(e.rowsPerPage||20),[v,E]=useState(e.selected||[]),[D,p]=useState(e.columns?e.columns.map(f=>f.id):[]),[g,b]=useState(e.showSummary||false),[h,m]=useState([]),[y,I]=useState(new Set),[c,u]=useState(()=>{let f={};return (e.columns||[]).forEach(R=>{f[R.id]=o(R);}),f}),[x,C]=useState(null),[s,M]=useState(null),[S,z]=useState(null),[B,V]=useState(null),[A,N]=useState(false),[te,Oe]=useState("");useEffect(()=>{e.order!==void 0&&n(e.order),e.orderBy!==void 0&&i(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(f=>{let R={...f};return (e.columns||[]).forEach(L=>{R[L.id]===void 0&&(R[L.id]=o(L));}),R});},[e.columns,o]);let oe=useMemo(()=>{let f=e.rows||[];return t&&(f=f.filter(R=>Object.keys(R).some(L=>String(R[L]).toLowerCase().includes(t.toLowerCase())))),f},[e.rows,t]),re=useMemo(()=>e.onSortChange||!l?oe:ai(oe,oi(a,l)),[oe,a,l,e.onSortChange]),ie=useCallback(f=>{if(h.length===0)return f.map(K=>({type:"row",data:K,id:K[e.rowKey||"id"]}));let R=[...f].sort((K,Y)=>{for(let W of h){if(K[W]<Y[W])return -1;if(K[W]>Y[W])return 1}return 0}),L=(K,Y=0)=>{if(Y>=h.length)return K;let W=h[Y],j={},ge=[];return K.forEach(se=>{let Be=se[W],ce=`${W}:${Be}`;j[ce]||(j[ce]={key:ce,field:W,value:Be,children:[],count:0,level:Y},ge.push(j[ce])),j[ce].children.push(se),j[ce].count++;}),ge.forEach(se=>{se.children&&(se.children=L(se.children,Y+1));}),ge},ee=L(R),G=(K,Y="")=>{let W=[];return K.forEach(j=>{if(j.children){let ge=Y?`${Y}>${j.key}`:j.key,se=y.has(ge);W.push({type:"group",id:ge,field:j.field,value:j.value,level:j.level,count:j.count,isExpanded:se,childIds:(function Be(ce){let ve=[];return ce.children.forEach(We=>{We.children?ve=ve.concat(Be(We)):ve.push(We[e.rowKey||"id"]);}),ve})(j)}),se&&(W=W.concat(G(j.children,ge)));}else W.push({type:"row",data:j,id:j[e.rowKey||"id"],level:h.length});}),W};return G(ee)},[h,y,e.rowKey]),Re=useMemo(()=>ie(re),[re,ie]),at=useMemo(()=>k>0?Re.slice(d*k,d*k+k):Re,[Re,d,k]),nt=f=>{let R=new Set(y);R.has(f)?R.delete(f):R.add(f),I(R);},ze=f=>{nt(f);},Lt=f=>{let R=new Set(y);Array.from(R).forEach(L=>{L.startsWith(f)&&R.delete(L);}),I(R);},At=f=>{f||I(new Set);},Ge=f=>{let R=l===f&&a==="asc",L=l===f&&a==="desc";if(e.onSortChange){R?e.onSortChange(f,"desc"):L?e.onSortChange("","asc"):e.onSortChange(f,"asc");return}R?(n("desc"),i(f)):L?(n("asc"),i("")):(n("asc"),i(f));},rt=(f,R)=>{u(L=>({...L,[f]:R}));},Ft=f=>{if(f.target.checked){let R=oe.map(L=>L[e.rowKey||"id"]);E(R),e.onSelectionChange&&e.onSelectionChange(R);return}E([]),e.onSelectionChange&&e.onSelectionChange([]);},Vt=(f,R)=>{let L=R[e.rowKey||"id"],ee=v.indexOf(L),G=[];ee===-1?G=G.concat(v,L):ee===0?G=G.concat(v.slice(1)):ee===v.length-1?G=G.concat(v.slice(0,-1)):ee>0&&(G=G.concat(v.slice(0,ee),v.slice(ee+1))),E(G),e.onSelectionChange&&e.onSelectionChange(G);},it=f=>{T(f),e.onPageChange&&e.onPageChange(f);},lt=f=>{w(f),T(0),e.onRowsPerPageChange&&e.onRowsPerPageChange(f);},Nt=f=>{let R=D.indexOf(f),L=[...D];R===-1?L.push(f):L.splice(R,1),p(L);},st=f=>{let R=h.indexOf(f),L=[...h];R===-1?L.push(f):L.splice(R,1),m(L);},Ht=f=>{e.onLayoutSave&&e.onLayoutSave({visibleColumns:D,order:a,orderBy:l,grouping:h,columnWidths:c});},ct=f=>{f.layout&&(f.layout.visibleColumns&&p(f.layout.visibleColumns),f.layout.order&&n(f.layout.order),f.layout.orderBy&&i(f.layout.orderBy),f.layout.grouping&&m(f.layout.grouping),f.layout.columnWidths&&u(f.layout.columnWidths));},Ot=f=>{let R=f?.layoutData||f?.layout||f||{};R.visibleColumns&&p(R.visibleColumns),R.order&&n(R.order),R.orderBy!==void 0&&i(R.orderBy),R.grouping&&m(R.grouping),R.columnWidths&&u(R.columnWidths),R.showSummary!==void 0&&b(!!R.showSummary),I(new Set),T(0),f?.id&&Oe(f.id);};useEffect(()=>{e.layout&&ct({layout:e.layout});},[e.layout]);let zt=f=>{f.preventDefault(),V(B===null?{mouseX:f.clientX+2,mouseY:f.clientY-6}:null);},Gt=()=>{V(null);},dt=useMemo(()=>{if(!g)return {};let f={};e.columns.forEach(L=>{if(L.numeric){let ee=oe.reduce((G,K)=>{let Y=parseFloat(K[L.id]);return G+(isNaN(Y)?0:Y)},0);f[L.id]=ee.toFixed(2);}else f[L.id]="";});let R=e.columns.find(L=>D.includes(L.id));return R&&!R.numeric&&(f[R.id]="Total"),f},[oe,e.columns,g,D]),Wt=()=>{if(!e.columns||!oe)return;let f=e.columns.map(K=>K.label).join(","),R=oe.map(K=>e.columns.map(Y=>{let W=K[Y.id];return `"${(W==null?"":String(W)).replace(/"/g,'""')}"`}).join(",")).join(`
|
|
2
|
+
`),L=`data:text/csv;charset=utf-8,${f}
|
|
3
|
+
${R}`,ee=encodeURI(L),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);},$t=()=>{N(true);},_t=()=>{N(false);};return {isMobile:false,columns:e.columns,order:a,orderBy:l,filterText:t,setFilterText:r,visibleColumns:D,setVisibleColumns:p,showSummary:g,setShowSummary:b,summaryColumns:[],grouping:h,setGrouping:m,expandedGroups:y,setExpandedGroups:I,groupAnchorEl:s,setGroupAnchorEl:M,summaryAnchorEl:S,setSummaryAnchorEl:z,columnWidths:c,setColumnWidths:u,anchorEl:x,setAnchorEl:C,contextMenu:B,setContextMenu:V,sensors:void 0,sortedAndFilteredRows:re,visibleRows:at,summaryRow:dt,page:d,setPage:it,rowsPerPage:k,setRowsPerPage:lt,selected:v,setSelected:E,isAllExpanded:false,handleColumnResize:rt,handleRequestSort:Ge,handleSelectAllClick:Ft,handleClick:Vt,toggleSummaryColumn:()=>{},handleDragEnd:()=>{},handleExport:Wt,handleContextMenu:zt,handleCloseContextMenu:Gt,toggleColumnVisibility:Nt,toggleGroupExpand:nt,toggleGroupField:st,handleToggleAll:At,handleExpandGroupRecursively:ze,handleCollapseGroupRecursively:Lt,handleLayoutLoad:Ot,handleVariantLoad:ct,handleLayoutSave:Ht,effectiveAppId:e.appId||"",currentLayoutData:{visibleColumns:D,order:a,orderBy:l,grouping:h,columnWidths:c},currentLayoutId:te,layoutIdToLoad:"",onPageChange:it,onRowsPerPageChange:lt,graphReportOpen:A,handleOpenGraphReport:$t,handleCloseGraphReport:_t}};var Ac=e=>jsx(ii,{...e}),Fc=e=>jsx(Ao,{...e}),Vc=e=>jsx(Ra,{...e}),Nc=e=>jsx(fn,{...e}),Hc=e=>jsx(yn,{...e}),Rt=e=>{let{title:o="Data Table",showToolbar:t=true,selectionMode:r,selected:a=[],onSelectionChange:n,actions:l,extraTools:i,fitContainer:d=false,fullWidth:T=false,maxHeight:k,loading:w=false,page:v=0,rowsPerPage:E=20,rowsPerPageOptions:D=[20,50,100,-1],count:p=0,onPageChange:g,onRowsPerPageChange:b,onLayoutSave:h,filterConfig:m,rowKey:y,tableKey:I="default",graphReport:c}=e,{isMobile:u,columns:x,order:C,orderBy:s,filterText:M,setFilterText:S,visibleColumns:z,showSummary:B,setShowSummary:V,summaryColumns:A,grouping:N,setGrouping:te,expandedGroups:Oe,groupAnchorEl:oe,setGroupAnchorEl:re,summaryAnchorEl:ie,setSummaryAnchorEl:Re,columnWidths:at,anchorEl:nt,setAnchorEl:ze,contextMenu:Lt,sensors:At,sortedAndFilteredRows:Ge,summaryRow:rt,visibleRows:Ft,isAllExpanded:Vt,handleColumnResize:it,handleRequestSort:lt,handleSelectAllClick:Nt,handleClick:st,toggleSummaryColumn:Ht,handleDragEnd:ct,handleExport:Ot,handleContextMenu:zt,handleCloseContextMenu:Gt,toggleColumnVisibility:dt,toggleGroupExpand:Wt,toggleGroupField:$t,handleToggleAll:_t,handleExpandGroupRecursively:f,handleCollapseGroupRecursively:R,handleLayoutLoad:L,handleVariantLoad:ee,handleLayoutSave:G,effectiveAppId:K,currentLayoutData:Y,currentLayoutId:W,layoutIdToLoad:j,graphReportOpen:ge,handleOpenGraphReport:se,handleCloseGraphReport:Be}=Ma(e),ce=c?.enabled??false,{model:ve}=ta({rows:Ge,config:{...c,title:c?.title||`${o} Graphic Report`}}),We=ve.table.columns.map(ut=>({id:ut.id,label:ut.label,align:ut.align||"left",minWidth:120,numeric:ut.align==="right"})),Va=K?jsx(wa,{appId:K,tableKey:I,currentLayoutData:Y,onLayoutLoad:L,targetLayoutId:j,activeLayoutId:W,serviceUrl:(m?.variantService,void 0)}):null,Co=jsxs(Fragment,{children:[jsx(jo,{groupAnchorEl:oe,setGroupAnchorEl:re,grouping:N,setGrouping:te,columns:x,toggleGroupField:$t}),jsx(Uo,{anchorEl:nt,setAnchorEl:ze,columns:x,visibleColumns:z,toggleColumnVisibility:dt}),jsx(Ko,{anchorEl:ie,setAnchorEl:Re,showSummary:B,setShowSummary:V,columns:x,summaryColumns:A,toggleSummaryColumn:Ht}),jsx(Yo,{contextMenu:Lt,handleCloseContextMenu:Gt,columns:x,visibleColumns:z,toggleColumnVisibility:dt})]});return u?jsxs(ho,{sx:{display:"flex",flexDirection:"column",gap:2,height:"100%"},children:[m&&jsx(qe,{fields:m.fields,filters:m.filters,onFilterChange:m.onFilterChange,onSearch:m.onSearch,variants:m.variants||[],currentVariantId:m.currentVariantId,onVariantLoad:m.onVariantLoad,onVariantSave:m.onVariantSave,onVariantDelete:m.onVariantDelete,onVariantSetDefault:m.onVariantSetDefault,appId:m.appId,tableKey:I,currentLayout:[{tableKey:I,layoutData:Y}],variantService:m.variantService}),jsx($o,{title:o,loading:w,showSummary:B,setShowSummary:V,setAnchorEl:ze,setSummaryAnchorEl:Re,filterText:M,setFilterText:S,sortedAndFilteredRows:Ge,selected:a,columns:x,visibleColumns:z,summaryRow:rt,handleClick:st,selectionMode:r}),Co]}):jsxs(ho,{sx:{width:T?"100%":"auto",mb:d?0:2,...d?{flex:1,display:"flex",flexDirection:"column",minHeight:0,height:"100%"}:{}},children:[m&&jsx(ho,{sx:{mb:2},children:jsx(qe,{fields:m.fields,filters:m.filters,onFilterChange:m.onFilterChange,onSearch:m.onSearch,variants:m.variants||[],currentVariantId:m.currentVariantId,onVariantLoad:ee,onVariantSave:m.onVariantSave,onVariantDelete:m.onVariantDelete,onVariantSetDefault:m.onVariantSetDefault,loading:w,appId:m.appId,tableKey:I,currentLayout:[{tableKey:I,layoutData:Y}],currentLayoutId:W,layoutRefs:[{tableKey:I,layoutId:W}],variantService:m.variantService})}),jsxs(ni,{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:M,setFilterText:S,onRowsPerPageChange:b,rowsPerPage:E,rowsPerPageOptions:D,page:v,count:p,onPageChange:g,actions:l,extraTools:i,grouping:N,setGroupAnchorEl:re,showSummary:B,setShowSummary:V,setAnchorEl:ze,setSummaryAnchorEl:Re,handleExport:Ot,onLayoutSave:h||m?.variantService&&m?.appId?G:void 0,loading:w,layoutManager:Va,onOpenGraphReport:ce?se:void 0}),jsx(Ra,{sx:{flex:1,maxHeight:k||"calc(100vh - 320px)",overflowY:"auto",overflowX:"auto",position:"relative",minHeight:0},children:jsx(DndContext,{sensors:At,collisionDetection:closestCenter,onDragEnd:ct,modifiers:[restrictToHorizontalAxis],children:jsxs(ri,{sx:{minWidth:T?750:"auto",width:T?"100%":"auto",tableLayout:Object.keys(at).length>0?"fixed":"auto",borderCollapse:"separate",borderSpacing:0},"aria-labelledby":"tableTitle",size:"small",stickyHeader:true,children:[jsx(No,{columns:x,visibleColumns:z,order:C,orderBy:s,onRequestSort:lt,onContextMenu:zt,selectionMode:r,grouping:N,isAllExpanded:Vt,handleToggleAll:_t,rowCount:Ge.length,numSelected:a.length,onSelectAllClick:Nt,columnWidths:at,onColumnResize:it}),jsx(Oo,{visibleRows:Ft,columns:x,visibleColumns:z,selectionMode:r,selected:a,orderBy:s,loading:w,expandedGroups:Oe,toggleGroupExpand:Wt,handleExpandGroupRecursively:f,handleCollapseGroupRecursively:R,handleClick:st,onSelectionChange:n,grouping:N,rowKeyProp:y,page:v,rowsPerPage:E}),B&&jsx(Go,{showSummary:B,columns:x,visibleColumns:z,summaryRow:rt,selectionMode:r?.toString(),orderBy:s,zIndex:3})]})})})]}),Co,ce&&jsx(Qo,{open:ge,onClose:Be,model:ve,tableContent:jsx(Rt,{title:"Data Body",columns:We,rows:ve.table.rows,rowKey:"id",fullWidth:true,maxHeight:"420px",rowsPerPage:20,rowsPerPageOptions:[20,50,100],graphReport:{enabled:false}})})]})},Oc=Rt;var Uc=({title:e,hideHeader:o=true,filterConfig:t,tableProps:r,children:a,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(qe,{...t})}),jsx(Box,{sx:{flex:1,minHeight:0,overflow:"hidden"},children:jsx(Rt,{...r,fitContainer:true,filterConfig:void 0})})]}),a]});var Xc=({metadata:e,fetchData:o})=>{let[t,r]=useState(false),[a,n]=useState([]),[l,i]=useState({}),[d,T]=useState(e.variants||[]),[k,w]=useState(e.layout||null),[v,E]=useState(0),[D,p]=useState(0),[g,b]=useState(10),[h,m]=useState([]),[y,I]=useState("asc"),[c,u]=useState("");useEffect(()=>{let A={};e.filters.forEach(N=>{N.defaultValue!==void 0&&(A[N.id]=N.defaultValue);}),i(A);},[e.filters]);let x=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(()=>{x(l,D,g,y,c);},[x,D,g,y,c]);let C=()=>{p(0),x(l,0,g,y,c);},s=(A,N)=>{I(N),u(A);},M=A=>{i(A);},S=A=>{if(A.filters){let N=A.filters.find(te=>te.scope==="default"||te.scope===e.id);N&&(i(N.filters),x(N.filters,0,g));}A.layout&&w(A.layout);},z=A=>{let N={...A,id:Date.now().toString(),createdAt:new Date().toISOString()};T(te=>[...te,N]);},B=A=>{w(A);};return {pageProps:{title:e.title,filterConfig:{appId:e.id,fields:e.filters,filters:l,onFilterChange:M,onSearch:C,onVariantLoad:S,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:a,loading:t,rowKey:"id",count:v,page:D,rowsPerPage:g,rowsPerPageOptions:[10,25,50,100],onPageChange:p,onRowsPerPageChange:b,selectionMode:"multiple",selected:h,onSelectionChange:m,onLayoutSave:B,layout:k,title:e.title,showSummary:true,order:y,orderBy:c,onSortChange:s,graphReport:e.graphReport||{enabled:true,title:`${e.title} Graphic Report`}}},filters:l,rows:a,loading:t,refresh:C}};var Ba=64,Di="#E9EDF2",Pi="linear-gradient(90deg, #F5F7FA 0%, #E9EDF2 50%, #F5F7FA 100%)",La=({appTitle:e,logo:o,mode:t="dark",onToggleMode:r,localeLabel:a="EN",searchPlaceholder:n="Ask me...",onSearch:l,user:i,leftSlot:d,rightSlot:T})=>{let w=useTheme().palette.mode==="dark",[v,E]=useState(""),D=b=>{b.preventDefault(),l&&l(v.trim());},p=t==="system"?jsx(ki,{fontSize:"small"}):t==="dark"?jsx(Mi,{fontSize:"small"}):jsx(Ri,{fontSize:"small"}),g=t==="system"?"Theme: System":t==="dark"?"Theme: Dark":"Theme: Light";return jsx(AppBar,{position:"sticky",elevation:0,sx:b=>({top:0,zIndex:b.zIndex.drawer+10,height:Ba,backgroundColor:b.palette.mode==="dark"?"#0D0D0D":Di,backgroundImage:b.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%)",Pi,"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:b.palette.mode==="dark"?"rgba(255,255,255,0.12)":"rgba(15,23,42,0.12)"}),children:jsxs(Toolbar,{sx:{minHeight:`${Ba}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:D,sx:{width:"100%",maxWidth:540},children:jsx(TextField,{size:"small",fullWidth:true,value:v,onChange:b=>E(b.target.value),placeholder:n,InputProps:{startAdornment:jsx(InputAdornment,{position:"start",children:jsx(ma,{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(Ii,{sx:{color:w?"common.white":"#111827",fontSize:18}}),jsx(Typography,{variant:"caption",sx:{color:w?"common.white":"#111827",fontWeight:500},children:a})]}),jsx(IconButton,{size:"small",sx:{color:w?"common.white":"#111827"},onClick:r,title:g,children:p}),i&&jsxs(Stack,{direction:"row",alignItems:"center",spacing:1,children:[jsx(Box,{sx:{textAlign:"right"},children:jsx(Typography,{variant:"body2",sx:{color:w?"common.white":"#111827",fontWeight:600,lineHeight:1.2},children:i.name})}),jsx(Avatar,{src:i.avatarSrc,imgProps:{style:{objectFit:"cover"}},sx:{width:34,height:34,bgcolor:"grey.100",color:"grey.700",fontSize:"0.85rem"},children:i.avatarText||i.name.slice(0,1).toUpperCase()})]}),T]})]})})};var Aa=({menuData:e=[],initialNavigationCollapsed:o=false}={})=>{let{navigationIslandProps:t}=Do({initialCollapsed:o,content:e}),[r,a]=useState(900);useEffect(()=>{let l=()=>a(window.innerHeight);return l(),window.addEventListener("resize",l),()=>window.removeEventListener("resize",l)},[]);let n=useMemo(()=>Math.max(280,r-100),[r]);return {navigationIslandProps:t,navigationMaxHeight:n}};var yd=({appTitle:e,menuData:o=[],children:t,showNavigation:r=true,localeLabel:a,user:n,logo:l,onSearch:i,rightHeaderSlot:d,leftHeaderSlot:T,contentSx:k})=>{let[w,v]=useState("system"),[E,D]=useState("light"),[p,g]=useState(false),b=w==="system"?p?E:"light":w;useEffect(()=>{g(true);let I=window.matchMedia("(prefers-color-scheme: dark)"),c=()=>{D(I.matches?"dark":"light");};return c(),I.addEventListener("change",c),()=>I.removeEventListener("change",c)},[]);let h=useMemo(()=>createTheme({palette:{mode:b}}),[b]),{navigationIslandProps:m,navigationMaxHeight:y}=Aa({menuData:o,initialNavigationCollapsed:false});return jsx(ThemeProvider,{theme:h,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(La,{appTitle:e,logo:l,mode:w,onToggleMode:()=>v(I=>I==="system"?"dark":I==="dark"?"light":"system"),localeLabel:a,user:n,onSearch:i,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,{...m,maxHeight:y,colorMode:b})}),jsx(Box,{sx:{flex:1,minWidth:0,minHeight:0,overflow:"auto",p:1.5,...k},children:t})]})]})})};export{Ut as Button,La as CAppHeader,yd as CAppPageLayout,Sa as CLayoutManagement,wa as CLayoutManager,Po as CPageLayout,qe as CSmartFilter,Oc as CSmartTable,Uc as CStandardPage,Rt as CTable,Ac as CTableBody,Fc as CTableCell,Vc as CTableContainer,Nc as CTableHead,Hc as CTableRow,Ct as CVariantManagement,sa as CVariantManager,Mo as NavigationIsland,Yt as TreeMenu,Ga as buttonVariants,Do as useNavigationIsland,Aa as usePageLayout,Xc as useStandardReport};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orbcafe-ui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
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",
|
|
@@ -26,6 +27,11 @@
|
|
|
26
27
|
"access": "public"
|
|
27
28
|
},
|
|
28
29
|
"peerDependencies": {
|
|
30
|
+
"@emotion/react": "^11.14.0",
|
|
31
|
+
"@emotion/styled": "^11.14.1",
|
|
32
|
+
"@mui/icons-material": "^7.3.8",
|
|
33
|
+
"@mui/material": "^7.3.8",
|
|
34
|
+
"@mui/x-date-pickers": "^8.27.2",
|
|
29
35
|
"next": "^13.0.0 || ^14.0.0 || ^15.0.0",
|
|
30
36
|
"react": "^18.0.0 || ^19.0.0",
|
|
31
37
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
@@ -42,11 +48,6 @@
|
|
|
42
48
|
"@dnd-kit/core": "^6.3.1",
|
|
43
49
|
"@dnd-kit/modifiers": "^9.0.0",
|
|
44
50
|
"@dnd-kit/sortable": "^10.0.0",
|
|
45
|
-
"@emotion/react": "^11.14.0",
|
|
46
|
-
"@emotion/styled": "^11.14.1",
|
|
47
|
-
"@mui/icons-material": "^7.3.8",
|
|
48
|
-
"@mui/material": "^7.3.8",
|
|
49
|
-
"@mui/x-date-pickers": "^8.27.2",
|
|
50
51
|
"@radix-ui/react-slot": "^1.0.0",
|
|
51
52
|
"class-variance-authority": "^0.7.0",
|
|
52
53
|
"clsx": "^2.0.0",
|