orbcafe-ui 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3 -3
- package/dist/index.mjs +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
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
|
-
`),
|
|
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;
|
|
1
|
+
'use strict';var So=require('react'),navigation=require('next/navigation'),lucideReact=require('lucide-react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),reactSlot=require('@radix-ui/react-slot'),classVarianceAuthority=require('class-variance-authority'),jsxRuntime=require('react/jsx-runtime'),material=require('@mui/material'),bo=require('@mui/material/Box'),si=require('@mui/material/Paper'),ci=require('@mui/material/Table'),di=require('@mui/material/TableBody'),Bo=require('@mui/material/TableCell'),Rn=require('@mui/material/TableContainer'),xa=require('@mui/material/TableHead'),Ca=require('@mui/material/TableRow'),core=require('@dnd-kit/core'),modifiers=require('@dnd-kit/modifiers'),mn=require('@mui/icons-material/Search'),da=require('@mui/icons-material/ViewColumn'),vn=require('@mui/icons-material/Save'),pa=require('@mui/icons-material/Download'),ma=require('@mui/icons-material/AccountTree'),ga=require('@mui/icons-material/Functions'),fa=require('@mui/icons-material/Insights'),va=require('@mui/material/Checkbox'),Sa=require('@mui/material/TableSortLabel'),Ma=require('@mui/icons-material/KeyboardArrowRight'),Ra=require('@mui/icons-material/KeyboardArrowDown'),Oa=require('@mui/icons-material/Check'),Ga=require('@mui/icons-material/ClearAll'),Qa=require('@mui/icons-material/Close'),zr=require('@mui/icons-material/Settings'),Or=require('@mui/icons-material/KeyboardArrowUp'),Wr=require('@mui/icons-material/ArrowRightAlt'),pr=require('@mui/icons-material/Star'),DateCalendar=require('@mui/x-date-pickers/DateCalendar'),PickersDay=require('@mui/x-date-pickers/PickersDay'),Mr=require('@mui/icons-material/CalendarMonth'),Rr=require('@mui/icons-material/Clear'),Dr=require('@mui/icons-material/ArrowForward'),Ee=require('dayjs'),Pr=require('dayjs/plugin/isBetween'),ei=require('@mui/icons-material/Delete'),oi=require('@mui/icons-material/StarBorder'),ni=require('@mui/icons-material/ViewQuilt'),Ri=require('@mui/icons-material/Language'),Di=require('@mui/icons-material/DesktopWindows'),Pi=require('@mui/icons-material/DarkMode'),Ei=require('@mui/icons-material/LightMode'),Bi=require('@mui/icons-material/Logout');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var So__namespace=/*#__PURE__*/_interopNamespace(So);var bo__default=/*#__PURE__*/_interopDefault(bo);var si__default=/*#__PURE__*/_interopDefault(si);var ci__default=/*#__PURE__*/_interopDefault(ci);var di__default=/*#__PURE__*/_interopDefault(di);var Bo__default=/*#__PURE__*/_interopDefault(Bo);var Rn__default=/*#__PURE__*/_interopDefault(Rn);var xa__default=/*#__PURE__*/_interopDefault(xa);var Ca__default=/*#__PURE__*/_interopDefault(Ca);var mn__default=/*#__PURE__*/_interopDefault(mn);var da__default=/*#__PURE__*/_interopDefault(da);var vn__default=/*#__PURE__*/_interopDefault(vn);var pa__default=/*#__PURE__*/_interopDefault(pa);var ma__default=/*#__PURE__*/_interopDefault(ma);var ga__default=/*#__PURE__*/_interopDefault(ga);var fa__default=/*#__PURE__*/_interopDefault(fa);var va__default=/*#__PURE__*/_interopDefault(va);var Sa__default=/*#__PURE__*/_interopDefault(Sa);var Ma__default=/*#__PURE__*/_interopDefault(Ma);var Ra__default=/*#__PURE__*/_interopDefault(Ra);var Oa__default=/*#__PURE__*/_interopDefault(Oa);var Ga__default=/*#__PURE__*/_interopDefault(Ga);var Qa__default=/*#__PURE__*/_interopDefault(Qa);var zr__default=/*#__PURE__*/_interopDefault(zr);var Or__default=/*#__PURE__*/_interopDefault(Or);var Wr__default=/*#__PURE__*/_interopDefault(Wr);var pr__default=/*#__PURE__*/_interopDefault(pr);var Mr__default=/*#__PURE__*/_interopDefault(Mr);var Rr__default=/*#__PURE__*/_interopDefault(Rr);var Dr__default=/*#__PURE__*/_interopDefault(Dr);var Ee__default=/*#__PURE__*/_interopDefault(Ee);var Pr__default=/*#__PURE__*/_interopDefault(Pr);var ei__default=/*#__PURE__*/_interopDefault(ei);var oi__default=/*#__PURE__*/_interopDefault(oi);var ni__default=/*#__PURE__*/_interopDefault(ni);var Ri__default=/*#__PURE__*/_interopDefault(Ri);var Di__default=/*#__PURE__*/_interopDefault(Di);var Pi__default=/*#__PURE__*/_interopDefault(Pi);var Ei__default=/*#__PURE__*/_interopDefault(Ei);var Bi__default=/*#__PURE__*/_interopDefault(Bi);function le(...e){return tailwindMerge.twMerge(clsx.clsx(e))}var Kt={primary:"#000000",primaryHover:"#333333"},pt={primary:"bg-primary text-primary-foreground hover:bg-primary/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",ghost:"hover:bg-accent hover:text-accent-foreground"},_e={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",full:"rounded-full"},vo=()=>"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50";var Un=classVarianceAuthority.cva(vo(),{variants:{variant:{default:`${pt.primary} shadow-sm`,destructive:"bg-red-500 text-white hover:bg-red-600 active:bg-red-700 dark:bg-red-600 dark:hover:bg-red-500 dark:active:bg-red-700 shadow-sm",outline:`${pt.outline} shadow-sm`,secondary:"bg-gray-200 text-gray-700 hover:bg-gray-300 active:bg-gray-400 dark:bg-gray-700 dark:text-gray-200 dark:hover:bg-gray-600 dark:active:bg-gray-500 shadow-sm",ghost:pt.ghost,link:"text-blue-600 dark:text-blue-400 underline-offset-4 hover:underline hover:text-blue-700 dark:hover:text-blue-300 active:text-blue-800 dark:active:text-blue-200","chat-tool":"bg-[var(--orbai-surface-2)] border border-[var(--orbai-border-soft)] text-[var(--orbai-text-2)] hover:bg-[var(--orbai-surface-3)] hover:border-[var(--orbai-border-strong)] hover:text-[var(--orbai-text-1)] active:scale-95 transition-all duration-200","chat-send":`bg-[${Kt.primary}] hover:bg-[${Kt.primaryHover}] text-white border border-[var(--orbai-border-strong)] shadow-[var(--orbai-shadow-soft-sm)] hover:shadow-[var(--orbai-shadow-soft-md)] active:scale-95 transition-all duration-200`,"chat-stop":"bg-red-500 hover:bg-red-600 border border-[var(--orbai-border-strong)] shadow-[var(--orbai-shadow-soft-sm)] hover:shadow-[var(--orbai-shadow-soft-md)] active:scale-95 text-white transition-all duration-200","chat-disabled":"cursor-not-allowed opacity-50 bg-[var(--orbai-surface-2)] border border-[var(--orbai-border-soft)] text-[var(--orbai-muted)]"},size:{default:"h-10 px-4 py-2",sm:"h-9 px-3",lg:"h-11 px-8",icon:"h-10 w-10","chat-sm":"h-8 w-8 rounded-full","chat-md":"h-10 w-10 rounded-full","chat-lg":"h-12 w-12 rounded-full"},rounded:{none:_e.none,sm:_e.sm,md:_e.md,full:_e.full}},defaultVariants:{variant:"default",size:"default",rounded:"md"}}),Yt=So__namespace.forwardRef(({className:e,variant:o,size:t,asChild:r=false,...l},n)=>jsxRuntime.jsx(r?reactSlot.Slot:"button",{className:le(Un({variant:o,size:t,className:e})),ref:n,...l}));Yt.displayName="Button";function Xt({items:e,onItemClick:o,className:t="",level:r=0,expandedIds:l,onToggleExpand:n,colorMode:i="light"}){let a=i==="dark",d=navigation.usePathname(),[T,k]=So.useState(new Set),w=l!==void 0&&n!==void 0,C=w?l:T,E=m=>{if(w)n(m);else {let f=new Set(T);f.has(m)?f.delete(m):f.add(m),k(f);}},M=m=>{m.children&&m.children.length>0&&E(m.id),o&&o(m);};return !e||!Array.isArray(e)?jsxRuntime.jsx("div",{className:le("tree-menu",t),children:jsxRuntime.jsx("div",{className:"text-sm text-gray-500 p-2",children:"No items to display"})}):jsxRuntime.jsx("div",{className:le("tree-menu",t),children:e.map(m=>{let f=C.has(m.id)||m.isExpanded,S=m.children&&m.children.length>0,y=m.appurl||m.href,g=y?d===y:false;return jsxRuntime.jsxs("div",{className:"tree-menu-item relative",children:[g&&jsxRuntime.jsx("div",{className:le("absolute left-0 top-2 bottom-2 w-[3px] rounded-r-full z-10",a?"bg-[#90caf9]":"bg-[#1976d2]")}),jsxRuntime.jsxs(Yt,{variant:"ghost",className:le("w-full justify-start gap-2 h-auto py-2 relative overflow-hidden group",`ml-${r*4}`,g?a?"bg-transparent text-[#90caf9] hover:bg-gray-800/35":"bg-transparent text-[#1976d2] hover:bg-gray-100/60":a?"hover:bg-gray-800/50 text-gray-300":"hover:bg-gray-100/50 text-gray-700"),onClick:()=>M(m),children:[S&&jsxRuntime.jsx("div",{className:le("flex-shrink-0 transition-transform duration-200",f&&"rotate-90",g?a?"text-[#90caf9]":"text-[#1976d2]":a?"text-gray-500 group-hover:text-gray-300":"text-gray-400 group-hover:text-gray-600"),children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-4 w-4"})}),!S&&jsxRuntime.jsx("div",{className:"w-4 h-4 flex-shrink-0"}),m.icon&&jsxRuntime.jsx("div",{className:le("flex-shrink-0 transition-colors duration-200",g?a?"text-[#90caf9]":"text-[#1976d2]":a?"text-gray-500 group-hover:text-gray-300":"text-gray-400 group-hover:text-gray-600"),children:m.icon}),jsxRuntime.jsxs("div",{className:"flex-1 text-left overflow-hidden z-10",children:[jsxRuntime.jsx("div",{className:le("text-sm truncate transition-colors duration-200",g?"font-semibold":"font-medium"),children:m.title||m.label}),m.description&&jsxRuntime.jsx("div",{className:le("text-xs truncate transition-colors duration-200",g?a?"text-[#90caf9]/70":"text-[#1976d2]/75":a?"text-gray-400":"text-gray-500"),title:m.description,children:m.description})]})]}),S&&jsxRuntime.jsx("div",{className:le("grid transition-[grid-template-rows] duration-300 ease-in-out",f?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:jsxRuntime.jsx("div",{className:"overflow-hidden",children:jsxRuntime.jsx(Xt,{items:m.children,onItemClick:o,level:r+1,expandedIds:l,onToggleExpand:n,colorMode:i})})})]},m.id)})})}var Mo=({collapsed:e,onToggle:o,className:t="",maxHeight:r,menuData:l=[],colorMode:n="light"})=>{let i=n==="dark",a=navigation.useRouter(),[d,T]=So.useState(""),[k,w]=So.useState(new Set);So.useEffect(()=>{e&&w(new Set);},[e]);let C=So.useCallback(f=>{let S=[],y=g=>{g.forEach(p=>{S.push(p.id),p.children&&y(p.children);});};return y(f),S},[]),E=So.useMemo(()=>{if(!d.trim())return l;let f=S=>S.reduce((y,g)=>{let p=g.title?.toLowerCase().includes(d.toLowerCase())||g.description?.toLowerCase().includes(d.toLowerCase()),I=g.children?f(g.children):[];return (p||I.length>0)&&y.push({...g,children:I.length>0?I:g.children}),y},[]);return f(l)},[d,l]),M=So.useMemo(()=>d.trim()?new Set(C(l)):k,[d,l,k,C]),m=So.useCallback(async f=>{if(console.log("\u{1F5B1}\uFE0F \u5BFC\u822A\u83DC\u5355\u9879\u70B9\u51FB:",f),f.id==="chat"||f.appurl==="/chat"){console.log("\u{1F4AC} \u68C0\u6D4B\u5230chat\u83DC\u5355\u70B9\u51FB\uFF0C\u8DF3\u8F6C\u5230\u65B0\u7684\u804A\u5929\u89C6\u56FE");try{a.push("/chat?new=true");}catch(y){console.error("\u274C \u65E0\u6CD5\u8DF3\u8F6C\u5230\u65B0\u804A\u5929\u89C6\u56FE:",y),a.push("/chat");}return}let S=f.appurl||f.href;S&&(S.startsWith("http://")||S.startsWith("https://")?window.open(S,"_blank"):a.push(S));},[a]);return jsxRuntime.jsxs("div",{className:`flex flex-col backdrop-blur-xl border shadow-[0_4px_8px_0_rgba(31,38,135,0.1)] ${e?"w-14 rounded-full":"w-[234px] rounded-2xl"} relative ${t} ${i?"bg-[#111111] border-white/10":"bg-white/70 border-white/30"}`,style:{backdropFilter:"blur(16px) saturate(180%)",WebkitBackdropFilter:"blur(16px) saturate(180%)",transition:"width 400ms cubic-bezier(0.4, 0.0, 0.2, 1), border-radius 0ms cubic-bezier(0.4, 0.0, 0.2, 1), box-shadow 400ms ease-out",maxHeight:r?`${r}px`:void 0},children:[jsxRuntime.jsx("div",{className:`pt-4 pb-2 transition-all duration-500 ease-in-out ${e?"px-1":"px-2"}`,children:e?jsxRuntime.jsx("div",{className:"flex justify-center",children:jsxRuntime.jsx("button",{onClick:o,className:`w-10 h-10 flex items-center justify-center rounded-lg transition-colors duration-200 ${i?"text-gray-300 hover:bg-gray-800":"text-gray-500 hover:bg-gray-50"}`,title:"\u5C55\u5F00\u5BFC\u822A",children:jsxRuntime.jsx(lucideReact.Search,{className:"h-5 w-5"})})}):jsxRuntime.jsxs("div",{className:`relative transition-opacity duration-300 ${e?"opacity-0":"opacity-100 delay-200"}`,children:[jsxRuntime.jsx("input",{type:"text",placeholder:"\u641C\u7D22\u83DC\u5355...",value:d,onChange:f=>T(f.target.value),className:`w-full pl-10 pr-4 py-2 text-sm border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent ${i?"border-gray-700 bg-[#1A1A1A] text-white placeholder-gray-400":"border-gray-300 bg-white text-gray-900 placeholder-gray-500"}`}),jsxRuntime.jsx("div",{className:"absolute left-3 top-1/2 transform -translate-y-1/2 pointer-events-none",children:jsxRuntime.jsx(lucideReact.Search,{className:`h-4 w-4 ${i?"text-gray-500":"text-gray-400"}`})})]})}),jsxRuntime.jsx("nav",{className:`flex-1 pb-4 transition-all duration-500 ease-in-out overflow-y-auto min-h-0 ${e?"px-1":"px-2"}`,children:E.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-gray-500 text-sm",children:e?"\u{1F4C2}":d?"\u672A\u627E\u5230\u5339\u914D\u7684\u83DC\u5355\u9879":"\u6682\u65E0\u53EF\u8BBF\u95EE\u7684\u5E94\u7528"}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[!e&&jsxRuntime.jsx("div",{className:`transition-opacity duration-300 ${e?"opacity-0":"opacity-100 delay-200"}`,children:jsxRuntime.jsx(Xt,{items:E,onItemClick:m,className:"space-y-1",expandedIds:M,colorMode:n,onToggleExpand:f=>{let S=new Set(k);E.some(g=>g.id===f)?S.has(f)?S.delete(f):(E.forEach(g=>{g.id!==f&&S.has(g.id)&&S.delete(g.id);}),S.add(f)):S.has(f)?S.delete(f):S.add(f),w(S);}})}),e&&jsxRuntime.jsx("div",{className:"space-y-2",children:l.map(f=>jsxRuntime.jsx("div",{className:"space-y-1",children:jsxRuntime.jsx("button",{onClick:()=>{o();let S=new Set([f.id]);w(S);},className:`w-full flex items-center justify-center p-2 rounded-lg cursor-pointer transition-colors duration-200 ${i?"text-gray-400 hover:bg-gray-800":"text-gray-600 hover:bg-gray-50"}`,title:`\u5C55\u5F00\u67E5\u770B ${f.title}`,children:f.icon||jsxRuntime.jsx("div",{className:`w-6 h-6 rounded text-xs flex items-center justify-center font-medium ${i?"bg-[#90caf9] text-[#0b0b0b]":"bg-[#1976d2] text-white"}`,children:f.title?.charAt(0)||"?"})})},f.id))})]})}),!e&&jsxRuntime.jsx("button",{onClick:o,className:`absolute -bottom-1 -right-1 w-6 h-6 bg-transparent rounded-full flex items-center justify-center transition-all duration-300 ease-in-out z-20 ${i?"hover:bg-gray-800/50":"hover:bg-white/20"}`,title:"\u6298\u53E0\u5BFC\u822A",children:jsxRuntime.jsx("div",{className:"absolute",style:{bottom:"0px",right:"0px",width:"16px",height:"16px",overflow:"hidden"},children:jsxRuntime.jsx("div",{className:i?"border-yellow-400":"",style:{width:"32px",height:"32px",borderRadius:"16px",border:"3px solid #21BCFF",backgroundColor:"transparent",position:"absolute",top:"-16px",left:"-16px"}})})})]})};var Do=(e={})=>{let{initialCollapsed:o=false,content:t=[]}=e,[r,l]=So.useState(o),[n,i]=So.useState(t),a=So.useCallback(()=>{l(T=>!T);},[]),d=So.useMemo(()=>({collapsed:r,onToggle:a,menuData:n}),[r,a,n]);return {collapsed:r,setCollapsed:l,toggleCollapsed:a,menuData:n,setMenuData:i,navigationIslandProps:d}};var Po=({title:e,hideHeader:o,children:t})=>jsxRuntime.jsxs(material.Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[!o&&jsxRuntime.jsx(material.Box,{sx:{mb:2},children:jsxRuntime.jsx(material.Typography,{variant:"h4",children:e})}),jsxRuntime.jsx(material.Box,{sx:{flex:1,overflow:"hidden"},children:t})]});var Lo=e=>{let o="0.75rem",t=Array.isArray(e.actions)?e.actions:e.actions?[e.actions]:[],r=Array.isArray(e.extraTools)?e.extraTools:e.extraTools?[e.extraTools]:[],l=[...t,...r];return jsxRuntime.jsxs(material.Toolbar,{sx:{pl:{sm:2},pr:{xs:1,sm:1},alignItems:"center",gap:1},children:[jsxRuntime.jsx(material.TextField,{size:"small",placeholder:"Search...",value:e.filterText,onChange:n=>e.setFilterText(n.target.value),InputProps:{sx:{fontSize:o,"& .MuiInputBase-input":{fontSize:o},"& .MuiInputBase-input::placeholder":{fontSize:o,opacity:1}},startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(mn__default.default,{fontSize:"small"})})},sx:{width:300}}),jsxRuntime.jsx(material.Box,{sx:{flex:1}}),jsxRuntime.jsxs(material.Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsxRuntime.jsx(material.Box,{sx:{width:1,height:20,bgcolor:"divider",mr:.5}}),jsxRuntime.jsx(material.Tooltip,{title:"Group By",children:jsxRuntime.jsx(material.IconButton,{onClick:n=>e.setGroupAnchorEl(n.currentTarget),children:jsxRuntime.jsx(material.Badge,{badgeContent:e.grouping?.length,color:"primary",children:jsxRuntime.jsx(ma__default.default,{})})})}),jsxRuntime.jsx(material.Tooltip,{title:"Summary",children:jsxRuntime.jsx(material.IconButton,{onClick:n=>e.setSummaryAnchorEl(n.currentTarget),color:e.showSummary?"primary":"default",children:jsxRuntime.jsx(ga__default.default,{})})}),jsxRuntime.jsx(material.Tooltip,{title:"Columns",children:jsxRuntime.jsx(material.IconButton,{onClick:n=>e.setAnchorEl(n.currentTarget),children:jsxRuntime.jsx(da__default.default,{})})}),jsxRuntime.jsx(material.Tooltip,{title:"Export",children:jsxRuntime.jsx(material.IconButton,{onClick:e.handleExport,children:jsxRuntime.jsx(pa__default.default,{})})}),e.onOpenGraphReport&&jsxRuntime.jsx(material.Tooltip,{title:"Graphic Report",children:jsxRuntime.jsx(material.IconButton,{onClick:e.onOpenGraphReport,children:jsxRuntime.jsx(fa__default.default,{})})}),e.onLayoutSave&&!e.layoutManager&&jsxRuntime.jsx(material.Tooltip,{title:"Save Layout",children:jsxRuntime.jsx(material.IconButton,{onClick:n=>e.onLayoutSave(n),children:jsxRuntime.jsx(vn__default.default,{})})}),e.layoutManager,l.length>0&&jsxRuntime.jsx(material.Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:l.map((n,i)=>jsxRuntime.jsx(So__namespace.default.Fragment,{children:n},`toolbar-custom-${i}`))})]})]})};var Vo=e=>{let{onSelectAllClick:o,order:t,orderBy:r,numSelected:l=0,rowCount:n=0,onRequestSort:i,columns:a,visibleColumns:d,selectionMode:T,onColumnResize:k,columnWidths:w}=e,[C,E]=So.useState(null),M=So.useRef(null),m=p=>I=>{C||i(p);},f=(p,I,c)=>{p.preventDefault(),p.stopPropagation(),E(I),M.current={startX:p.clientX,startWidth:c,colId:I},document.addEventListener("mousemove",S),document.addEventListener("mouseup",y),document.body.style.cursor="col-resize";},S=p=>{if(!M.current)return;let{startX:I,startWidth:c,colId:u}=M.current,b=p.clientX-I,x=Math.max(50,c+b);k&&k(u,x);},y=()=>{E(null),M.current=null,document.removeEventListener("mousemove",S),document.removeEventListener("mouseup",y),document.body.style.cursor="";};return So.useEffect(()=>()=>{document.removeEventListener("mousemove",S),document.removeEventListener("mouseup",y);},[]),jsxRuntime.jsx(xa__default.default,{children:jsxRuntime.jsxs(Ca__default.default,{children:[(T==="multiple"||T==="single")&&jsxRuntime.jsx(Bo__default.default,{padding:"checkbox",sx:p=>({width:48,backgroundColor:p.palette.mode==="dark"?"#000000":"#f5f5f5",color:p.palette.mode==="dark"?"#ffffff":p.palette.text.primary}),children:jsxRuntime.jsx(va__default.default,{color:"primary",indeterminate:l>0&&l<n,checked:n>0&&l===n,onChange:o,disabled:T==="single"})}),a.filter(p=>d.includes(p.id)).map(p=>{let I=w?.[p.id]||p.minWidth||100;return jsxRuntime.jsxs(Bo__default.default,{align:"left",padding:p.disablePadding?"none":"normal",sortDirection:r===p.id?t:false,style:{width:I,minWidth:I,maxWidth:I},sx:c=>({position:"relative",backgroundColor:c.palette.mode==="dark"?"#000000":"#f5f5f5",color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary,fontWeight:"bold",userSelect:"none"}),children:[jsxRuntime.jsx(Sa__default.default,{active:r===p.id,direction:r===p.id?t:"asc",onClick:m(p.id),sx:c=>({"&.MuiTableSortLabel-root":{width:"100%"},"& .MuiTableSortLabel-icon":{color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary,opacity:r===p.id?1:0,transition:"opacity 0.2s"},"&:hover .MuiTableSortLabel-icon":{opacity:.5},"&.Mui-active .MuiTableSortLabel-icon":{opacity:1,color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary},fontWeight:"bold",color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary}),children:jsxRuntime.jsx(bo__default.default,{component:"span",sx:{overflow:"visible",textOverflow:"clip",whiteSpace:"normal",lineHeight:1.2,wordBreak:"break-word",pr:1},children:p.label})}),jsxRuntime.jsx(bo__default.default,{onMouseDown:c=>f(c,p.id,typeof I=="number"?I:100),onClick:c=>c.stopPropagation(),sx:{position:"absolute",right:0,top:0,bottom:0,width:5,cursor:"col-resize","&:hover":{backgroundColor:"primary.main",opacity:.5},zIndex:1}})]},p.id)})]})})};var Ho=e=>{let{visibleRows:o,visibleColumns:t,selected:r=[],handleClick:l,columns:n,toggleGroupExpand:i,expandedGroups:a=new Set,selectionMode:d}=e,T=C=>r.indexOf(C)!==-1,k=d==="multiple"||d==="single",w=t.length+(k?1:0);return jsxRuntime.jsxs(material.TableBody,{children:[o.map((C,E)=>{if(C.type==="group"){let M=a.has(C.id),m=C.childIds||[],f=m.filter(p=>T(p)).length,S=m.length>0&&f===m.length,y=f>0&&f<m.length,g=p=>{if(p.stopPropagation(),!!e.onSelectionChange)if(S){let I=r.filter(c=>!m.includes(c));e.onSelectionChange(I);}else {let I=Array.from(new Set([...r,...m]));e.onSelectionChange(I);}};return jsxRuntime.jsx(material.TableRow,{sx:p=>({backgroundColor:p.palette.mode==="dark"?"#111111":"#f5f5f5","& .MuiTableCell-root":{color:p.palette.text.primary,borderBottomColor:p.palette.divider},"& .MuiIconButton-root":{color:p.palette.text.primary},"& .MuiCheckbox-root":{color:p.palette.text.secondary},"& .MuiCheckbox-root.Mui-checked, & .MuiCheckbox-root.MuiCheckbox-indeterminate":{color:p.palette.primary.main}}),children:jsxRuntime.jsx(material.TableCell,{colSpan:w,sx:{py:1,pl:C.level*4+2},children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center"},children:[jsxRuntime.jsx(material.IconButton,{size:"small",onClick:()=>i&&i(C.id),sx:{mr:1},children:M?jsxRuntime.jsx(Ra__default.default,{}):jsxRuntime.jsx(Ma__default.default,{})}),k&&jsxRuntime.jsx(material.Checkbox,{size:"small",checked:S,indeterminate:y,onChange:g,onClick:p=>p.stopPropagation(),sx:{mr:1,p:.5}}),jsxRuntime.jsxs(material.Typography,{variant:"body2",fontWeight:"bold",color:"text.primary",children:[C.field,": ",C.value," (",C.count,")"]})]})})},C.id)}else {let M=C.data||C,m=C.id||M.id||E,f=T(m),S=`enhanced-table-checkbox-${E}`,g=(C.level!==void 0?C.level:0)*4;return jsxRuntime.jsxs(material.TableRow,{hover:true,onClick:p=>l&&l(p,M),role:"checkbox","aria-checked":f,tabIndex:-1,selected:f,sx:{cursor:"pointer"},children:[k&&jsxRuntime.jsx(material.TableCell,{padding:"checkbox",sx:{pl:g>0?g+1:void 0},children:jsxRuntime.jsx(material.Checkbox,{color:"primary",checked:f,inputProps:{"aria-labelledby":S}})}),n.filter(p=>t.includes(p.id)).map((p,I)=>{let u=!k&&I===0&&g>0?{pl:g+2}:{};return jsxRuntime.jsx(material.TableCell,{align:"left",sx:u,children:p.render?p.render(M[p.id],M):(function(){let x=M[p.id];if(p.numeric){if(typeof x=="number")return x.toLocaleString();if(typeof x=="string"&&x.trim()!==""&&!isNaN(Number(x)))return Number(x).toLocaleString()}return x})()},p.id)})]},m)}}),o.length===0&&jsxRuntime.jsx(material.TableRow,{children:jsxRuntime.jsx(material.TableCell,{colSpan:w,align:"center",children:"No data"})})]})};var Oo=e=>{let{visibleColumns:o,summaryRow:t,selectionMode:r}=e;if(!e.showSummary)return null;let l=r==="multiple"||r==="single";return jsxRuntime.jsx(material.TableFooter,{sx:{position:"sticky",bottom:0,zIndex:e.zIndex,bgcolor:"background.paper"},children:jsxRuntime.jsxs(material.TableRow,{children:[l&&jsxRuntime.jsx(material.TableCell,{padding:"checkbox",sx:{bgcolor:"background.paper"}}),o.map(n=>jsxRuntime.jsx(material.TableCell,{sx:{fontWeight:"bold",fontSize:"0.875rem",bgcolor:"background.paper",color:"text.primary"},children:(function(){let a=t[n];return a==null||a===""?"":typeof a=="number"?a.toLocaleString():typeof a=="string"&&a.trim()!==""&&!isNaN(Number(a))?Number(a).toLocaleString():a})()},n))]})})};var Wo=e=>jsxRuntime.jsx(material.Box,{sx:{p:2},children:jsxRuntime.jsx(material.Typography,{children:"Mobile View Not Implemented"})});var _o=({groupAnchorEl:e,setGroupAnchorEl:o,grouping:t,setGrouping:r,columns:l,toggleGroupField:n})=>jsxRuntime.jsxs(material.Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsxRuntime.jsxs(material.Box,{sx:{p:1,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[jsxRuntime.jsx(material.Typography,{variant:"subtitle2",sx:{px:1},children:"Group By"}),t.length>0&&jsxRuntime.jsx(material.Button,{size:"small",color:"error",onClick:()=>r([]),startIcon:jsxRuntime.jsx(Ga__default.default,{}),children:"Clear All"})]}),jsxRuntime.jsx(material.Divider,{}),l.map(i=>{let a=t.includes(i.id),d=t.indexOf(i.id)+1;return jsxRuntime.jsx(material.MenuItem,{onClick:()=>n(i.id),children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsxRuntime.jsx(material.Checkbox,{checked:a,size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:i.label}),a&&jsxRuntime.jsx(material.Badge,{badgeContent:d,color:"primary",sx:{mr:2}})]})},i.id)})]}),jo=({anchorEl:e,setAnchorEl:o,columns:t,visibleColumns:r,toggleColumnVisibility:l})=>jsxRuntime.jsxs(material.Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.ListItemText,{primary:"Visible Columns"})}),jsxRuntime.jsx(material.Divider,{}),t.map(n=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>l(n.id),children:[jsxRuntime.jsx(material.Checkbox,{checked:r.includes(n.id),size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:n.label})]},n.id))]}),Uo=({anchorEl:e,setAnchorEl:o,showSummary:t,setShowSummary:r,columns:l,summaryColumns:n,toggleSummaryColumn:i})=>jsxRuntime.jsxs(material.Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsxRuntime.jsx(material.MenuItem,{children:jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Switch,{checked:t,onChange:a=>r(a.target.checked),size:"small"}),label:"Show Summary Row"})}),jsxRuntime.jsx(material.Divider,{}),l.filter(a=>a.numeric).map(a=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>i(a.id),disabled:!t,children:[jsxRuntime.jsx(material.Checkbox,{checked:n.includes(a.id),size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:a.label})]},a.id)),l.filter(a=>a.numeric).length===0&&jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.ListItemText,{primary:"No numeric columns"})})]}),Ko=({contextMenu:e,handleCloseContextMenu:o,columns:t,visibleColumns:r,toggleColumnVisibility:l})=>jsxRuntime.jsxs(material.Menu,{open:e!==null,onClose:o,anchorReference:"anchorPosition",anchorPosition:e!==null?{top:e.mouseY,left:e.mouseX}:void 0,children:[jsxRuntime.jsx(material.MenuItem,{onClick:o,children:"Copy"}),jsxRuntime.jsx(material.Divider,{}),jsxRuntime.jsx(material.MenuItem,{disabled:true,children:"Visible Columns"}),t.map(n=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>l(n.id),children:[jsxRuntime.jsx(material.ListItemIcon,{children:r.includes(n.id)&&jsxRuntime.jsx(Oa__default.default,{fontSize:"small"})}),jsxRuntime.jsx(material.ListItemText,{children:n.label})]},n.id))]});var je=(e,o=2)=>e.toLocaleString(void 0,{maximumFractionDigits:o}),qo=({kpis:e})=>{let o=[{label:"Total Records",value:je(e.totalRecords,0),color:"text.primary"},{label:"Total Report",value:je(e.totalReportHours),color:"text.primary"},{label:"Total Billable",value:je(e.totalBillableHours),color:"success.main"},{label:"Efficiency",value:`${e.efficiency.toFixed(2)}%`,color:"warning.main"},{label:"Amount",value:je(e.totalAmount),color:"info.main"},{label:"Flagged",value:je(e.flaggedCount,0),color:"error.main"}];return jsxRuntime.jsx(material.Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"repeat(2, minmax(0, 1fr))",lg:"repeat(6, minmax(0, 1fr))"},gap:1.5},children:o.map(t=>jsxRuntime.jsxs(material.Paper,{variant:"outlined",sx:{p:1.5,borderRadius:2,minHeight:96,display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",children:t.label}),jsxRuntime.jsx(material.Typography,{variant:"h4",fontWeight:800,sx:{color:t.color},children:t.value})]},t.label))})};var bt=["#1E88E5","#1ABC9C","#FBC02D","#EF5350","#7E57C2","#78909C"],Ua=({data:e})=>{let o=Math.max(...e.map(t=>t.value),1);return jsxRuntime.jsx(material.Stack,{spacing:1,children:e.map(t=>jsxRuntime.jsxs(material.Box,{sx:{display:"grid",gridTemplateColumns:"140px 1fr 64px",gap:1},children:[jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",noWrap:true,title:t.name,children:t.name}),jsxRuntime.jsx(material.Box,{sx:{alignSelf:"center",bgcolor:"action.hover",height:10,borderRadius:999,overflow:"hidden"},children:jsxRuntime.jsx(material.Box,{sx:{width:`${t.value/o*100}%`,height:"100%",bgcolor:"primary.main"}})}),jsxRuntime.jsx(material.Typography,{variant:"caption",sx:{textAlign:"right",fontWeight:600},children:t.value.toFixed(1)})]},t.name))})},Ka=({data:e})=>{let o=Math.max(...e.map(t=>t.value),1);return jsxRuntime.jsx(material.Box,{sx:{display:"flex",gap:1,alignItems:"flex-end",minHeight:210},children:e.map(t=>jsxRuntime.jsxs(material.Box,{sx:{flex:1,minWidth:0},children:[jsxRuntime.jsx(material.Box,{sx:{height:`${Math.max(t.value/o*180,6)}px`,bgcolor:"primary.main",borderRadius:"8px 8px 0 0"}}),jsxRuntime.jsx(material.Typography,{variant:"caption",noWrap:true,title:t.name,sx:{display:"block",mt:.5},children:t.name}),jsxRuntime.jsxs(material.Typography,{variant:"caption",color:"text.secondary",children:[t.value.toFixed(1),"%"]})]},t.name))})},Ya=({data:e})=>{if(e.length===0)return jsxRuntime.jsx(material.Typography,{variant:"body2",color:"text.secondary",children:"No data"});let o=0,r=`conic-gradient(${e.map((l,n)=>{let i=o;return o+=l.percent,`${bt[n%bt.length]} ${i}% ${o}%`}).join(", ")})`;return jsxRuntime.jsxs(material.Stack,{direction:{xs:"column",sm:"row"},spacing:2,alignItems:"center",children:[jsxRuntime.jsx(material.Box,{sx:{width:180,height:180,borderRadius:"50%",background:r,position:"relative"},children:jsxRuntime.jsx(material.Box,{sx:{position:"absolute",inset:30,bgcolor:"background.paper",borderRadius:"50%"}})}),jsxRuntime.jsx(material.Stack,{spacing:1,sx:{minWidth:180},children:e.map((l,n)=>jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsxRuntime.jsx(material.Box,{sx:{width:10,height:10,borderRadius:"50%",bgcolor:bt[n%bt.length]}}),jsxRuntime.jsx(material.Typography,{variant:"caption",sx:{flex:1},children:l.name}),jsxRuntime.jsxs(material.Typography,{variant:"caption",sx:{fontWeight:700},children:[l.percent.toFixed(0),"%"]})]},l.name))})]})},ao=({title:e,subtitle:o,children:t})=>jsxRuntime.jsxs(material.Paper,{variant:"outlined",sx:{p:2,borderRadius:2},children:[jsxRuntime.jsx(material.Typography,{variant:"subtitle1",fontWeight:700,children:e}),jsxRuntime.jsx(material.Typography,{variant:"body2",color:"text.secondary",sx:{mb:2},children:o}),t]}),Xo=({billableByPrimary:e,efficiencyBySecondary:o,statusDistribution:t})=>jsxRuntime.jsxs(material.Box,{sx:{display:"grid",gap:1.5,gridTemplateColumns:{xs:"1fr",lg:"1.2fr 1.2fr 1fr"}},children:[jsxRuntime.jsx(ao,{title:"Billable by Dimension",subtitle:"Top values by billable hours",children:jsxRuntime.jsx(Ua,{data:e})}),jsxRuntime.jsx(ao,{title:"Efficiency by Person",subtitle:"Lowest efficiency first",children:jsxRuntime.jsx(Ka,{data:o})}),jsxRuntime.jsx(ao,{title:"Status Distribution",subtitle:"Record ratio by status",children:jsxRuntime.jsx(Ya,{data:t})})]});var Zo=({open:e,onClose:o,model:t,tableContent:r})=>jsxRuntime.jsx(material.Dialog,{open:e,onClose:o,fullScreen:true,children:jsxRuntime.jsxs(material.Box,{sx:{height:"100%",display:"flex",flexDirection:"column",bgcolor:"background.default"},children:[jsxRuntime.jsx(material.Box,{sx:{p:2,borderBottom:1,borderColor:"divider"},children:jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",justifyContent:"space-between",spacing:2,children:[jsxRuntime.jsxs(material.Stack,{direction:"row",spacing:1.5,alignItems:"center",children:[jsxRuntime.jsx(material.Typography,{variant:"h5",fontWeight:800,children:t.title}),jsxRuntime.jsx(material.Chip,{size:"small",label:`${t.kpis.totalRecords} records`})]}),jsxRuntime.jsx(material.IconButton,{onClick:o,children:jsxRuntime.jsx(Qa__default.default,{})})]})}),jsxRuntime.jsxs(material.Box,{sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,overflow:"auto",minHeight:0},children:[jsxRuntime.jsx(qo,{kpis:t.kpis}),jsxRuntime.jsx(Xo,{billableByPrimary:t.charts.billableByPrimary,efficiencyBySecondary:t.charts.efficiencyBySecondary,statusDistribution:t.charts.statusDistribution}),r]})]})});var Ie={primaryDimension:["Client","Customer","Category","Project"],secondaryDimension:["Person","Consultant","Owner","Name"],status:["Status","state"],date:["Date","WorkDate","CreatedAt"],description:["Description","Task","Title","Memo"],reportHours:["Report_Hour","Report Hours","Hours","ReportHours"],billableHours:["Billable_Hour","Billable Hours","BillableHours"],amount:["Amount","Billable_Amount","Total_Amount","Value"]},er=5,Qo=e=>e.toLowerCase().replace(/[\s_-]/g,""),ke=(e,o,t,r)=>{if(o)return o;if(e.length===0)return r;let l=Object.keys(e[0]),n=new Map(l.map(i=>[Qo(i),i]));for(let i of t){let a=n.get(Qo(i));if(a)return a}return l[0]||r},xe=e=>{if(typeof e=="number")return Number.isFinite(e)?e:0;if(typeof e=="string"){let o=Number(e.replace(/,/g,"").trim());return Number.isFinite(o)?o:0}return 0},Ce=(e,o)=>e==null||e===""?o:String(e),tr=(e,o,t,r)=>{let l=new Map;return e.forEach(n=>{let i=Ce(n[o],"Unassigned");l.set(i,(l.get(i)||0)+xe(n[t]));}),Array.from(l.entries()).map(([n,i])=>({name:n,value:i})).sort((n,i)=>i.value-n.value).slice(0,r)},or=(e,o,t,r,l)=>{let n=new Map;return e.forEach(i=>{let a=Ce(i[o],"Unassigned"),d=n.get(a)||{report:0,billable:0};d.report+=xe(i[t]),d.billable+=xe(i[r]),n.set(a,d);}),Array.from(n.entries()).map(([i,a])=>({name:i,value:a.report>0?a.billable/a.report*100:0})).sort((i,a)=>i.value-a.value).slice(0,l)},nr=(e,o)=>{let t=e.length;if(t===0)return [];let r=new Map;return e.forEach(l=>{let n=Ce(l[o],"Unassigned");r.set(n,(r.get(n)||0)+1);}),Array.from(r.entries()).map(([l,n])=>({name:l,value:n,percent:n/t*100}))},en=({rows:e,config:o})=>{let t=So.useMemo(()=>{let d=o?.fieldMapping;return {primaryDimension:ke(e,d?.primaryDimension,Ie.primaryDimension,"Category"),secondaryDimension:ke(e,d?.secondaryDimension,Ie.secondaryDimension,"Owner"),status:ke(e,d?.status,Ie.status,"Status"),date:ke(e,d?.date,Ie.date,"Date"),description:ke(e,d?.description,Ie.description,"Description"),reportHours:ke(e,d?.reportHours,Ie.reportHours,"ReportHours"),billableHours:ke(e,d?.billableHours,Ie.billableHours,"BillableHours"),amount:ke(e,d?.amount,Ie.amount,"Amount")}},[e,o?.fieldMapping]),r=So.useMemo(()=>e.map((d,T)=>{let k=xe(d[t.reportHours]),w=xe(d[t.billableHours]),C=xe(d[t.amount]),E=k>0?w/k*100:0;return {id:`graph-row-${T}`,Date:Ce(d[t.date],""),Primary:Ce(d[t.primaryDimension],"Unassigned"),Secondary:Ce(d[t.secondaryDimension],"Unassigned"),Description:Ce(d[t.description],""),ReportHours:k,BillableHours:w,Amount:C,Efficiency:E,Status:Ce(d[t.status],"Unassigned")}}),[e,t]),l=So.useMemo(()=>{let d=r.length,T=r.reduce((m,f)=>m+xe(f.ReportHours),0),k=r.reduce((m,f)=>m+xe(f.BillableHours),0),w=r.reduce((m,f)=>m+xe(f.Amount),0),C=T>0?k/T*100:0,E=o?.statusFlagValues||["flag","flagged","warning","risk"],M=r.filter(m=>E.includes(Ce(m.Status,"").toLowerCase())).length;return {totalRecords:d,totalReportHours:T,totalBillableHours:k,efficiency:C,totalAmount:w,flaggedCount:M}},[r,o?.statusFlagValues]),n=o?.topN||er,i=So.useMemo(()=>({billableByPrimary:tr(r,"Primary","BillableHours",n),efficiencyBySecondary:or(r,"Secondary","ReportHours","BillableHours",n),statusDistribution:nr(r,"Status")}),[r,n]),a=So.useMemo(()=>({title:o?.title||"Graphic Report",kpis:l,charts:i,table:{columns:[{id:"Date",label:t.date},{id:"Primary",label:t.primaryDimension},{id:"Secondary",label:t.secondaryDimension},{id:"Description",label:t.description},{id:"ReportHours",label:"Report Hours",align:"right"},{id:"BillableHours",label:"Billable Hours",align:"right"},{id:"Amount",label:"Amount",align:"right"},{id:"Efficiency",label:"Efficiency",align:"right"},{id:"Status",label:t.status}],rows:r}}),[i,o?.title,t,l,r]);return {fieldMapping:t,model:a}};var vt=({variants:e,currentVariantId:o,onLoad:t,onSave:r,onDelete:l,onSetDefault:n})=>{let i="0.75rem",[a,d]=So.useState(false),[T,k]=So.useState(""),[w,C]=So.useState(false),[E,M]=So.useState(false),m=e.find(y=>y.id===o);return jsxRuntime.jsxs(material.Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsxRuntime.jsx(material.Typography,{variant:"body2",sx:{fontWeight:"bold",minWidth:"fit-content",fontSize:i},children:"Variant:"}),jsxRuntime.jsx(material.Autocomplete,{size:"small",sx:{width:200,"& .MuiInputBase-root":{fontSize:i},"& .MuiInputBase-input":{fontSize:i},"& .MuiAutocomplete-noOptions":{fontSize:i}},noOptionsText:jsxRuntime.jsx(material.Typography,{sx:{fontSize:i},children:"No options"}),options:e,getOptionLabel:y=>y.name+(y.isDefault?" (Default)":""),value:m||null,onChange:(y,g)=>{g&&t(g);},renderInput:y=>jsxRuntime.jsx(material.TextField,{...y,variant:"outlined",size:"small",InputProps:{...y.InputProps,sx:{fontSize:i}},placeholder:"Select Variant"}),renderOption:(y,g)=>jsxRuntime.jsx("li",{...y,children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsxRuntime.jsx(material.Typography,{sx:{flex:1,fontSize:i},children:g.name}),g.isDefault&&jsxRuntime.jsx(pr__default.default,{fontSize:"small",color:"action"})]})})}),jsxRuntime.jsx(material.Tooltip,{title:"Save View",children:jsxRuntime.jsx(material.IconButton,{onClick:()=>{k(m?.name||"New Variant"),C(m?.isDefault||false),M(m?.isPublic||false),d(true);},size:"small",color:"primary",children:jsxRuntime.jsx(vn__default.default,{})})}),jsxRuntime.jsxs(material.Dialog,{open:a,onClose:()=>d(false),children:[jsxRuntime.jsx(material.DialogTitle,{children:"Save View"}),jsxRuntime.jsxs(material.DialogContent,{children:[jsxRuntime.jsx(material.TextField,{autoFocus:true,margin:"dense",label:"View Name",fullWidth:true,variant:"outlined",value:T,onChange:y=>k(y.target.value)}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:w,onChange:y=>C(y.target.checked)}),label:"Set as Default"}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:E,onChange:y=>M(y.target.checked)}),label:"Public (All Users)"})]}),jsxRuntime.jsxs(material.DialogActions,{children:[jsxRuntime.jsx(material.Button,{onClick:()=>d(false),children:"Cancel"}),jsxRuntime.jsx(material.Button,{onClick:()=>{r({name:T,isDefault:w,isPublic:E,description:""}),d(false);},variant:"contained",children:"Save"})]})]})]})};var fr="http://127.0.0.1:8515",sn=({appId:e,tableKey:o="default",currentFilters:t,currentLayoutId:r,layoutRefs:l,onLoad:n,serviceUrl:i=fr,onError:a,onSuccess:d,currentVariantId:T,onVariantChange:k})=>{let[w,C]=So.useState([]),[E,M]=So.useState(""),m=T!==void 0?T:E,f=c=>{T===void 0&&M(c),k&&k(c);},S=So.useCallback(async()=>{if(!e)return [];try{let c=await fetch(`${i}/api/variants?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!c.ok)throw new Error("Failed to fetch variants");let u=await c.json();C(u);let b=u.find(x=>x.isDefault);return b&&!m&&(f(b.id),n(b)),u}catch(c){return console.error("Error fetching variants",c),a&&a("Failed to load variants"),[]}},[e,o,i,a,m,n]);return So.useEffect(()=>{S();},[e,o]),jsxRuntime.jsx(vt,{variants:w,currentVariantId:m,onLoad:c=>{f(c.id),n(c);},onSave:async c=>{try{let u=w.find(L=>L.name===c.name),b=u?u.id:Date.now().toString(),x=[];if(u&&(Array.isArray(u.filters)?x=[...u.filters]:u.filters&&(x=[{scope:"default",filters:u.filters}])),c.scope==="Search"||c.scope==="Both"){let L=(Array.isArray(t),t);if(L)if(Array.isArray(L)&&L.length>0&&L[0].scope)L.forEach(V=>{let A=x.findIndex(N=>N.scope===V.scope);A>=0?x[A]=V:x.push(V);});else {let V={scope:o,filters:L},A=x.findIndex(N=>N.scope===o);A>=0?x[A]=V:x.push(V);}}let s=u?.layout||{},R=[];if(u&&Array.isArray(u.layoutRefs)&&(R=[...u.layoutRefs]),c.scope==="Layout"||c.scope==="Both")if(l&&l.length>0)l.forEach(L=>{let V=R.findIndex(A=>A.tableKey===L.tableKey);V>=0?R[V]=L:R.push(L);});else {let L={tableKey:o,layoutId:r||null},V=R.findIndex(A=>A.tableKey===o);V>=0?R[V]=L:R.push(L);}let v={appId:e,tableKey:o,...c,id:b,createdAt:new Date().toISOString(),filters:x,layout:s,layoutRefs:R};if(!(await fetch(`${i}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(v)})).ok)throw new Error("Failed to save variant");d&&d("Variant saved successfully"),await S(),f(b),n(v);}catch(u){console.error("Error saving variant",u),a&&a("Failed to save variant");}},onDelete:async c=>{try{if(!(await fetch(`${i}/api/variants/${c}`,{method:"DELETE"})).ok)throw new Error("Failed to delete variant");m===c&&f(""),S(),d&&d("Variant deleted successfully");}catch(u){console.error("Error deleting variant",u),a&&a("Failed to delete variant");}},onSetDefault:async c=>{try{let u=w.find(s=>s.id===c);if(!u)return;let b={appId:e,tableKey:o,...u,isDefault:!0};if(!(await fetch(`${i}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)})).ok)throw new Error("Failed to set default variant");await S(),d&&d("Default variant updated");}catch(u){console.error("Error setting default variant",u),a&&a("Failed to update default variant");}}})};Ee__default.default.extend(Pr__default.default);var Er=[null,null],uo="0.75rem",Lr=material.styled(PickersDay.PickersDay,{shouldForwardProp:e=>e!=="isInRange"&&e!=="isStart"&&e!=="isEnd"&&e!=="isHovered"})(({theme:e,isInRange:o,isStart:t,isEnd:r,isHovered:l})=>({...o&&{borderRadius:0,backgroundColor:e.palette.primary.light,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.main}},...l&&!o&&!t&&!r&&{borderRadius:0,backgroundColor:e.palette.action.hover,border:`1px dashed ${e.palette.primary.main}`},...t&&{borderRadius:"50% 0 0 50%",backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.dark}},...r&&{borderRadius:"0 50% 50% 0",backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.dark}},...t&&r&&{borderRadius:"50%"}})),un=({label:e="Date Range",value:o=Er,onChange:t})=>{let[r,l]=So.useState(null),[n,i]=So.useState(o),[a,d]=So.useState("start"),[T,k]=So.useState(null),[w,C]=So.useState(o[0]||Ee__default.default()),E=So__namespace.default.useRef(o);So.useEffect(()=>{let[b,x]=o,[s,R]=E.current,v=V=>V&&typeof V.isSame=="function",z=!(b===null&&s===null||v(b)&&v(s)&&b.isSame(s,"day")),L=!(x===null&&R===null||v(x)&&v(R)&&x.isSame(R,"day"));(z||L)&&(i(o),o[0]&&v(o[0])&&C(o[0])),E.current=o;},[o]);let M=b=>{l(b.currentTarget);},m=()=>{l(null),d("start"),k(null);},f=!!r,S=b=>{if(!b)return;let x=[...n];if(a==="start")x=[b,null],d("end");else {let s=x[0];s&&b.isBefore(s)?(x=[b,null],d("end")):(x=[s,b],d("start"));}i(x);},y=b=>{let x=Ee__default.default(),s=[null,null];switch(b){case "today":s=[x,x];break;case "week":s=[x.startOf("week"),x.endOf("week")];break;case "month":s=[x.startOf("month"),x.endOf("month")];break}i(s),d("start"),C(x);},g=()=>{i([null,null]),d("start"),C(Ee__default.default());},p=()=>{t&&t(n),m();},I=()=>{i(o),d("start"),m();},c=So.useCallback(b=>{let{day:x,...s}=b,[R,v]=n,z=R?x.isSame(R,"day"):false,L=v?x.isSame(v,"day"):false,V=R&&v?x.isBetween(R,v,"day","()"):false,A=false;return a==="end"&&R&&!v&&T&&x.isAfter(R,"day")&&x.isBefore(T.add(1,"day"),"day")&&(A=true),jsxRuntime.jsx(Lr,{...s,day:x,disableMargin:true,isStart:z,isEnd:L,isInRange:V||A,onMouseEnter:()=>k(x)})},[n,a,T]),u=b=>b?b.format("YYYY-MM-DD"):"";return jsxRuntime.jsxs(material.Box,{children:[jsxRuntime.jsx(material.TextField,{label:e,value:n[0]?`${u(n[0])} - ${u(n[1])}`:"",onClick:M,fullWidth:true,size:"small",InputLabelProps:{sx:{fontSize:uo}},InputProps:{readOnly:true,sx:{fontSize:uo,"& .MuiOutlinedInput-input":{fontSize:uo},paddingRight:"4px"},endAdornment:jsxRuntime.jsxs(material.InputAdornment,{position:"end",sx:{ml:0},children:[(n[0]||n[1])&&jsxRuntime.jsx(material.IconButton,{size:"small",onClick:b=>{b.stopPropagation(),g();},edge:"end",sx:{mr:.5,padding:"2px"},children:jsxRuntime.jsx(Rr__default.default,{sx:{fontSize:"1rem"}})}),jsxRuntime.jsx(material.IconButton,{size:"small",edge:"end",onClick:M,sx:{padding:"2px"},children:jsxRuntime.jsx(Mr__default.default,{sx:{fontSize:"1rem"},color:"action"})})]})}}),jsxRuntime.jsxs(material.Popover,{open:f,anchorEl:r,onClose:m,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},slotProps:{paper:{sx:{display:"flex",flexDirection:"column",p:0,minWidth:320}}},children:[jsxRuntime.jsx(material.Box,{sx:{p:2,bgcolor:"background.default",borderBottom:1,borderColor:"divider"},children:jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:2,justifyContent:"space-between",children:[jsxRuntime.jsxs(material.Box,{sx:{p:1,border:1,borderColor:a==="start"?"primary.main":"divider",borderRadius:1,bgcolor:a==="start"?"action.hover":"transparent",flex:1,cursor:"pointer"},onClick:()=>d("start"),children:[jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",display:"block",children:"Start Date"}),jsxRuntime.jsx(material.Typography,{variant:"body2",fontWeight:500,children:n[0]?n[0].format("MMM DD, YYYY"):"Select..."})]}),jsxRuntime.jsx(Dr__default.default,{color:"action",fontSize:"small"}),jsxRuntime.jsxs(material.Box,{sx:{p:1,border:1,borderColor:a==="end"?"primary.main":"divider",borderRadius:1,bgcolor:a==="end"?"action.hover":"transparent",flex:1,cursor:"pointer"},onClick:()=>{n[0]&&d("end");},children:[jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",display:"block",children:"End Date"}),jsxRuntime.jsx(material.Typography,{variant:"body2",fontWeight:500,children:n[1]?n[1].format("MMM DD, YYYY"):"Select..."})]})]})}),jsxRuntime.jsx(material.Box,{sx:{p:2,pb:0},children:jsxRuntime.jsxs(material.Stack,{direction:"row",spacing:1,justifyContent:"center",children:[jsxRuntime.jsx(material.Chip,{label:"Today",onClick:()=>y("today"),clickable:true,size:"small",variant:"outlined"}),jsxRuntime.jsx(material.Chip,{label:"This Week",onClick:()=>y("week"),clickable:true,size:"small",variant:"outlined"}),jsxRuntime.jsx(material.Chip,{label:"This Month",onClick:()=>y("month"),clickable:true,size:"small",variant:"outlined"})]})}),jsxRuntime.jsx(DateCalendar.DateCalendar,{value:null,referenceDate:w,onMonthChange:C,onYearChange:C,onChange:S,slots:{day:c},views:["day"],showDaysOutsideCurrentMonth:true,sx:{m:0}}),jsxRuntime.jsx(material.Divider,{}),jsxRuntime.jsxs(material.Stack,{direction:"row",justifyContent:"flex-end",spacing:1,sx:{p:2},children:[jsxRuntime.jsx(material.Button,{size:"small",onClick:I,color:"inherit",children:"Cancel"}),jsxRuntime.jsx(material.Button,{size:"small",variant:"contained",onClick:p,children:"Done"})]})]})]})};var It={equals:"=",contains:"\u2287",notContains:"\u2285",wildcard:"*","=":"=","!=":"!=",">":">","<":"<",">=":"\u2265","<=":"\u2264",between:"\u2194"},$r={equals:"Equals",contains:"Contains",notContains:"Does Not Contain",wildcard:"Wildcard Search","=":"Equals","!=":"Not Equals",">":"Greater Than","<":"Less Than",">=":"Greater Than or Equal","<=":"Less Than or Equal",between:"Between"},_r=["equals","contains","notContains","wildcard"],gn=["=","!=",">","<",">=","<=","between"],Z="0.75rem",jr=({field:e,value:o,onChange:t})=>{let[r,l]=So.useState(null),[n,i]=So.useState(null),[a,d]=So.useState(""),[T,k]=So.useState(""),[w,C]=So.useState(false),[E,M]=So.useState(""),[m,f]=So.useState("");So.useEffect(()=>{let s=setTimeout(()=>{f(E);},1e3);return ()=>clearTimeout(s)},[E]);let S=o?.operator||(e.type==="number"?"=":"equals"),y=o?.value,g=s=>$r[s]||s,p=s=>{l(s.currentTarget);},I=s=>{t({...o,operator:s,value:y}),l(null);},c={size:"small",fullWidth:true,variant:"outlined",InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}},SelectProps:{MenuProps:{PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,paddingTop:"4px",paddingBottom:"4px",minHeight:"auto"}}}}}},u=e.type||"text";if(u==="date"){let R=(v=>{if(!v)return [null,null];if(Array.isArray(v)&&v.length===2){let z=v[0]?Ee__default.default.isDayjs(v[0])?v[0]:Ee__default.default(v[0]):null,L=v[1]?Ee__default.default.isDayjs(v[1])?v[1]:Ee__default.default(v[1]):null;return [z,L]}return Ee__default.default.isDayjs(v)||typeof v=="string"?[Ee__default.default.isDayjs(v)?v:Ee__default.default(v),null]:[null,null]})(y);return jsxRuntime.jsx(un,{label:e.label,value:R,onChange:v=>t({value:v,operator:"between"})})}if(u==="number"&&S==="between"){let s=()=>{t({value:[a,T],operator:"between"}),i(null);},R=Array.isArray(y)?`${y[0]||""} - ${y[1]||""}`:"";return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(material.TextField,{...c,label:e.label,value:R,placeholder:"Min - Max",InputProps:{...c.InputProps,startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(material.Tooltip,{title:g("between"),children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:p,sx:{width:24,height:24,fontSize:Z},children:It.between})})}),readOnly:true},onClick:v=>i(v.currentTarget)}),jsxRuntime.jsx(material.Menu,{anchorEl:r,open:!!r,onClose:()=>l(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,minHeight:"auto",py:.5}}},children:gn.map(v=>jsxRuntime.jsxs(material.MenuItem,{selected:v===S,onClick:()=>I(v),children:[jsxRuntime.jsx(material.Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:It[v]}),jsxRuntime.jsx(material.ListItemText,{primary:g(v),primaryTypographyProps:{fontSize:Z}})]},v))}),jsxRuntime.jsx(material.Popover,{open:!!n,anchorEl:n,onClose:()=>i(null),anchorOrigin:{vertical:"bottom",horizontal:"left"},children:jsxRuntime.jsxs(material.Box,{sx:{p:2,display:"flex",gap:1,alignItems:"center"},children:[jsxRuntime.jsx(material.TextField,{size:"small",label:"Min",type:"number",value:a,onChange:v=>d(v.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}}}),jsxRuntime.jsx(Wr__default.default,{color:"action"}),jsxRuntime.jsx(material.TextField,{size:"small",label:"Max",type:"number",value:T,onChange:v=>k(v.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}}}),jsxRuntime.jsx(material.Button,{variant:"contained",size:"small",onClick:s,children:"OK"})]})})]})}if(u==="select")return jsxRuntime.jsxs(material.TextField,{...c,select:true,label:e.label,value:y||"",onChange:s=>t({...o,value:s.target.value,operator:"equals"}),children:[jsxRuntime.jsx(material.MenuItem,{value:"",children:jsxRuntime.jsx("em",{children:"None"})}),e.options?.map(s=>jsxRuntime.jsx(material.MenuItem,{value:s.value,children:s.label},s.value))]});if(u==="multi-select"){let s=Array.isArray(y)?y:[],R=e.options?.filter(v=>v.label.toLowerCase().includes(m.toLowerCase()))||[];return jsxRuntime.jsxs(material.TextField,{...c,select:true,label:e.label,value:s,onChange:v=>t({...o,value:v.target.value,operator:"anyOf"}),SelectProps:{...c.SelectProps,multiple:true,onClose:()=>{M(""),f("");},renderValue:v=>{if(!Array.isArray(v)||v.length===0)return jsxRuntime.jsx("em",{children:"None"});let z=V=>e.options?.find(A=>A.value===V)?.label||V,L=v.map(z);return L.length>2?`${L.slice(0,2).join(", ")} +${L.length-2}`:L.join(", ")}},children:[jsxRuntime.jsx(material.ListSubheader,{children:jsxRuntime.jsx(material.TextField,{size:"small",autoFocus:true,placeholder:"Search...",fullWidth:true,InputProps:{startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(mn__default.default,{fontSize:"small"})}),sx:{fontSize:Z}},value:E,onChange:v=>M(v.target.value),onKeyDown:v=>{v.key!=="Escape"&&v.stopPropagation();},onClick:v=>v.stopPropagation()})}),R.length>0?R.map(v=>jsxRuntime.jsxs(material.MenuItem,{value:v.value,children:[jsxRuntime.jsx(material.Checkbox,{checked:s.indexOf(v.value)>-1,size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:v.label,primaryTypographyProps:{fontSize:Z}})]},v.value)):jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.ListItemText,{primary:"No options found",primaryTypographyProps:{fontSize:Z}})})]})}let b=u==="number"?gn:_r,x=w||y!==void 0&&y!==""&&y!==null||!!r;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(material.TextField,{...c,label:e.label,sx:{minWidth:"120px"},value:y||"",type:u==="number"?"number":"text",onChange:s=>t({...o,value:s.target.value,operator:S}),onFocus:()=>C(true),onBlur:()=>C(false),InputProps:{...c.InputProps,startAdornment:x?jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(material.Tooltip,{title:g(S),children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:p,onMouseDown:s=>s.preventDefault(),sx:{width:24,height:24,fontSize:Z,fontWeight:"bold",color:"primary.main",bgcolor:"action.hover"},children:It[S]})})}):null,endAdornment:e.hasSearchIcon?jsxRuntime.jsx(material.InputAdornment,{position:"end",children:jsxRuntime.jsx(mn__default.default,{color:"action"})}):void 0}}),jsxRuntime.jsx(material.Menu,{anchorEl:r,open:!!r,onClose:()=>l(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,minHeight:"auto",py:.5}}},children:b.map(s=>jsxRuntime.jsxs(material.MenuItem,{selected:s===S,onClick:()=>I(s),children:[jsxRuntime.jsx(material.Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:It[s]}),jsxRuntime.jsx(material.ListItemText,{primary:g(s),primaryTypographyProps:{fontSize:Z}})]},s))})]})},Xe=({fields:e,filters:o,onFilterChange:t,variants:r=[],currentVariantId:l,onVariantLoad:n,onVariantSave:i,onVariantDelete:a,onVariantSetDefault:d,onSearch:T,loading:k=false,appId:w,tableKey:C,currentLayout:E,currentLayoutId:M,layoutRefs:m,variantService:f})=>{let[S,y]=So.useState(true),[g,p]=So.useState(null),[I,c]=So.useState(e.filter(s=>!s.hidden).map(s=>s.id)),u=(s,R)=>{t({...o,[s]:R});},b=s=>{I.includes(s)?c(I.filter(R=>R!==s)):c([...I,s]);};return jsxRuntime.jsxs(material.Paper,{sx:{mb:0,display:"flex",flexDirection:"column",overflow:"visible",position:"relative"},children:[jsxRuntime.jsxs(material.Box,{sx:{p:2,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[w?jsxRuntime.jsx(sn,{appId:w,tableKey:C,currentFilters:{values:o,visibleFields:I},currentLayout:E,currentLayoutId:M,layoutRefs:m,onLoad:s=>{if(!s.filters)return;let R=null;if(Array.isArray(s.filters)){let v=C||"default",z=s.filters.find(L=>L.scope===v);R=z?z.filters:null;}else R=s.filters;R&&(R.values||R.visibleFields?(R.visibleFields&&Array.isArray(R.visibleFields)&&c(R.visibleFields),R.values&&t(R.values)):t(R)),n&&n(s);},variantService:f,currentVariantId:l}):jsxRuntime.jsx(vt,{variants:r,currentVariantId:l,onLoad:n,onSave:s=>{i&&i({...s,filters:{values:o,visibleFields:I}});},onDelete:a,onSetDefault:d}),jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsxRuntime.jsx(material.Tooltip,{title:"Add Filters",children:jsxRuntime.jsx(material.Button,{onClick:s=>p(s.currentTarget),size:"small",color:"primary",startIcon:jsxRuntime.jsx(zr__default.default,{fontSize:"small"}),sx:{textTransform:"none",fontSize:Z},children:"Adapt Filters"})}),jsxRuntime.jsx(material.Button,{variant:"contained",size:"small",onClick:T,disabled:k,sx:{minWidth:"40px",fontWeight:"bold"},children:k?"...":"Go"}),jsxRuntime.jsxs(material.Menu,{anchorEl:g,open:!!g,onClose:()=>p(null),slotProps:{paper:{style:{maxHeight:400,width:"25ch"}}},children:[jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.ListItemText,{primary:"Visible Filters"})}),jsxRuntime.jsx(material.Divider,{}),e.map(s=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>b(s.id),children:[jsxRuntime.jsx(material.Checkbox,{checked:I.includes(s.id),size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:s.label})]},s.id))]})]})]}),jsxRuntime.jsx(material.Collapse,{in:S,children:jsxRuntime.jsx(material.Box,{sx:{px:2,pb:2},children:jsxRuntime.jsx(material.Grid,{container:true,spacing:2,columns:{xs:2,sm:3,md:4,lg:6},children:e.filter(s=>I.includes(s.id)).map(s=>jsxRuntime.jsx(material.Grid,{size:1,children:jsxRuntime.jsx(jr,{field:s,value:o[s.id]||{value:"",operator:s.type==="number"?"=":"equals"},onChange:R=>u(s.id,R)})},s.id))})})}),jsxRuntime.jsx(material.Box,{sx:{position:"absolute",bottom:0,left:"50%",transform:"translate(-50%, 50%)",zIndex:10},children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:()=>y(!S),sx:{bgcolor:"background.paper",boxShadow:2,border:"1px solid",borderColor:"divider",width:20,height:20,minHeight:0,p:0,"&:hover":{bgcolor:"background.paper"}},children:S?jsxRuntime.jsx(Or__default.default,{sx:{fontSize:16},color:"action"}):jsxRuntime.jsx(Ra__default.default,{sx:{fontSize:16},color:"action"})})})]})};var Sn=({layouts:e,currentLayoutId:o,onLoad:t,onSave:r,onDelete:l,onSetDefault:n})=>{let[i,a]=So.useState(null),[d,T]=So.useState(false),[k,w]=So.useState(""),[C,E]=So.useState(""),[M,m]=So.useState({isDefault:false,isPublic:false}),f=e.find(c=>c.id===o),S=c=>{a(c.currentTarget);},y=()=>{a(null);},g=c=>{t(c),y();},p=()=>{w(""),E(""),m({isDefault:false,isPublic:false}),T(true),y();},I=()=>{k.trim()&&(r({name:k,description:C,...M}),T(false));};return jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsxRuntime.jsx(material.Tooltip,{title:"Save Layout",children:jsxRuntime.jsx(material.IconButton,{onClick:p,color:"primary",size:"small",children:jsxRuntime.jsx(vn__default.default,{})})}),jsxRuntime.jsx(material.Tooltip,{title:"Layout Options",children:jsxRuntime.jsx(material.IconButton,{onClick:S,color:f?"primary":"default",children:jsxRuntime.jsx(ni__default.default,{})})}),jsxRuntime.jsxs(material.Menu,{anchorEl:i,open:!!i,onClose:y,PaperProps:{sx:{width:320,maxHeight:400}},children:[jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.Typography,{variant:"caption",children:"Select Layout"})}),jsxRuntime.jsxs(material.MenuItem,{onClick:p,children:[jsxRuntime.jsx(material.ListItemIcon,{children:jsxRuntime.jsx(vn__default.default,{fontSize:"small"})}),jsxRuntime.jsx(material.ListItemText,{children:"Save Current Layout..."})]}),jsxRuntime.jsx(material.Divider,{}),e.length===0&&jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.Typography,{variant:"body2",color:"text.secondary",children:"No saved layouts"})}),e.map((c,u)=>jsxRuntime.jsx(material.MenuItem,{onClick:()=>g(c),selected:c.id===o,children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",width:"100%",justifyContent:"space-between"},children:[jsxRuntime.jsxs(material.Box,{sx:{display:"flex",flexDirection:"column",overflow:"hidden",mr:1},children:[jsxRuntime.jsx(material.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:jsxRuntime.jsx(material.Typography,{variant:"body2",fontWeight:c.id===o?"bold":"normal",noWrap:true,children:c.name})}),c.description&&jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",noWrap:true,children:c.description})]}),jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center"},onClick:b=>b.stopPropagation(),children:[jsxRuntime.jsx(material.Tooltip,{title:c.isDefault?"Remove Default":"Set as Default",children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:b=>{b.stopPropagation(),n(c.id);},children:c.isDefault?jsxRuntime.jsx(pr__default.default,{fontSize:"small",color:"warning"}):jsxRuntime.jsx(oi__default.default,{fontSize:"small"})})}),jsxRuntime.jsx(material.Tooltip,{title:"Delete",children:jsxRuntime.jsx(material.IconButton,{size:"small",color:"error",onClick:b=>{b.stopPropagation(),l(c.id);},children:jsxRuntime.jsx(ei__default.default,{fontSize:"small"})})})]})]})},c.id||u))]}),jsxRuntime.jsxs(material.Dialog,{open:d,onClose:()=>T(false),maxWidth:"xs",fullWidth:true,children:[jsxRuntime.jsx(material.DialogTitle,{children:"Save Layout"}),jsxRuntime.jsx(material.DialogContent,{children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[jsxRuntime.jsx(material.TextField,{label:"Layout Name",value:k,onChange:c=>w(c.target.value),fullWidth:true,autoFocus:true,size:"small",helperText:"e.g., 'Compact View'"}),e.some(c=>c.name===k)&&jsxRuntime.jsx(material.Typography,{variant:"caption",color:"warning.main",sx:{ml:1},children:"Warning: Existing layout will be overwritten"}),jsxRuntime.jsx(material.TextField,{label:"Description",value:C,onChange:c=>E(c.target.value),fullWidth:true,size:"small"}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:M.isDefault,onChange:c=>m({...M,isDefault:c.target.checked})}),label:"Use as Default Layout"}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:M.isPublic,onChange:c=>m({...M,isPublic:c.target.checked})}),label:"Public (Visible to all users)"})]})}),jsxRuntime.jsxs(material.DialogActions,{children:[jsxRuntime.jsx(material.Button,{onClick:()=>T(false),children:"Cancel"}),jsxRuntime.jsx(material.Button,{onClick:I,variant:"contained",disabled:!k,children:"Save"})]})]})]})};var ai="http://127.0.0.1:8515",wn=({appId:e,tableKey:o="default",currentLayoutData:t,onLayoutLoad:r,targetLayoutId:l,activeLayoutId:n,serviceUrl:i=ai,onError:a,onSuccess:d})=>{let[T,k]=So.useState([]),[w,C]=So.useState(""),E=`orbcafe.layouts.${e}.${o}`,M=u=>({id:u.layoutId,name:u.name,description:u.description??"",isDefault:!!u.isDefault,isPublic:!!u.isPublic,createdAt:u.createdAt??new Date().toISOString(),layoutData:u.layout??{}}),m=u=>({appId:e,tableKey:o,layoutId:u.id,name:u.name,description:u.description??"",isDefault:!!u.isDefault,isPublic:!!u.isPublic,createdAt:u.createdAt,layout:u.layoutData}),f=So.useCallback(()=>{try{let u=localStorage.getItem(E);if(!u)return [];let b=JSON.parse(u);return Array.isArray(b)?b:[]}catch{return []}},[E]),S=So.useCallback(u=>{try{localStorage.setItem(E,JSON.stringify(u));}catch{}},[E]);So.useEffect(()=>{n!==void 0&&C(n);},[n]),So.useEffect(()=>{if(l&&T.length>0){let u=T.find(b=>b.id===l);u&&(C(u.id),r(u));}},[l,T,r]);let y=So.useCallback(async()=>{if(e)try{let u=await fetch(`${i}/api/layouts?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!u.ok)throw new Error("Failed to fetch layouts");let x=(await u.json()).map(M);k(x);let s=x.find(R=>R.isDefault);s&&!w&&!l&&(C(s.id),r(s));}catch(u){console.error("Error fetching layouts",u);let b=f();k(b);let x=b.find(s=>s.isDefault);x&&!w&&!l&&(C(x.id),r(x)),a&&a("Failed to load layouts from backend, fallback to local storage");}},[e,o,i,a,w,r,l,f]);return So.useEffect(()=>{y();},[e,o]),jsxRuntime.jsx(Sn,{layouts:T,currentLayoutId:w,onLoad:u=>{C(u.id),r(u);},onSave:async u=>{let b=T.find(R=>R.name===u.name),x=b?b.id:Date.now().toString(),s={id:x,...u,createdAt:new Date().toISOString(),layoutData:t,isDefault:u.isDefault??false,isPublic:u.isPublic??false};try{if(!(await fetch(`${i}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(m(s))})).ok)throw new Error("Failed to save layout");d&&d("Layout saved successfully"),await y(),C(x),r(s);}catch(R){console.error("Error saving layout",R);let z=T.some(L=>L.id===x)?T.map(L=>L.id===x?s:L):[...T,s];k(z),S(z),C(x),r(s),d&&d("Layout saved to local storage"),a&&a("Backend unavailable, saved to local storage");}},onDelete:async u=>{try{if(!(await fetch(`${i}/api/layouts/${encodeURIComponent(u)}`,{method:"DELETE"})).ok)throw new Error("Failed to delete layout");w===u&&C(""),d&&d("Layout deleted successfully"),await y();}catch(b){console.error("Error deleting layout",b);let x=T.filter(s=>s.id!==u);k(x),S(x),w===u&&C(""),d&&d("Layout deleted from local storage"),a&&a("Backend unavailable, deleted from local storage");}},onSetDefault:async u=>{try{let b=T.find(s=>s.id===u);if(!b)return;if(!(await fetch(`${i}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(m({...b,isDefault:!0}))})).ok)throw new Error("Failed to set default layout");d&&d("Default layout set"),await y();}catch(b){console.error("Error setting default",b);let x=T.map(s=>({...s,isDefault:s.id===u}));k(x),S(x),d&&d("Default layout set in local storage"),a&&a("Backend unavailable, default saved to local storage");}}})};function kn(e,o,t){return o[t]<e[t]?-1:o[t]>e[t]?1:0}function ii(e,o){return e==="desc"?(t,r)=>kn(t,r,o):(t,r)=>-kn(t,r,o)}function li(e,o){let t=e.map((r,l)=>[r,l]);return t.sort((r,l)=>{let n=o(r[0],l[0]);return n!==0?n:r[1]-l[1]}),t.map(r=>r[0])}var Mn=e=>{let o=So.useCallback(h=>{let B=String(h?.label??h?.id??"").length*9+64,ee=typeof h?.minWidth=="number"?h.minWidth:0;return Math.max(100,ee,B)},[]),[t,r]=So.useState(""),[l,n]=So.useState(e.order||"asc"),[i,a]=So.useState(e.orderBy||""),[d,T]=So.useState(e.page||0),[k,w]=So.useState(e.rowsPerPage||20),[C,E]=So.useState(e.selected||[]),[M,m]=So.useState(e.columns?e.columns.map(h=>h.id):[]),[f,S]=So.useState(e.showSummary||false),[y,g]=So.useState([]),[p,I]=So.useState(new Set),[c,u]=So.useState(()=>{let h={};return (e.columns||[]).forEach(D=>{h[D.id]=o(D);}),h}),[b,x]=So.useState(null),[s,R]=So.useState(null),[v,z]=So.useState(null),[L,V]=So.useState(null),[A,N]=So.useState(false),[te,Oe]=So.useState("");So.useEffect(()=>{e.order!==void 0&&n(e.order),e.orderBy!==void 0&&a(e.orderBy);},[e.order,e.orderBy]),So.useEffect(()=>{e.selected!==void 0&&E(e.selected);},[e.selected]),So.useEffect(()=>{e.page!==void 0&&T(e.page);},[e.page]),So.useEffect(()=>{u(h=>{let D={...h};return (e.columns||[]).forEach(B=>{D[B.id]===void 0&&(D[B.id]=o(B));}),D});},[e.columns,o]);let oe=So.useMemo(()=>{let h=e.rows||[];return t&&(h=h.filter(D=>Object.keys(D).some(B=>String(D[B]).toLowerCase().includes(t.toLowerCase())))),h},[e.rows,t]),re=So.useMemo(()=>e.onSortChange||!i?oe:li(oe,ii(l,i)),[oe,l,i,e.onSortChange]),ie=So.useCallback(h=>{if(y.length===0)return h.map(Y=>({type:"row",data:Y,id:Y[e.rowKey||"id"]}));let D=[...h].sort((Y,q)=>{for(let $ of y){if(Y[$]<q[$])return -1;if(Y[$]>q[$])return 1}return 0}),B=(Y,q=0)=>{if(q>=y.length)return Y;let $=y[q],U={},fe=[];return Y.forEach(se=>{let Be=se[$],ce=`${$}:${Be}`;U[ce]||(U[ce]={key:ce,field:$,value:Be,children:[],count:0,level:q},fe.push(U[ce])),U[ce].children.push(se),U[ce].count++;}),fe.forEach(se=>{se.children&&(se.children=B(se.children,q+1));}),fe},ee=B(D),G=(Y,q="")=>{let $=[];return Y.forEach(U=>{if(U.children){let fe=q?`${q}>${U.key}`:U.key,se=p.has(fe);$.push({type:"group",id:fe,field:U.field,value:U.value,level:U.level,count:U.count,isExpanded:se,childIds:(function Be(ce){let Se=[];return ce.children.forEach($e=>{$e.children?Se=Se.concat(Be($e)):Se.push($e[e.rowKey||"id"]);}),Se})(U)}),se&&($=$.concat(G(U.children,fe)));}else $.push({type:"row",data:U,id:U[e.rowKey||"id"],level:y.length});}),$};return G(ee)},[y,p,e.rowKey]),De=So.useMemo(()=>ie(re),[re,ie]),nt=So.useMemo(()=>k>0?De.slice(d*k,d*k+k):De,[De,d,k]),at=h=>{let D=new Set(p);D.has(h)?D.delete(h):D.add(h),I(D);},Ge=h=>{at(h);},Ft=h=>{let D=new Set(p);Array.from(D).forEach(B=>{B.startsWith(h)&&D.delete(B);}),I(D);},Vt=h=>{h||I(new Set);},We=h=>{let D=i===h&&l==="asc",B=i===h&&l==="desc";if(e.onSortChange){D?e.onSortChange(h,"desc"):B?e.onSortChange("","asc"):e.onSortChange(h,"asc");return}D?(n("desc"),a(h)):B?(n("asc"),a("")):(n("asc"),a(h));},rt=(h,D)=>{u(B=>({...B,[h]:D}));},Nt=h=>{if(h.target.checked){let D=oe.map(B=>B[e.rowKey||"id"]);E(D),e.onSelectionChange&&e.onSelectionChange(D);return}E([]),e.onSelectionChange&&e.onSelectionChange([]);},Ht=(h,D)=>{let B=D[e.rowKey||"id"],ee=C.indexOf(B),G=[];ee===-1?G=G.concat(C,B):ee===0?G=G.concat(C.slice(1)):ee===C.length-1?G=G.concat(C.slice(0,-1)):ee>0&&(G=G.concat(C.slice(0,ee),C.slice(ee+1))),E(G),e.onSelectionChange&&e.onSelectionChange(G);},it=h=>{T(h),e.onPageChange&&e.onPageChange(h);},lt=h=>{w(h),T(0),e.onRowsPerPageChange&&e.onRowsPerPageChange(h);},zt=h=>{let D=M.indexOf(h),B=[...M];D===-1?B.push(h):B.splice(D,1),m(B);},st=h=>{let D=y.indexOf(h),B=[...y];D===-1?B.push(h):B.splice(D,1),g(B);},Ot=h=>{e.onLayoutSave&&e.onLayoutSave({visibleColumns:M,order:l,orderBy:i,grouping:y,columnWidths:c});},ct=h=>{h.layout&&(h.layout.visibleColumns&&m(h.layout.visibleColumns),h.layout.order&&n(h.layout.order),h.layout.orderBy&&a(h.layout.orderBy),h.layout.grouping&&g(h.layout.grouping),h.layout.columnWidths&&u(h.layout.columnWidths));},Gt=h=>{let D=h?.layoutData||h?.layout||h||{};D.visibleColumns&&m(D.visibleColumns),D.order&&n(D.order),D.orderBy!==void 0&&a(D.orderBy),D.grouping&&g(D.grouping),D.columnWidths&&u(D.columnWidths),D.showSummary!==void 0&&S(!!D.showSummary),I(new Set),T(0),h?.id&&Oe(h.id);};So.useEffect(()=>{e.layout&&ct({layout:e.layout});},[e.layout]);let Wt=h=>{h.preventDefault(),V(L===null?{mouseX:h.clientX+2,mouseY:h.clientY-6}:null);},$t=()=>{V(null);},dt=So.useMemo(()=>{if(!f)return {};let h={};e.columns.forEach(B=>{if(B.numeric){let ee=oe.reduce((G,Y)=>{let q=parseFloat(Y[B.id]);return G+(isNaN(q)?0:q)},0);h[B.id]=ee.toFixed(2);}else h[B.id]="";});let D=e.columns.find(B=>M.includes(B.id));return D&&!D.numeric&&(h[D.id]="Total"),h},[oe,e.columns,f,M]),_t=()=>{if(!e.columns||!oe)return;let h=e.columns.map(Y=>Y.label).join(","),D=oe.map(Y=>e.columns.map(q=>{let $=Y[q.id];return `"${($==null?"":String($)).replace(/"/g,'""')}"`}).join(",")).join(`
|
|
2
|
+
`),B=`data:text/csv;charset=utf-8,${h}
|
|
3
|
+
${D}`,ee=encodeURI(B),G=document.createElement("a");G.setAttribute("href",ee),G.setAttribute("download",`${e.title||"export"}.csv`),document.body.appendChild(G),G.click(),document.body.removeChild(G);},jt=()=>{N(true);},Ut=()=>{N(false);};return {isMobile:false,columns:e.columns,order:l,orderBy:i,filterText:t,setFilterText:r,visibleColumns:M,setVisibleColumns:m,showSummary:f,setShowSummary:S,summaryColumns:[],grouping:y,setGrouping:g,expandedGroups:p,setExpandedGroups:I,groupAnchorEl:s,setGroupAnchorEl:R,summaryAnchorEl:v,setSummaryAnchorEl:z,columnWidths:c,setColumnWidths:u,anchorEl:b,setAnchorEl:x,contextMenu:L,setContextMenu:V,sensors:void 0,sortedAndFilteredRows:re,visibleRows:nt,summaryRow:dt,page:d,setPage:it,rowsPerPage:k,setRowsPerPage:lt,selected:C,setSelected:E,isAllExpanded:false,handleColumnResize:rt,handleRequestSort:We,handleSelectAllClick:Nt,handleClick:Ht,toggleSummaryColumn:()=>{},handleDragEnd:()=>{},handleExport:_t,handleContextMenu:Wt,handleCloseContextMenu:$t,toggleColumnVisibility:zt,toggleGroupExpand:at,toggleGroupField:st,handleToggleAll:Vt,handleExpandGroupRecursively:Ge,handleCollapseGroupRecursively:Ft,handleLayoutLoad:Gt,handleVariantLoad:ct,handleLayoutSave:Ot,effectiveAppId:e.appId||"",currentLayoutData:{visibleColumns:M,order:l,orderBy:i,grouping:y,columnWidths:c},currentLayoutId:te,layoutIdToLoad:"",onPageChange:it,onRowsPerPageChange:lt,graphReportOpen:A,handleOpenGraphReport:jt,handleCloseGraphReport:Ut}};var zc=e=>jsxRuntime.jsx(di__default.default,{...e}),Oc=e=>jsxRuntime.jsx(Bo__default.default,{...e}),Gc=e=>jsxRuntime.jsx(Rn__default.default,{...e}),Wc=e=>jsxRuntime.jsx(xa__default.default,{...e}),$c=e=>jsxRuntime.jsx(Ca__default.default,{...e}),Dt=e=>{let{title:o="Data Table",showToolbar:t=true,selectionMode:r,selected:l=[],onSelectionChange:n,actions:i,extraTools:a,fitContainer:d=false,fullWidth:T=false,maxHeight:k,loading:w=false,page:C=0,rowsPerPage:E=20,rowsPerPageOptions:M=[20,50,100,-1],count:m=0,onPageChange:f,onRowsPerPageChange:S,onLayoutSave:y,filterConfig:g,rowKey:p,tableKey:I="default",graphReport:c}=e,{isMobile:u,columns:b,order:x,orderBy:s,filterText:R,setFilterText:v,visibleColumns:z,showSummary:L,setShowSummary:V,summaryColumns:A,grouping:N,setGrouping:te,expandedGroups:Oe,groupAnchorEl:oe,setGroupAnchorEl:re,summaryAnchorEl:ie,setSummaryAnchorEl:De,columnWidths:nt,anchorEl:at,setAnchorEl:Ge,contextMenu:Ft,sensors:Vt,sortedAndFilteredRows:We,summaryRow:rt,visibleRows:Nt,isAllExpanded:Ht,handleColumnResize:it,handleRequestSort:lt,handleSelectAllClick:zt,handleClick:st,toggleSummaryColumn:Ot,handleDragEnd:ct,handleExport:Gt,handleContextMenu:Wt,handleCloseContextMenu:$t,toggleColumnVisibility:dt,toggleGroupExpand:_t,toggleGroupField:jt,handleToggleAll:Ut,handleExpandGroupRecursively:h,handleCollapseGroupRecursively:D,handleLayoutLoad:B,handleVariantLoad:ee,handleLayoutSave:G,effectiveAppId:Y,currentLayoutData:q,currentLayoutId:$,layoutIdToLoad:U,graphReportOpen:fe,handleOpenGraphReport:se,handleCloseGraphReport:Be}=Mn(e),ce=c?.enabled??false,{model:Se}=en({rows:We,config:{...c,title:c?.title||`${o} Graphic Report`}}),$e=Se.table.columns.map(ut=>({id:ut.id,label:ut.label,align:ut.align||"left",minWidth:120,numeric:ut.align==="right"})),Gn=Y?jsxRuntime.jsx(wn,{appId:Y,tableKey:I,currentLayoutData:q,onLayoutLoad:B,targetLayoutId:U,activeLayoutId:$,serviceUrl:(g?.variantService,void 0)}):null,Co=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(_o,{groupAnchorEl:oe,setGroupAnchorEl:re,grouping:N,setGrouping:te,columns:b,toggleGroupField:jt}),jsxRuntime.jsx(jo,{anchorEl:at,setAnchorEl:Ge,columns:b,visibleColumns:z,toggleColumnVisibility:dt}),jsxRuntime.jsx(Uo,{anchorEl:ie,setAnchorEl:De,showSummary:L,setShowSummary:V,columns:b,summaryColumns:A,toggleSummaryColumn:Ot}),jsxRuntime.jsx(Ko,{contextMenu:Ft,handleCloseContextMenu:$t,columns:b,visibleColumns:z,toggleColumnVisibility:dt})]});return u?jsxRuntime.jsxs(bo__default.default,{sx:{display:"flex",flexDirection:"column",gap:2,height:"100%"},children:[g&&jsxRuntime.jsx(Xe,{fields:g.fields,filters:g.filters,onFilterChange:g.onFilterChange,onSearch:g.onSearch,variants:g.variants||[],currentVariantId:g.currentVariantId,onVariantLoad:g.onVariantLoad,onVariantSave:g.onVariantSave,onVariantDelete:g.onVariantDelete,onVariantSetDefault:g.onVariantSetDefault,appId:g.appId,tableKey:I,currentLayout:[{tableKey:I,layoutData:q}],variantService:g.variantService}),jsxRuntime.jsx(Wo,{title:o,loading:w,showSummary:L,setShowSummary:V,setAnchorEl:Ge,setSummaryAnchorEl:De,filterText:R,setFilterText:v,sortedAndFilteredRows:We,selected:l,columns:b,visibleColumns:z,summaryRow:rt,handleClick:st,selectionMode:r}),Co]}):jsxRuntime.jsxs(bo__default.default,{sx:{width:T?"100%":"auto",mb:d?0:2,...d?{flex:1,display:"flex",flexDirection:"column",minHeight:0,height:"100%"}:{}},children:[g&&jsxRuntime.jsx(bo__default.default,{sx:{mb:2},children:jsxRuntime.jsx(Xe,{fields:g.fields,filters:g.filters,onFilterChange:g.onFilterChange,onSearch:g.onSearch,variants:g.variants||[],currentVariantId:g.currentVariantId,onVariantLoad:ee,onVariantSave:g.onVariantSave,onVariantDelete:g.onVariantDelete,onVariantSetDefault:g.onVariantSetDefault,loading:w,appId:g.appId,tableKey:I,currentLayout:[{tableKey:I,layoutData:q}],currentLayoutId:$,layoutRefs:[{tableKey:I,layoutId:$}],variantService:g.variantService})}),jsxRuntime.jsxs(si__default.default,{sx:{width:T?"100%":"auto",mb:d?0:2,display:"flex",flexDirection:"column",overflow:"hidden",...k?{height:k}:d?{flex:1,minHeight:0}:{}},children:[t&&jsxRuntime.jsx(Lo,{filterText:R,setFilterText:v,onRowsPerPageChange:S,rowsPerPage:E,rowsPerPageOptions:M,page:C,count:m,onPageChange:f,actions:i,extraTools:a,grouping:N,setGroupAnchorEl:re,showSummary:L,setShowSummary:V,setAnchorEl:Ge,setSummaryAnchorEl:De,handleExport:Gt,onLayoutSave:y||g?.variantService&&g?.appId?G:void 0,loading:w,layoutManager:Gn,onOpenGraphReport:ce?se:void 0}),jsxRuntime.jsx(Rn__default.default,{sx:{flex:1,maxHeight:k||"calc(100vh - 320px)",overflowY:"auto",overflowX:"auto",position:"relative",minHeight:0},children:jsxRuntime.jsx(core.DndContext,{sensors:Vt,collisionDetection:core.closestCenter,onDragEnd:ct,modifiers:[modifiers.restrictToHorizontalAxis],children:jsxRuntime.jsxs(ci__default.default,{sx:{minWidth:T?750:"auto",width:T?"100%":"auto",tableLayout:Object.keys(nt).length>0?"fixed":"auto",borderCollapse:"separate",borderSpacing:0},"aria-labelledby":"tableTitle",size:"small",stickyHeader:true,children:[jsxRuntime.jsx(Vo,{columns:b,visibleColumns:z,order:x,orderBy:s,onRequestSort:lt,onContextMenu:Wt,selectionMode:r,grouping:N,isAllExpanded:Ht,handleToggleAll:Ut,rowCount:We.length,numSelected:l.length,onSelectAllClick:zt,columnWidths:nt,onColumnResize:it}),jsxRuntime.jsx(Ho,{visibleRows:Nt,columns:b,visibleColumns:z,selectionMode:r,selected:l,orderBy:s,loading:w,expandedGroups:Oe,toggleGroupExpand:_t,handleExpandGroupRecursively:h,handleCollapseGroupRecursively:D,handleClick:st,onSelectionChange:n,grouping:N,rowKeyProp:p,page:C,rowsPerPage:E}),L&&jsxRuntime.jsx(Oo,{showSummary:L,columns:b,visibleColumns:z,summaryRow:rt,selectionMode:r?.toString(),orderBy:s,zIndex:3})]})})})]}),Co,ce&&jsxRuntime.jsx(Zo,{open:fe,onClose:Be,model:Se,tableContent:jsxRuntime.jsx(Dt,{title:"Data Body",columns:$e,rows:Se.table.rows,rowKey:"id",fullWidth:true,maxHeight:"420px",rowsPerPage:20,rowsPerPageOptions:[20,50,100],graphReport:{enabled:false}})})]})},_c=Dt;var Jc=({title:e,hideHeader:o=true,filterConfig:t,tableProps:r,children:l,spacing:n=1})=>jsxRuntime.jsxs(Po,{title:e,hideHeader:o,children:[jsxRuntime.jsxs(material.Stack,{spacing:n,sx:{height:"100%",overflow:"hidden"},children:[t&&jsxRuntime.jsx(material.Box,{sx:{flexShrink:0},children:jsxRuntime.jsx(Xe,{...t})}),jsxRuntime.jsx(material.Box,{sx:{flex:1,minHeight:0,overflow:"hidden"},children:jsxRuntime.jsx(Dt,{...r,fitContainer:true,filterConfig:void 0})})]}),l]});var td=({metadata:e,fetchData:o})=>{let[t,r]=So.useState(false),[l,n]=So.useState([]),[i,a]=So.useState({}),[d,T]=So.useState(e.variants||[]),[k,w]=So.useState(e.layout||null),[C,E]=So.useState(0),[M,m]=So.useState(0),[f,S]=So.useState(10),[y,g]=So.useState([]),[p,I]=So.useState("asc"),[c,u]=So.useState("");So.useEffect(()=>{let A={};e.filters.forEach(N=>{N.defaultValue!==void 0&&(A[N.id]=N.defaultValue);}),a(A);},[e.filters]);let b=So.useCallback(async(A,N,te,Oe,oe)=>{r(true);try{let re={...A,page:N+1,limit:te,sort:oe,order:Oe},ie;o?ie=await o(re):typeof e.api=="function"?ie=await e.api(re):e.api&&typeof e.api=="object"?(console.log("Fetching from URL:",e.api.url,re),ie={rows:[],total:0}):(console.warn("No API configured for report"),ie={rows:[],total:0}),ie&&(n(ie.rows||[]),E(ie.total||0));}catch(re){console.error("Failed to fetch report data",re);}finally{r(false);}},[e.api,o]);So.useEffect(()=>{b(i,M,f,p,c);},[b,M,f,p,c]);let x=()=>{m(0),b(i,0,f,p,c);},s=(A,N)=>{I(N),u(A);},R=A=>{a(A);},v=A=>{if(A.filters){let N=A.filters.find(te=>te.scope==="default"||te.scope===e.id);N&&(a(N.filters),b(N.filters,0,f));}A.layout&&w(A.layout);},z=A=>{let N={...A,id:Date.now().toString(),createdAt:new Date().toISOString()};T(te=>[...te,N]);},L=A=>{w(A);};return {pageProps:{title:e.title,filterConfig:{appId:e.id,fields:e.filters,filters:i,onFilterChange:R,onSearch:x,onVariantLoad:v,onVariantSave:z,onVariantDelete:A=>T(N=>N.filter(te=>te.id!==A)),onVariantSetDefault:A=>{T(N=>N.map(te=>({...te,isDefault:te.id===A})));},variants:d},tableProps:{appId:e.id,columns:e.columns,rows:l,loading:t,rowKey:"id",count:C,page:M,rowsPerPage:f,rowsPerPageOptions:[10,25,50,100],onPageChange:m,onRowsPerPageChange:S,selectionMode:"multiple",selected:y,onSelectionChange:g,onLayoutSave:L,layout:k,title:e.title,showSummary:true,order:p,orderBy:c,onSortChange:s,graphReport:e.graphReport||{enabled:true,title:`${e.title} Graphic Report`}}},filters:i,rows:l,loading:t,refresh:x}};var Nn=64,Ai="#E9EDF2",Fi="linear-gradient(90deg, #F5F7FA 0%, #E9EDF2 50%, #F5F7FA 100%)",Hn=({appTitle:e,logo:o,mode:t="dark",onToggleMode:r,localeLabel:l="EN",searchPlaceholder:n="Ask me...",onSearch:i,user:a,leftSlot:d,rightSlot:T})=>{let w=material.useTheme().palette.mode==="dark",[C,E]=So.useState(""),[M,m]=So.useState(null),f=p=>{p.preventDefault(),i&&i(C.trim());},S=t==="system"?jsxRuntime.jsx(Di__default.default,{fontSize:"small"}):t==="dark"?jsxRuntime.jsx(Pi__default.default,{fontSize:"small"}):jsxRuntime.jsx(Ei__default.default,{fontSize:"small"}),y=t==="system"?"Theme: System":t==="dark"?"Theme: Dark":"Theme: Light",g=!!M;return jsxRuntime.jsxs(material.AppBar,{position:"sticky",elevation:0,sx:p=>({top:0,zIndex:p.zIndex.drawer+10,height:Nn,backgroundColor:p.palette.mode==="dark"?"#0D0D0D":Ai,backgroundImage:p.palette.mode==="dark"?["radial-gradient(circle at 18% 22%, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0) 45%)","radial-gradient(circle at 78% 32%, rgba(144,202,249,0.14) 0%, rgba(144,202,249,0) 42%)","linear-gradient(90deg, #0A0A0A 0%, #151515 50%, #0A0A0A 100%)","linear-gradient(rgba(255,255,255,0.04) 1px, transparent 1px)","linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px)"].join(","):["radial-gradient(circle at 22% 22%, rgba(255,255,255,0.7) 0%, rgba(255,255,255,0) 48%)","radial-gradient(circle at 76% 24%, rgba(203,213,225,0.45) 0%, rgba(203,213,225,0) 42%)",Fi,"linear-gradient(rgba(15,23,42,0.05) 1px, transparent 1px)","linear-gradient(90deg, rgba(15,23,42,0.04) 1px, transparent 1px)"].join(","),backgroundSize:"auto, auto, auto, 24px 24px, 24px 24px",borderBottom:"1px solid",borderColor:p.palette.mode==="dark"?"rgba(255,255,255,0.12)":"rgba(15,23,42,0.12)"}),children:[jsxRuntime.jsxs(material.Toolbar,{sx:{minHeight:`${Nn}px !important`,px:2,gap:2},children:[jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:1.5,sx:{minWidth:220},children:[o||jsxRuntime.jsx(material.Box,{component:"img",src:"/orbcafe.png",alt:"ORBCAFE Logo",sx:{width:44,height:44,display:"block",objectFit:"contain",flexShrink:0}}),e&&jsxRuntime.jsx(material.Typography,{variant:"h6",sx:{fontWeight:700,color:w?"common.white":"#111827"},children:e}),d]}),jsxRuntime.jsx(material.Box,{sx:{flex:1,display:"flex",justifyContent:"center",minWidth:0},children:jsxRuntime.jsx(material.Box,{component:"form",onSubmit:f,sx:{width:"100%",maxWidth:540},children:jsxRuntime.jsx(material.TextField,{size:"small",fullWidth:true,value:C,onChange:p=>E(p.target.value),placeholder:n,InputProps:{startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(mn__default.default,{sx:{color:w?"rgba(255,255,255,0.7)":"rgba(15,23,42,0.55)",fontSize:18}})}),sx:{color:w?"common.white":"rgba(17,24,39,0.9)",bgcolor:w?"rgba(255,255,255,0.08)":"#ffffff",borderRadius:999,"& .MuiOutlinedInput-notchedOutline":{borderColor:w?"rgba(255,255,255,0.15)":"rgba(15,23,42,0.2)"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:w?"rgba(255,255,255,0.35)":"rgba(15,23,42,0.35)"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:w?"rgba(255,255,255,0.5)":"rgba(15,23,42,0.55)"}}},inputProps:{style:{color:w?"white":"#111827"}}})})}),jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:1.5,children:[jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:.5,children:[jsxRuntime.jsx(Ri__default.default,{sx:{color:w?"common.white":"#111827",fontSize:18}}),jsxRuntime.jsx(material.Typography,{variant:"caption",sx:{color:w?"common.white":"#111827",fontWeight:500},children:l})]}),jsxRuntime.jsx(material.IconButton,{size:"small",sx:{color:w?"common.white":"#111827"},onClick:r,title:y,children:S}),a&&jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:1,children:[jsxRuntime.jsxs(material.Box,{sx:{textAlign:"right",minWidth:0},children:[jsxRuntime.jsx(material.Typography,{variant:"body2",sx:{color:w?"common.white":"#111827",fontWeight:700,lineHeight:1.15},children:a.name}),a.subtitle&&jsxRuntime.jsx(material.Typography,{variant:"caption",sx:{display:"block",mt:.25,color:w?"rgba(255,255,255,0.72)":"rgba(17,24,39,0.62)",fontSize:"0.72rem",lineHeight:1.1,letterSpacing:"0.01em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:220},title:a.subtitle,children:a.subtitle})]}),jsxRuntime.jsx(material.IconButton,{size:"small",onClick:p=>m(p.currentTarget),sx:{p:0},children:jsxRuntime.jsx(material.Avatar,{src:a.avatarSrc,imgProps:{style:{objectFit:"cover"}},sx:{width:34,height:34,bgcolor:"grey.100",color:"grey.700",fontSize:"0.85rem"},children:a.avatarText||a.name.slice(0,1).toUpperCase()})})]}),T]})]}),jsxRuntime.jsxs(material.Menu,{anchorEl:M,open:g,onClose:()=>m(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},slotProps:{paper:{sx:{minWidth:160,"& .MuiMenuItem-root":{minHeight:34,py:.5,px:1.25}}}},children:[jsxRuntime.jsxs(material.MenuItem,{onClick:()=>m(null),children:[jsxRuntime.jsx(material.ListItemIcon,{children:jsxRuntime.jsx(zr__default.default,{sx:{fontSize:18}})}),jsxRuntime.jsx(material.ListItemText,{primary:"Setting",slotProps:{primary:{sx:{fontSize:"0.86rem",fontWeight:500}}}})]}),jsxRuntime.jsxs(material.MenuItem,{onClick:()=>m(null),children:[jsxRuntime.jsx(material.ListItemIcon,{children:jsxRuntime.jsx(Bi__default.default,{sx:{fontSize:18}})}),jsxRuntime.jsx(material.ListItemText,{primary:"Logout",slotProps:{primary:{sx:{fontSize:"0.86rem",fontWeight:500}}}})]})]})]})};var zn=({menuData:e=[],initialNavigationCollapsed:o=false}={})=>{let{navigationIslandProps:t}=Do({initialCollapsed:o,content:e}),[r,l]=So.useState(900);So.useEffect(()=>{let i=()=>l(window.innerHeight);return i(),window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)},[]);let n=So.useMemo(()=>Math.max(280,r-100),[r]);return {navigationIslandProps:t,navigationMaxHeight:n}};var Td=({appTitle:e,menuData:o=[],children:t,showNavigation:r=true,localeLabel:l,user:n,logo:i,onSearch:a,rightHeaderSlot:d,leftHeaderSlot:T,contentSx:k})=>{let[w,C]=So.useState("system"),[E,M]=So.useState("light"),[m,f]=So.useState(false),S=w==="system"?m?E:"light":w;So.useEffect(()=>{f(true);let I=window.matchMedia("(prefers-color-scheme: dark)"),c=()=>{M(I.matches?"dark":"light");};return c(),I.addEventListener("change",c),()=>I.removeEventListener("change",c)},[]);let y=So.useMemo(()=>material.createTheme({palette:{mode:S}}),[S]),{navigationIslandProps:g,navigationMaxHeight:p}=zn({menuData:o,initialNavigationCollapsed:false});return jsxRuntime.jsx(material.ThemeProvider,{theme:y,children:jsxRuntime.jsxs(material.Box,{sx:I=>({minHeight:"100vh",display:"flex",flexDirection:"column",background:I.palette.mode==="dark"?"linear-gradient(180deg, #0A0A0A 0%, #141414 55%, #1A1A1A 100%)":I.palette.background.default}),children:[jsxRuntime.jsx(Hn,{appTitle:e,logo:i,mode:w,onToggleMode:()=>C(I=>I==="system"?"dark":I==="dark"?"light":"system"),localeLabel:l,user:n,onSearch:a,leftSlot:T,rightSlot:d}),jsxRuntime.jsxs(material.Box,{sx:{flex:1,minHeight:0,display:"flex"},children:[r&&jsxRuntime.jsx(material.Box,{sx:{p:1.5,display:"flex",alignItems:"flex-start",flexShrink:0},children:jsxRuntime.jsx(Mo,{...g,maxHeight:p,colorMode:S})}),jsxRuntime.jsx(material.Box,{sx:{flex:1,minWidth:0,minHeight:0,overflow:"auto",p:1.5,...k},children:t})]})]})})};exports.Button=Yt;exports.CAppHeader=Hn;exports.CAppPageLayout=Td;exports.CLayoutManagement=Sn;exports.CLayoutManager=wn;exports.CPageLayout=Po;exports.CSmartFilter=Xe;exports.CSmartTable=_c;exports.CStandardPage=Jc;exports.CTable=Dt;exports.CTableBody=zc;exports.CTableCell=Oc;exports.CTableContainer=Gc;exports.CTableHead=Wc;exports.CTableRow=$c;exports.CVariantManagement=vt;exports.CVariantManager=sn;exports.NavigationIsland=Mo;exports.TreeMenu=Xt;exports.buttonVariants=Un;exports.useNavigationIsland=Do;exports.usePageLayout=zn;exports.useStandardReport=td;
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import*as 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
|
-
`),
|
|
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};
|
|
1
|
+
import*as So from'react';import So__default,{useState,useEffect,useCallback,useMemo,useRef}from'react';import {usePathname,useRouter}from'next/navigation';import {ChevronRight,Search}from'lucide-react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {Slot}from'@radix-ui/react-slot';import {cva}from'class-variance-authority';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {styled,Box,Typography,Autocomplete,TextField,Tooltip,IconButton,Dialog,DialogTitle,DialogContent,FormControlLabel,Checkbox,DialogActions,Button,Paper,Menu,MenuItem,ListItemText,Divider,Collapse,Grid,ListItemIcon,Stack,useTheme,AppBar,Toolbar,InputAdornment,Avatar,createTheme,ThemeProvider,Popover,ListSubheader,Badge,Switch,TableBody,TableRow,TableCell,TableFooter,Chip}from'@mui/material';import bo from'@mui/material/Box';import si from'@mui/material/Paper';import ci from'@mui/material/Table';import di from'@mui/material/TableBody';import Bo from'@mui/material/TableCell';import Rn from'@mui/material/TableContainer';import xa from'@mui/material/TableHead';import Ca from'@mui/material/TableRow';import {DndContext,closestCenter}from'@dnd-kit/core';import {restrictToHorizontalAxis}from'@dnd-kit/modifiers';import mn from'@mui/icons-material/Search';import da from'@mui/icons-material/ViewColumn';import vn from'@mui/icons-material/Save';import pa from'@mui/icons-material/Download';import ma from'@mui/icons-material/AccountTree';import ga from'@mui/icons-material/Functions';import fa from'@mui/icons-material/Insights';import va from'@mui/material/Checkbox';import Sa from'@mui/material/TableSortLabel';import Ma from'@mui/icons-material/KeyboardArrowRight';import Ra from'@mui/icons-material/KeyboardArrowDown';import Oa from'@mui/icons-material/Check';import Ga from'@mui/icons-material/ClearAll';import Qa from'@mui/icons-material/Close';import zr from'@mui/icons-material/Settings';import Or from'@mui/icons-material/KeyboardArrowUp';import Wr from'@mui/icons-material/ArrowRightAlt';import pr from'@mui/icons-material/Star';import {DateCalendar}from'@mui/x-date-pickers/DateCalendar';import {PickersDay}from'@mui/x-date-pickers/PickersDay';import Mr from'@mui/icons-material/CalendarMonth';import Rr from'@mui/icons-material/Clear';import Dr from'@mui/icons-material/ArrowForward';import Ee from'dayjs';import Pr from'dayjs/plugin/isBetween';import ei from'@mui/icons-material/Delete';import oi from'@mui/icons-material/StarBorder';import ni from'@mui/icons-material/ViewQuilt';import Ri from'@mui/icons-material/Language';import Di from'@mui/icons-material/DesktopWindows';import Pi from'@mui/icons-material/DarkMode';import Ei from'@mui/icons-material/LightMode';import Bi from'@mui/icons-material/Logout';function le(...e){return twMerge(clsx(e))}var Kt={primary:"#000000",primaryHover:"#333333"},pt={primary:"bg-primary text-primary-foreground hover:bg-primary/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",ghost:"hover:bg-accent hover:text-accent-foreground"},_e={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",full:"rounded-full"},vo=()=>"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50";var Un=cva(vo(),{variants:{variant:{default:`${pt.primary} shadow-sm`,destructive:"bg-red-500 text-white hover:bg-red-600 active:bg-red-700 dark:bg-red-600 dark:hover:bg-red-500 dark:active:bg-red-700 shadow-sm",outline:`${pt.outline} shadow-sm`,secondary:"bg-gray-200 text-gray-700 hover:bg-gray-300 active:bg-gray-400 dark:bg-gray-700 dark:text-gray-200 dark:hover:bg-gray-600 dark:active:bg-gray-500 shadow-sm",ghost:pt.ghost,link:"text-blue-600 dark:text-blue-400 underline-offset-4 hover:underline hover:text-blue-700 dark:hover:text-blue-300 active:text-blue-800 dark:active:text-blue-200","chat-tool":"bg-[var(--orbai-surface-2)] border border-[var(--orbai-border-soft)] text-[var(--orbai-text-2)] hover:bg-[var(--orbai-surface-3)] hover:border-[var(--orbai-border-strong)] hover:text-[var(--orbai-text-1)] active:scale-95 transition-all duration-200","chat-send":`bg-[${Kt.primary}] hover:bg-[${Kt.primaryHover}] text-white border border-[var(--orbai-border-strong)] shadow-[var(--orbai-shadow-soft-sm)] hover:shadow-[var(--orbai-shadow-soft-md)] active:scale-95 transition-all duration-200`,"chat-stop":"bg-red-500 hover:bg-red-600 border border-[var(--orbai-border-strong)] shadow-[var(--orbai-shadow-soft-sm)] hover:shadow-[var(--orbai-shadow-soft-md)] active:scale-95 text-white transition-all duration-200","chat-disabled":"cursor-not-allowed opacity-50 bg-[var(--orbai-surface-2)] border border-[var(--orbai-border-soft)] text-[var(--orbai-muted)]"},size:{default:"h-10 px-4 py-2",sm:"h-9 px-3",lg:"h-11 px-8",icon:"h-10 w-10","chat-sm":"h-8 w-8 rounded-full","chat-md":"h-10 w-10 rounded-full","chat-lg":"h-12 w-12 rounded-full"},rounded:{none:_e.none,sm:_e.sm,md:_e.md,full:_e.full}},defaultVariants:{variant:"default",size:"default",rounded:"md"}}),Yt=So.forwardRef(({className:e,variant:o,size:t,asChild:r=false,...l},n)=>jsx(r?Slot:"button",{className:le(Un({variant:o,size:t,className:e})),ref:n,...l}));Yt.displayName="Button";function Xt({items:e,onItemClick:o,className:t="",level:r=0,expandedIds:l,onToggleExpand:n,colorMode:i="light"}){let a=i==="dark",d=usePathname(),[T,k]=useState(new Set),w=l!==void 0&&n!==void 0,C=w?l:T,E=m=>{if(w)n(m);else {let f=new Set(T);f.has(m)?f.delete(m):f.add(m),k(f);}},M=m=>{m.children&&m.children.length>0&&E(m.id),o&&o(m);};return !e||!Array.isArray(e)?jsx("div",{className:le("tree-menu",t),children:jsx("div",{className:"text-sm text-gray-500 p-2",children:"No items to display"})}):jsx("div",{className:le("tree-menu",t),children:e.map(m=>{let f=C.has(m.id)||m.isExpanded,S=m.children&&m.children.length>0,y=m.appurl||m.href,g=y?d===y:false;return jsxs("div",{className:"tree-menu-item relative",children:[g&&jsx("div",{className:le("absolute left-0 top-2 bottom-2 w-[3px] rounded-r-full z-10",a?"bg-[#90caf9]":"bg-[#1976d2]")}),jsxs(Yt,{variant:"ghost",className:le("w-full justify-start gap-2 h-auto py-2 relative overflow-hidden group",`ml-${r*4}`,g?a?"bg-transparent text-[#90caf9] hover:bg-gray-800/35":"bg-transparent text-[#1976d2] hover:bg-gray-100/60":a?"hover:bg-gray-800/50 text-gray-300":"hover:bg-gray-100/50 text-gray-700"),onClick:()=>M(m),children:[S&&jsx("div",{className:le("flex-shrink-0 transition-transform duration-200",f&&"rotate-90",g?a?"text-[#90caf9]":"text-[#1976d2]":a?"text-gray-500 group-hover:text-gray-300":"text-gray-400 group-hover:text-gray-600"),children:jsx(ChevronRight,{className:"h-4 w-4"})}),!S&&jsx("div",{className:"w-4 h-4 flex-shrink-0"}),m.icon&&jsx("div",{className:le("flex-shrink-0 transition-colors duration-200",g?a?"text-[#90caf9]":"text-[#1976d2]":a?"text-gray-500 group-hover:text-gray-300":"text-gray-400 group-hover:text-gray-600"),children:m.icon}),jsxs("div",{className:"flex-1 text-left overflow-hidden z-10",children:[jsx("div",{className:le("text-sm truncate transition-colors duration-200",g?"font-semibold":"font-medium"),children:m.title||m.label}),m.description&&jsx("div",{className:le("text-xs truncate transition-colors duration-200",g?a?"text-[#90caf9]/70":"text-[#1976d2]/75":a?"text-gray-400":"text-gray-500"),title:m.description,children:m.description})]})]}),S&&jsx("div",{className:le("grid transition-[grid-template-rows] duration-300 ease-in-out",f?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:jsx("div",{className:"overflow-hidden",children:jsx(Xt,{items:m.children,onItemClick:o,level:r+1,expandedIds:l,onToggleExpand:n,colorMode:i})})})]},m.id)})})}var Mo=({collapsed:e,onToggle:o,className:t="",maxHeight:r,menuData:l=[],colorMode:n="light"})=>{let i=n==="dark",a=useRouter(),[d,T]=useState(""),[k,w]=useState(new Set);useEffect(()=>{e&&w(new Set);},[e]);let C=useCallback(f=>{let S=[],y=g=>{g.forEach(p=>{S.push(p.id),p.children&&y(p.children);});};return y(f),S},[]),E=useMemo(()=>{if(!d.trim())return l;let f=S=>S.reduce((y,g)=>{let p=g.title?.toLowerCase().includes(d.toLowerCase())||g.description?.toLowerCase().includes(d.toLowerCase()),I=g.children?f(g.children):[];return (p||I.length>0)&&y.push({...g,children:I.length>0?I:g.children}),y},[]);return f(l)},[d,l]),M=useMemo(()=>d.trim()?new Set(C(l)):k,[d,l,k,C]),m=useCallback(async f=>{if(console.log("\u{1F5B1}\uFE0F \u5BFC\u822A\u83DC\u5355\u9879\u70B9\u51FB:",f),f.id==="chat"||f.appurl==="/chat"){console.log("\u{1F4AC} \u68C0\u6D4B\u5230chat\u83DC\u5355\u70B9\u51FB\uFF0C\u8DF3\u8F6C\u5230\u65B0\u7684\u804A\u5929\u89C6\u56FE");try{a.push("/chat?new=true");}catch(y){console.error("\u274C \u65E0\u6CD5\u8DF3\u8F6C\u5230\u65B0\u804A\u5929\u89C6\u56FE:",y),a.push("/chat");}return}let S=f.appurl||f.href;S&&(S.startsWith("http://")||S.startsWith("https://")?window.open(S,"_blank"):a.push(S));},[a]);return jsxs("div",{className:`flex flex-col backdrop-blur-xl border shadow-[0_4px_8px_0_rgba(31,38,135,0.1)] ${e?"w-14 rounded-full":"w-[234px] rounded-2xl"} relative ${t} ${i?"bg-[#111111] border-white/10":"bg-white/70 border-white/30"}`,style:{backdropFilter:"blur(16px) saturate(180%)",WebkitBackdropFilter:"blur(16px) saturate(180%)",transition:"width 400ms cubic-bezier(0.4, 0.0, 0.2, 1), border-radius 0ms cubic-bezier(0.4, 0.0, 0.2, 1), box-shadow 400ms ease-out",maxHeight:r?`${r}px`:void 0},children:[jsx("div",{className:`pt-4 pb-2 transition-all duration-500 ease-in-out ${e?"px-1":"px-2"}`,children:e?jsx("div",{className:"flex justify-center",children:jsx("button",{onClick:o,className:`w-10 h-10 flex items-center justify-center rounded-lg transition-colors duration-200 ${i?"text-gray-300 hover:bg-gray-800":"text-gray-500 hover:bg-gray-50"}`,title:"\u5C55\u5F00\u5BFC\u822A",children:jsx(Search,{className:"h-5 w-5"})})}):jsxs("div",{className:`relative transition-opacity duration-300 ${e?"opacity-0":"opacity-100 delay-200"}`,children:[jsx("input",{type:"text",placeholder:"\u641C\u7D22\u83DC\u5355...",value:d,onChange:f=>T(f.target.value),className:`w-full pl-10 pr-4 py-2 text-sm border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent ${i?"border-gray-700 bg-[#1A1A1A] text-white placeholder-gray-400":"border-gray-300 bg-white text-gray-900 placeholder-gray-500"}`}),jsx("div",{className:"absolute left-3 top-1/2 transform -translate-y-1/2 pointer-events-none",children:jsx(Search,{className:`h-4 w-4 ${i?"text-gray-500":"text-gray-400"}`})})]})}),jsx("nav",{className:`flex-1 pb-4 transition-all duration-500 ease-in-out overflow-y-auto min-h-0 ${e?"px-1":"px-2"}`,children:E.length===0?jsx("div",{className:"flex items-center justify-center py-8 text-gray-500 text-sm",children:e?"\u{1F4C2}":d?"\u672A\u627E\u5230\u5339\u914D\u7684\u83DC\u5355\u9879":"\u6682\u65E0\u53EF\u8BBF\u95EE\u7684\u5E94\u7528"}):jsxs(Fragment,{children:[!e&&jsx("div",{className:`transition-opacity duration-300 ${e?"opacity-0":"opacity-100 delay-200"}`,children:jsx(Xt,{items:E,onItemClick:m,className:"space-y-1",expandedIds:M,colorMode:n,onToggleExpand:f=>{let S=new Set(k);E.some(g=>g.id===f)?S.has(f)?S.delete(f):(E.forEach(g=>{g.id!==f&&S.has(g.id)&&S.delete(g.id);}),S.add(f)):S.has(f)?S.delete(f):S.add(f),w(S);}})}),e&&jsx("div",{className:"space-y-2",children:l.map(f=>jsx("div",{className:"space-y-1",children:jsx("button",{onClick:()=>{o();let S=new Set([f.id]);w(S);},className:`w-full flex items-center justify-center p-2 rounded-lg cursor-pointer transition-colors duration-200 ${i?"text-gray-400 hover:bg-gray-800":"text-gray-600 hover:bg-gray-50"}`,title:`\u5C55\u5F00\u67E5\u770B ${f.title}`,children:f.icon||jsx("div",{className:`w-6 h-6 rounded text-xs flex items-center justify-center font-medium ${i?"bg-[#90caf9] text-[#0b0b0b]":"bg-[#1976d2] text-white"}`,children:f.title?.charAt(0)||"?"})})},f.id))})]})}),!e&&jsx("button",{onClick:o,className:`absolute -bottom-1 -right-1 w-6 h-6 bg-transparent rounded-full flex items-center justify-center transition-all duration-300 ease-in-out z-20 ${i?"hover:bg-gray-800/50":"hover:bg-white/20"}`,title:"\u6298\u53E0\u5BFC\u822A",children:jsx("div",{className:"absolute",style:{bottom:"0px",right:"0px",width:"16px",height:"16px",overflow:"hidden"},children:jsx("div",{className:i?"border-yellow-400":"",style:{width:"32px",height:"32px",borderRadius:"16px",border:"3px solid #21BCFF",backgroundColor:"transparent",position:"absolute",top:"-16px",left:"-16px"}})})})]})};var Do=(e={})=>{let{initialCollapsed:o=false,content:t=[]}=e,[r,l]=useState(o),[n,i]=useState(t),a=useCallback(()=>{l(T=>!T);},[]),d=useMemo(()=>({collapsed:r,onToggle:a,menuData:n}),[r,a,n]);return {collapsed:r,setCollapsed:l,toggleCollapsed:a,menuData:n,setMenuData:i,navigationIslandProps:d}};var Po=({title:e,hideHeader:o,children:t})=>jsxs(Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[!o&&jsx(Box,{sx:{mb:2},children:jsx(Typography,{variant:"h4",children:e})}),jsx(Box,{sx:{flex:1,overflow:"hidden"},children:t})]});var Lo=e=>{let o="0.75rem",t=Array.isArray(e.actions)?e.actions:e.actions?[e.actions]:[],r=Array.isArray(e.extraTools)?e.extraTools:e.extraTools?[e.extraTools]:[],l=[...t,...r];return jsxs(Toolbar,{sx:{pl:{sm:2},pr:{xs:1,sm:1},alignItems:"center",gap:1},children:[jsx(TextField,{size:"small",placeholder:"Search...",value:e.filterText,onChange:n=>e.setFilterText(n.target.value),InputProps:{sx:{fontSize:o,"& .MuiInputBase-input":{fontSize:o},"& .MuiInputBase-input::placeholder":{fontSize:o,opacity:1}},startAdornment:jsx(InputAdornment,{position:"start",children:jsx(mn,{fontSize:"small"})})},sx:{width:300}}),jsx(Box,{sx:{flex:1}}),jsxs(Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsx(Box,{sx:{width:1,height:20,bgcolor:"divider",mr:.5}}),jsx(Tooltip,{title:"Group By",children:jsx(IconButton,{onClick:n=>e.setGroupAnchorEl(n.currentTarget),children:jsx(Badge,{badgeContent:e.grouping?.length,color:"primary",children:jsx(ma,{})})})}),jsx(Tooltip,{title:"Summary",children:jsx(IconButton,{onClick:n=>e.setSummaryAnchorEl(n.currentTarget),color:e.showSummary?"primary":"default",children:jsx(ga,{})})}),jsx(Tooltip,{title:"Columns",children:jsx(IconButton,{onClick:n=>e.setAnchorEl(n.currentTarget),children:jsx(da,{})})}),jsx(Tooltip,{title:"Export",children:jsx(IconButton,{onClick:e.handleExport,children:jsx(pa,{})})}),e.onOpenGraphReport&&jsx(Tooltip,{title:"Graphic Report",children:jsx(IconButton,{onClick:e.onOpenGraphReport,children:jsx(fa,{})})}),e.onLayoutSave&&!e.layoutManager&&jsx(Tooltip,{title:"Save Layout",children:jsx(IconButton,{onClick:n=>e.onLayoutSave(n),children:jsx(vn,{})})}),e.layoutManager,l.length>0&&jsx(Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:l.map((n,i)=>jsx(So__default.Fragment,{children:n},`toolbar-custom-${i}`))})]})]})};var Vo=e=>{let{onSelectAllClick:o,order:t,orderBy:r,numSelected:l=0,rowCount:n=0,onRequestSort:i,columns:a,visibleColumns:d,selectionMode:T,onColumnResize:k,columnWidths:w}=e,[C,E]=useState(null),M=useRef(null),m=p=>I=>{C||i(p);},f=(p,I,c)=>{p.preventDefault(),p.stopPropagation(),E(I),M.current={startX:p.clientX,startWidth:c,colId:I},document.addEventListener("mousemove",S),document.addEventListener("mouseup",y),document.body.style.cursor="col-resize";},S=p=>{if(!M.current)return;let{startX:I,startWidth:c,colId:u}=M.current,b=p.clientX-I,x=Math.max(50,c+b);k&&k(u,x);},y=()=>{E(null),M.current=null,document.removeEventListener("mousemove",S),document.removeEventListener("mouseup",y),document.body.style.cursor="";};return useEffect(()=>()=>{document.removeEventListener("mousemove",S),document.removeEventListener("mouseup",y);},[]),jsx(xa,{children:jsxs(Ca,{children:[(T==="multiple"||T==="single")&&jsx(Bo,{padding:"checkbox",sx:p=>({width:48,backgroundColor:p.palette.mode==="dark"?"#000000":"#f5f5f5",color:p.palette.mode==="dark"?"#ffffff":p.palette.text.primary}),children:jsx(va,{color:"primary",indeterminate:l>0&&l<n,checked:n>0&&l===n,onChange:o,disabled:T==="single"})}),a.filter(p=>d.includes(p.id)).map(p=>{let I=w?.[p.id]||p.minWidth||100;return jsxs(Bo,{align:"left",padding:p.disablePadding?"none":"normal",sortDirection:r===p.id?t:false,style:{width:I,minWidth:I,maxWidth:I},sx:c=>({position:"relative",backgroundColor:c.palette.mode==="dark"?"#000000":"#f5f5f5",color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary,fontWeight:"bold",userSelect:"none"}),children:[jsx(Sa,{active:r===p.id,direction:r===p.id?t:"asc",onClick:m(p.id),sx:c=>({"&.MuiTableSortLabel-root":{width:"100%"},"& .MuiTableSortLabel-icon":{color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary,opacity:r===p.id?1:0,transition:"opacity 0.2s"},"&:hover .MuiTableSortLabel-icon":{opacity:.5},"&.Mui-active .MuiTableSortLabel-icon":{opacity:1,color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary},fontWeight:"bold",color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary}),children:jsx(bo,{component:"span",sx:{overflow:"visible",textOverflow:"clip",whiteSpace:"normal",lineHeight:1.2,wordBreak:"break-word",pr:1},children:p.label})}),jsx(bo,{onMouseDown:c=>f(c,p.id,typeof I=="number"?I:100),onClick:c=>c.stopPropagation(),sx:{position:"absolute",right:0,top:0,bottom:0,width:5,cursor:"col-resize","&:hover":{backgroundColor:"primary.main",opacity:.5},zIndex:1}})]},p.id)})]})})};var Ho=e=>{let{visibleRows:o,visibleColumns:t,selected:r=[],handleClick:l,columns:n,toggleGroupExpand:i,expandedGroups:a=new Set,selectionMode:d}=e,T=C=>r.indexOf(C)!==-1,k=d==="multiple"||d==="single",w=t.length+(k?1:0);return jsxs(TableBody,{children:[o.map((C,E)=>{if(C.type==="group"){let M=a.has(C.id),m=C.childIds||[],f=m.filter(p=>T(p)).length,S=m.length>0&&f===m.length,y=f>0&&f<m.length,g=p=>{if(p.stopPropagation(),!!e.onSelectionChange)if(S){let I=r.filter(c=>!m.includes(c));e.onSelectionChange(I);}else {let I=Array.from(new Set([...r,...m]));e.onSelectionChange(I);}};return jsx(TableRow,{sx:p=>({backgroundColor:p.palette.mode==="dark"?"#111111":"#f5f5f5","& .MuiTableCell-root":{color:p.palette.text.primary,borderBottomColor:p.palette.divider},"& .MuiIconButton-root":{color:p.palette.text.primary},"& .MuiCheckbox-root":{color:p.palette.text.secondary},"& .MuiCheckbox-root.Mui-checked, & .MuiCheckbox-root.MuiCheckbox-indeterminate":{color:p.palette.primary.main}}),children:jsx(TableCell,{colSpan:w,sx:{py:1,pl:C.level*4+2},children:jsxs(Box,{sx:{display:"flex",alignItems:"center"},children:[jsx(IconButton,{size:"small",onClick:()=>i&&i(C.id),sx:{mr:1},children:M?jsx(Ra,{}):jsx(Ma,{})}),k&&jsx(Checkbox,{size:"small",checked:S,indeterminate:y,onChange:g,onClick:p=>p.stopPropagation(),sx:{mr:1,p:.5}}),jsxs(Typography,{variant:"body2",fontWeight:"bold",color:"text.primary",children:[C.field,": ",C.value," (",C.count,")"]})]})})},C.id)}else {let M=C.data||C,m=C.id||M.id||E,f=T(m),S=`enhanced-table-checkbox-${E}`,g=(C.level!==void 0?C.level:0)*4;return jsxs(TableRow,{hover:true,onClick:p=>l&&l(p,M),role:"checkbox","aria-checked":f,tabIndex:-1,selected:f,sx:{cursor:"pointer"},children:[k&&jsx(TableCell,{padding:"checkbox",sx:{pl:g>0?g+1:void 0},children:jsx(Checkbox,{color:"primary",checked:f,inputProps:{"aria-labelledby":S}})}),n.filter(p=>t.includes(p.id)).map((p,I)=>{let u=!k&&I===0&&g>0?{pl:g+2}:{};return jsx(TableCell,{align:"left",sx:u,children:p.render?p.render(M[p.id],M):(function(){let x=M[p.id];if(p.numeric){if(typeof x=="number")return x.toLocaleString();if(typeof x=="string"&&x.trim()!==""&&!isNaN(Number(x)))return Number(x).toLocaleString()}return x})()},p.id)})]},m)}}),o.length===0&&jsx(TableRow,{children:jsx(TableCell,{colSpan:w,align:"center",children:"No data"})})]})};var Oo=e=>{let{visibleColumns:o,summaryRow:t,selectionMode:r}=e;if(!e.showSummary)return null;let l=r==="multiple"||r==="single";return jsx(TableFooter,{sx:{position:"sticky",bottom:0,zIndex:e.zIndex,bgcolor:"background.paper"},children:jsxs(TableRow,{children:[l&&jsx(TableCell,{padding:"checkbox",sx:{bgcolor:"background.paper"}}),o.map(n=>jsx(TableCell,{sx:{fontWeight:"bold",fontSize:"0.875rem",bgcolor:"background.paper",color:"text.primary"},children:(function(){let a=t[n];return a==null||a===""?"":typeof a=="number"?a.toLocaleString():typeof a=="string"&&a.trim()!==""&&!isNaN(Number(a))?Number(a).toLocaleString():a})()},n))]})})};var Wo=e=>jsx(Box,{sx:{p:2},children:jsx(Typography,{children:"Mobile View Not Implemented"})});var _o=({groupAnchorEl:e,setGroupAnchorEl:o,grouping:t,setGrouping:r,columns:l,toggleGroupField:n})=>jsxs(Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsxs(Box,{sx:{p:1,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[jsx(Typography,{variant:"subtitle2",sx:{px:1},children:"Group By"}),t.length>0&&jsx(Button,{size:"small",color:"error",onClick:()=>r([]),startIcon:jsx(Ga,{}),children:"Clear All"})]}),jsx(Divider,{}),l.map(i=>{let a=t.includes(i.id),d=t.indexOf(i.id)+1;return jsx(MenuItem,{onClick:()=>n(i.id),children:jsxs(Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsx(Checkbox,{checked:a,size:"small"}),jsx(ListItemText,{primary:i.label}),a&&jsx(Badge,{badgeContent:d,color:"primary",sx:{mr:2}})]})},i.id)})]}),jo=({anchorEl:e,setAnchorEl:o,columns:t,visibleColumns:r,toggleColumnVisibility:l})=>jsxs(Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"Visible Columns"})}),jsx(Divider,{}),t.map(n=>jsxs(MenuItem,{onClick:()=>l(n.id),children:[jsx(Checkbox,{checked:r.includes(n.id),size:"small"}),jsx(ListItemText,{primary:n.label})]},n.id))]}),Uo=({anchorEl:e,setAnchorEl:o,showSummary:t,setShowSummary:r,columns:l,summaryColumns:n,toggleSummaryColumn:i})=>jsxs(Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsx(MenuItem,{children:jsx(FormControlLabel,{control:jsx(Switch,{checked:t,onChange:a=>r(a.target.checked),size:"small"}),label:"Show Summary Row"})}),jsx(Divider,{}),l.filter(a=>a.numeric).map(a=>jsxs(MenuItem,{onClick:()=>i(a.id),disabled:!t,children:[jsx(Checkbox,{checked:n.includes(a.id),size:"small"}),jsx(ListItemText,{primary:a.label})]},a.id)),l.filter(a=>a.numeric).length===0&&jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"No numeric columns"})})]}),Ko=({contextMenu:e,handleCloseContextMenu:o,columns:t,visibleColumns:r,toggleColumnVisibility:l})=>jsxs(Menu,{open:e!==null,onClose:o,anchorReference:"anchorPosition",anchorPosition:e!==null?{top:e.mouseY,left:e.mouseX}:void 0,children:[jsx(MenuItem,{onClick:o,children:"Copy"}),jsx(Divider,{}),jsx(MenuItem,{disabled:true,children:"Visible Columns"}),t.map(n=>jsxs(MenuItem,{onClick:()=>l(n.id),children:[jsx(ListItemIcon,{children:r.includes(n.id)&&jsx(Oa,{fontSize:"small"})}),jsx(ListItemText,{children:n.label})]},n.id))]});var je=(e,o=2)=>e.toLocaleString(void 0,{maximumFractionDigits:o}),qo=({kpis:e})=>{let o=[{label:"Total Records",value:je(e.totalRecords,0),color:"text.primary"},{label:"Total Report",value:je(e.totalReportHours),color:"text.primary"},{label:"Total Billable",value:je(e.totalBillableHours),color:"success.main"},{label:"Efficiency",value:`${e.efficiency.toFixed(2)}%`,color:"warning.main"},{label:"Amount",value:je(e.totalAmount),color:"info.main"},{label:"Flagged",value:je(e.flaggedCount,0),color:"error.main"}];return jsx(Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"repeat(2, minmax(0, 1fr))",lg:"repeat(6, minmax(0, 1fr))"},gap:1.5},children:o.map(t=>jsxs(Paper,{variant:"outlined",sx:{p:1.5,borderRadius:2,minHeight:96,display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[jsx(Typography,{variant:"caption",color:"text.secondary",children:t.label}),jsx(Typography,{variant:"h4",fontWeight:800,sx:{color:t.color},children:t.value})]},t.label))})};var bt=["#1E88E5","#1ABC9C","#FBC02D","#EF5350","#7E57C2","#78909C"],Ua=({data:e})=>{let o=Math.max(...e.map(t=>t.value),1);return jsx(Stack,{spacing:1,children:e.map(t=>jsxs(Box,{sx:{display:"grid",gridTemplateColumns:"140px 1fr 64px",gap:1},children:[jsx(Typography,{variant:"caption",color:"text.secondary",noWrap:true,title:t.name,children:t.name}),jsx(Box,{sx:{alignSelf:"center",bgcolor:"action.hover",height:10,borderRadius:999,overflow:"hidden"},children:jsx(Box,{sx:{width:`${t.value/o*100}%`,height:"100%",bgcolor:"primary.main"}})}),jsx(Typography,{variant:"caption",sx:{textAlign:"right",fontWeight:600},children:t.value.toFixed(1)})]},t.name))})},Ka=({data:e})=>{let o=Math.max(...e.map(t=>t.value),1);return jsx(Box,{sx:{display:"flex",gap:1,alignItems:"flex-end",minHeight:210},children:e.map(t=>jsxs(Box,{sx:{flex:1,minWidth:0},children:[jsx(Box,{sx:{height:`${Math.max(t.value/o*180,6)}px`,bgcolor:"primary.main",borderRadius:"8px 8px 0 0"}}),jsx(Typography,{variant:"caption",noWrap:true,title:t.name,sx:{display:"block",mt:.5},children:t.name}),jsxs(Typography,{variant:"caption",color:"text.secondary",children:[t.value.toFixed(1),"%"]})]},t.name))})},Ya=({data:e})=>{if(e.length===0)return jsx(Typography,{variant:"body2",color:"text.secondary",children:"No data"});let o=0,r=`conic-gradient(${e.map((l,n)=>{let i=o;return o+=l.percent,`${bt[n%bt.length]} ${i}% ${o}%`}).join(", ")})`;return jsxs(Stack,{direction:{xs:"column",sm:"row"},spacing:2,alignItems:"center",children:[jsx(Box,{sx:{width:180,height:180,borderRadius:"50%",background:r,position:"relative"},children:jsx(Box,{sx:{position:"absolute",inset:30,bgcolor:"background.paper",borderRadius:"50%"}})}),jsx(Stack,{spacing:1,sx:{minWidth:180},children:e.map((l,n)=>jsxs(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsx(Box,{sx:{width:10,height:10,borderRadius:"50%",bgcolor:bt[n%bt.length]}}),jsx(Typography,{variant:"caption",sx:{flex:1},children:l.name}),jsxs(Typography,{variant:"caption",sx:{fontWeight:700},children:[l.percent.toFixed(0),"%"]})]},l.name))})]})},ao=({title:e,subtitle:o,children:t})=>jsxs(Paper,{variant:"outlined",sx:{p:2,borderRadius:2},children:[jsx(Typography,{variant:"subtitle1",fontWeight:700,children:e}),jsx(Typography,{variant:"body2",color:"text.secondary",sx:{mb:2},children:o}),t]}),Xo=({billableByPrimary:e,efficiencyBySecondary:o,statusDistribution:t})=>jsxs(Box,{sx:{display:"grid",gap:1.5,gridTemplateColumns:{xs:"1fr",lg:"1.2fr 1.2fr 1fr"}},children:[jsx(ao,{title:"Billable by Dimension",subtitle:"Top values by billable hours",children:jsx(Ua,{data:e})}),jsx(ao,{title:"Efficiency by Person",subtitle:"Lowest efficiency first",children:jsx(Ka,{data:o})}),jsx(ao,{title:"Status Distribution",subtitle:"Record ratio by status",children:jsx(Ya,{data:t})})]});var Zo=({open:e,onClose:o,model:t,tableContent:r})=>jsx(Dialog,{open:e,onClose:o,fullScreen:true,children:jsxs(Box,{sx:{height:"100%",display:"flex",flexDirection:"column",bgcolor:"background.default"},children:[jsx(Box,{sx:{p:2,borderBottom:1,borderColor:"divider"},children:jsxs(Stack,{direction:"row",alignItems:"center",justifyContent:"space-between",spacing:2,children:[jsxs(Stack,{direction:"row",spacing:1.5,alignItems:"center",children:[jsx(Typography,{variant:"h5",fontWeight:800,children:t.title}),jsx(Chip,{size:"small",label:`${t.kpis.totalRecords} records`})]}),jsx(IconButton,{onClick:o,children:jsx(Qa,{})})]})}),jsxs(Box,{sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,overflow:"auto",minHeight:0},children:[jsx(qo,{kpis:t.kpis}),jsx(Xo,{billableByPrimary:t.charts.billableByPrimary,efficiencyBySecondary:t.charts.efficiencyBySecondary,statusDistribution:t.charts.statusDistribution}),r]})]})});var Ie={primaryDimension:["Client","Customer","Category","Project"],secondaryDimension:["Person","Consultant","Owner","Name"],status:["Status","state"],date:["Date","WorkDate","CreatedAt"],description:["Description","Task","Title","Memo"],reportHours:["Report_Hour","Report Hours","Hours","ReportHours"],billableHours:["Billable_Hour","Billable Hours","BillableHours"],amount:["Amount","Billable_Amount","Total_Amount","Value"]},er=5,Qo=e=>e.toLowerCase().replace(/[\s_-]/g,""),ke=(e,o,t,r)=>{if(o)return o;if(e.length===0)return r;let l=Object.keys(e[0]),n=new Map(l.map(i=>[Qo(i),i]));for(let i of t){let a=n.get(Qo(i));if(a)return a}return l[0]||r},xe=e=>{if(typeof e=="number")return Number.isFinite(e)?e:0;if(typeof e=="string"){let o=Number(e.replace(/,/g,"").trim());return Number.isFinite(o)?o:0}return 0},Ce=(e,o)=>e==null||e===""?o:String(e),tr=(e,o,t,r)=>{let l=new Map;return e.forEach(n=>{let i=Ce(n[o],"Unassigned");l.set(i,(l.get(i)||0)+xe(n[t]));}),Array.from(l.entries()).map(([n,i])=>({name:n,value:i})).sort((n,i)=>i.value-n.value).slice(0,r)},or=(e,o,t,r,l)=>{let n=new Map;return e.forEach(i=>{let a=Ce(i[o],"Unassigned"),d=n.get(a)||{report:0,billable:0};d.report+=xe(i[t]),d.billable+=xe(i[r]),n.set(a,d);}),Array.from(n.entries()).map(([i,a])=>({name:i,value:a.report>0?a.billable/a.report*100:0})).sort((i,a)=>i.value-a.value).slice(0,l)},nr=(e,o)=>{let t=e.length;if(t===0)return [];let r=new Map;return e.forEach(l=>{let n=Ce(l[o],"Unassigned");r.set(n,(r.get(n)||0)+1);}),Array.from(r.entries()).map(([l,n])=>({name:l,value:n,percent:n/t*100}))},en=({rows:e,config:o})=>{let t=useMemo(()=>{let d=o?.fieldMapping;return {primaryDimension:ke(e,d?.primaryDimension,Ie.primaryDimension,"Category"),secondaryDimension:ke(e,d?.secondaryDimension,Ie.secondaryDimension,"Owner"),status:ke(e,d?.status,Ie.status,"Status"),date:ke(e,d?.date,Ie.date,"Date"),description:ke(e,d?.description,Ie.description,"Description"),reportHours:ke(e,d?.reportHours,Ie.reportHours,"ReportHours"),billableHours:ke(e,d?.billableHours,Ie.billableHours,"BillableHours"),amount:ke(e,d?.amount,Ie.amount,"Amount")}},[e,o?.fieldMapping]),r=useMemo(()=>e.map((d,T)=>{let k=xe(d[t.reportHours]),w=xe(d[t.billableHours]),C=xe(d[t.amount]),E=k>0?w/k*100:0;return {id:`graph-row-${T}`,Date:Ce(d[t.date],""),Primary:Ce(d[t.primaryDimension],"Unassigned"),Secondary:Ce(d[t.secondaryDimension],"Unassigned"),Description:Ce(d[t.description],""),ReportHours:k,BillableHours:w,Amount:C,Efficiency:E,Status:Ce(d[t.status],"Unassigned")}}),[e,t]),l=useMemo(()=>{let d=r.length,T=r.reduce((m,f)=>m+xe(f.ReportHours),0),k=r.reduce((m,f)=>m+xe(f.BillableHours),0),w=r.reduce((m,f)=>m+xe(f.Amount),0),C=T>0?k/T*100:0,E=o?.statusFlagValues||["flag","flagged","warning","risk"],M=r.filter(m=>E.includes(Ce(m.Status,"").toLowerCase())).length;return {totalRecords:d,totalReportHours:T,totalBillableHours:k,efficiency:C,totalAmount:w,flaggedCount:M}},[r,o?.statusFlagValues]),n=o?.topN||er,i=useMemo(()=>({billableByPrimary:tr(r,"Primary","BillableHours",n),efficiencyBySecondary:or(r,"Secondary","ReportHours","BillableHours",n),statusDistribution:nr(r,"Status")}),[r,n]),a=useMemo(()=>({title:o?.title||"Graphic Report",kpis:l,charts:i,table:{columns:[{id:"Date",label:t.date},{id:"Primary",label:t.primaryDimension},{id:"Secondary",label:t.secondaryDimension},{id:"Description",label:t.description},{id:"ReportHours",label:"Report Hours",align:"right"},{id:"BillableHours",label:"Billable Hours",align:"right"},{id:"Amount",label:"Amount",align:"right"},{id:"Efficiency",label:"Efficiency",align:"right"},{id:"Status",label:t.status}],rows:r}}),[i,o?.title,t,l,r]);return {fieldMapping:t,model:a}};var vt=({variants:e,currentVariantId:o,onLoad:t,onSave:r,onDelete:l,onSetDefault:n})=>{let i="0.75rem",[a,d]=useState(false),[T,k]=useState(""),[w,C]=useState(false),[E,M]=useState(false),m=e.find(y=>y.id===o);return jsxs(Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsx(Typography,{variant:"body2",sx:{fontWeight:"bold",minWidth:"fit-content",fontSize:i},children:"Variant:"}),jsx(Autocomplete,{size:"small",sx:{width:200,"& .MuiInputBase-root":{fontSize:i},"& .MuiInputBase-input":{fontSize:i},"& .MuiAutocomplete-noOptions":{fontSize:i}},noOptionsText:jsx(Typography,{sx:{fontSize:i},children:"No options"}),options:e,getOptionLabel:y=>y.name+(y.isDefault?" (Default)":""),value:m||null,onChange:(y,g)=>{g&&t(g);},renderInput:y=>jsx(TextField,{...y,variant:"outlined",size:"small",InputProps:{...y.InputProps,sx:{fontSize:i}},placeholder:"Select Variant"}),renderOption:(y,g)=>jsx("li",{...y,children:jsxs(Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsx(Typography,{sx:{flex:1,fontSize:i},children:g.name}),g.isDefault&&jsx(pr,{fontSize:"small",color:"action"})]})})}),jsx(Tooltip,{title:"Save View",children:jsx(IconButton,{onClick:()=>{k(m?.name||"New Variant"),C(m?.isDefault||false),M(m?.isPublic||false),d(true);},size:"small",color:"primary",children:jsx(vn,{})})}),jsxs(Dialog,{open:a,onClose:()=>d(false),children:[jsx(DialogTitle,{children:"Save View"}),jsxs(DialogContent,{children:[jsx(TextField,{autoFocus:true,margin:"dense",label:"View Name",fullWidth:true,variant:"outlined",value:T,onChange:y=>k(y.target.value)}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:w,onChange:y=>C(y.target.checked)}),label:"Set as Default"}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:E,onChange:y=>M(y.target.checked)}),label:"Public (All Users)"})]}),jsxs(DialogActions,{children:[jsx(Button,{onClick:()=>d(false),children:"Cancel"}),jsx(Button,{onClick:()=>{r({name:T,isDefault:w,isPublic:E,description:""}),d(false);},variant:"contained",children:"Save"})]})]})]})};var fr="http://127.0.0.1:8515",sn=({appId:e,tableKey:o="default",currentFilters:t,currentLayoutId:r,layoutRefs:l,onLoad:n,serviceUrl:i=fr,onError:a,onSuccess:d,currentVariantId:T,onVariantChange:k})=>{let[w,C]=useState([]),[E,M]=useState(""),m=T!==void 0?T:E,f=c=>{T===void 0&&M(c),k&&k(c);},S=useCallback(async()=>{if(!e)return [];try{let c=await fetch(`${i}/api/variants?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!c.ok)throw new Error("Failed to fetch variants");let u=await c.json();C(u);let b=u.find(x=>x.isDefault);return b&&!m&&(f(b.id),n(b)),u}catch(c){return console.error("Error fetching variants",c),a&&a("Failed to load variants"),[]}},[e,o,i,a,m,n]);return useEffect(()=>{S();},[e,o]),jsx(vt,{variants:w,currentVariantId:m,onLoad:c=>{f(c.id),n(c);},onSave:async c=>{try{let u=w.find(L=>L.name===c.name),b=u?u.id:Date.now().toString(),x=[];if(u&&(Array.isArray(u.filters)?x=[...u.filters]:u.filters&&(x=[{scope:"default",filters:u.filters}])),c.scope==="Search"||c.scope==="Both"){let L=(Array.isArray(t),t);if(L)if(Array.isArray(L)&&L.length>0&&L[0].scope)L.forEach(V=>{let A=x.findIndex(N=>N.scope===V.scope);A>=0?x[A]=V:x.push(V);});else {let V={scope:o,filters:L},A=x.findIndex(N=>N.scope===o);A>=0?x[A]=V:x.push(V);}}let s=u?.layout||{},R=[];if(u&&Array.isArray(u.layoutRefs)&&(R=[...u.layoutRefs]),c.scope==="Layout"||c.scope==="Both")if(l&&l.length>0)l.forEach(L=>{let V=R.findIndex(A=>A.tableKey===L.tableKey);V>=0?R[V]=L:R.push(L);});else {let L={tableKey:o,layoutId:r||null},V=R.findIndex(A=>A.tableKey===o);V>=0?R[V]=L:R.push(L);}let v={appId:e,tableKey:o,...c,id:b,createdAt:new Date().toISOString(),filters:x,layout:s,layoutRefs:R};if(!(await fetch(`${i}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(v)})).ok)throw new Error("Failed to save variant");d&&d("Variant saved successfully"),await S(),f(b),n(v);}catch(u){console.error("Error saving variant",u),a&&a("Failed to save variant");}},onDelete:async c=>{try{if(!(await fetch(`${i}/api/variants/${c}`,{method:"DELETE"})).ok)throw new Error("Failed to delete variant");m===c&&f(""),S(),d&&d("Variant deleted successfully");}catch(u){console.error("Error deleting variant",u),a&&a("Failed to delete variant");}},onSetDefault:async c=>{try{let u=w.find(s=>s.id===c);if(!u)return;let b={appId:e,tableKey:o,...u,isDefault:!0};if(!(await fetch(`${i}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)})).ok)throw new Error("Failed to set default variant");await S(),d&&d("Default variant updated");}catch(u){console.error("Error setting default variant",u),a&&a("Failed to update default variant");}}})};Ee.extend(Pr);var Er=[null,null],uo="0.75rem",Lr=styled(PickersDay,{shouldForwardProp:e=>e!=="isInRange"&&e!=="isStart"&&e!=="isEnd"&&e!=="isHovered"})(({theme:e,isInRange:o,isStart:t,isEnd:r,isHovered:l})=>({...o&&{borderRadius:0,backgroundColor:e.palette.primary.light,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.main}},...l&&!o&&!t&&!r&&{borderRadius:0,backgroundColor:e.palette.action.hover,border:`1px dashed ${e.palette.primary.main}`},...t&&{borderRadius:"50% 0 0 50%",backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.dark}},...r&&{borderRadius:"0 50% 50% 0",backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.dark}},...t&&r&&{borderRadius:"50%"}})),un=({label:e="Date Range",value:o=Er,onChange:t})=>{let[r,l]=useState(null),[n,i]=useState(o),[a,d]=useState("start"),[T,k]=useState(null),[w,C]=useState(o[0]||Ee()),E=So__default.useRef(o);useEffect(()=>{let[b,x]=o,[s,R]=E.current,v=V=>V&&typeof V.isSame=="function",z=!(b===null&&s===null||v(b)&&v(s)&&b.isSame(s,"day")),L=!(x===null&&R===null||v(x)&&v(R)&&x.isSame(R,"day"));(z||L)&&(i(o),o[0]&&v(o[0])&&C(o[0])),E.current=o;},[o]);let M=b=>{l(b.currentTarget);},m=()=>{l(null),d("start"),k(null);},f=!!r,S=b=>{if(!b)return;let x=[...n];if(a==="start")x=[b,null],d("end");else {let s=x[0];s&&b.isBefore(s)?(x=[b,null],d("end")):(x=[s,b],d("start"));}i(x);},y=b=>{let x=Ee(),s=[null,null];switch(b){case "today":s=[x,x];break;case "week":s=[x.startOf("week"),x.endOf("week")];break;case "month":s=[x.startOf("month"),x.endOf("month")];break}i(s),d("start"),C(x);},g=()=>{i([null,null]),d("start"),C(Ee());},p=()=>{t&&t(n),m();},I=()=>{i(o),d("start"),m();},c=useCallback(b=>{let{day:x,...s}=b,[R,v]=n,z=R?x.isSame(R,"day"):false,L=v?x.isSame(v,"day"):false,V=R&&v?x.isBetween(R,v,"day","()"):false,A=false;return a==="end"&&R&&!v&&T&&x.isAfter(R,"day")&&x.isBefore(T.add(1,"day"),"day")&&(A=true),jsx(Lr,{...s,day:x,disableMargin:true,isStart:z,isEnd:L,isInRange:V||A,onMouseEnter:()=>k(x)})},[n,a,T]),u=b=>b?b.format("YYYY-MM-DD"):"";return jsxs(Box,{children:[jsx(TextField,{label:e,value:n[0]?`${u(n[0])} - ${u(n[1])}`:"",onClick:M,fullWidth:true,size:"small",InputLabelProps:{sx:{fontSize:uo}},InputProps:{readOnly:true,sx:{fontSize:uo,"& .MuiOutlinedInput-input":{fontSize:uo},paddingRight:"4px"},endAdornment:jsxs(InputAdornment,{position:"end",sx:{ml:0},children:[(n[0]||n[1])&&jsx(IconButton,{size:"small",onClick:b=>{b.stopPropagation(),g();},edge:"end",sx:{mr:.5,padding:"2px"},children:jsx(Rr,{sx:{fontSize:"1rem"}})}),jsx(IconButton,{size:"small",edge:"end",onClick:M,sx:{padding:"2px"},children:jsx(Mr,{sx:{fontSize:"1rem"},color:"action"})})]})}}),jsxs(Popover,{open:f,anchorEl:r,onClose:m,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},slotProps:{paper:{sx:{display:"flex",flexDirection:"column",p:0,minWidth:320}}},children:[jsx(Box,{sx:{p:2,bgcolor:"background.default",borderBottom:1,borderColor:"divider"},children:jsxs(Stack,{direction:"row",alignItems:"center",spacing:2,justifyContent:"space-between",children:[jsxs(Box,{sx:{p:1,border:1,borderColor:a==="start"?"primary.main":"divider",borderRadius:1,bgcolor:a==="start"?"action.hover":"transparent",flex:1,cursor:"pointer"},onClick:()=>d("start"),children:[jsx(Typography,{variant:"caption",color:"text.secondary",display:"block",children:"Start Date"}),jsx(Typography,{variant:"body2",fontWeight:500,children:n[0]?n[0].format("MMM DD, YYYY"):"Select..."})]}),jsx(Dr,{color:"action",fontSize:"small"}),jsxs(Box,{sx:{p:1,border:1,borderColor:a==="end"?"primary.main":"divider",borderRadius:1,bgcolor:a==="end"?"action.hover":"transparent",flex:1,cursor:"pointer"},onClick:()=>{n[0]&&d("end");},children:[jsx(Typography,{variant:"caption",color:"text.secondary",display:"block",children:"End Date"}),jsx(Typography,{variant:"body2",fontWeight:500,children:n[1]?n[1].format("MMM DD, YYYY"):"Select..."})]})]})}),jsx(Box,{sx:{p:2,pb:0},children:jsxs(Stack,{direction:"row",spacing:1,justifyContent:"center",children:[jsx(Chip,{label:"Today",onClick:()=>y("today"),clickable:true,size:"small",variant:"outlined"}),jsx(Chip,{label:"This Week",onClick:()=>y("week"),clickable:true,size:"small",variant:"outlined"}),jsx(Chip,{label:"This Month",onClick:()=>y("month"),clickable:true,size:"small",variant:"outlined"})]})}),jsx(DateCalendar,{value:null,referenceDate:w,onMonthChange:C,onYearChange:C,onChange:S,slots:{day:c},views:["day"],showDaysOutsideCurrentMonth:true,sx:{m:0}}),jsx(Divider,{}),jsxs(Stack,{direction:"row",justifyContent:"flex-end",spacing:1,sx:{p:2},children:[jsx(Button,{size:"small",onClick:I,color:"inherit",children:"Cancel"}),jsx(Button,{size:"small",variant:"contained",onClick:p,children:"Done"})]})]})]})};var It={equals:"=",contains:"\u2287",notContains:"\u2285",wildcard:"*","=":"=","!=":"!=",">":">","<":"<",">=":"\u2265","<=":"\u2264",between:"\u2194"},$r={equals:"Equals",contains:"Contains",notContains:"Does Not Contain",wildcard:"Wildcard Search","=":"Equals","!=":"Not Equals",">":"Greater Than","<":"Less Than",">=":"Greater Than or Equal","<=":"Less Than or Equal",between:"Between"},_r=["equals","contains","notContains","wildcard"],gn=["=","!=",">","<",">=","<=","between"],Z="0.75rem",jr=({field:e,value:o,onChange:t})=>{let[r,l]=useState(null),[n,i]=useState(null),[a,d]=useState(""),[T,k]=useState(""),[w,C]=useState(false),[E,M]=useState(""),[m,f]=useState("");useEffect(()=>{let s=setTimeout(()=>{f(E);},1e3);return ()=>clearTimeout(s)},[E]);let S=o?.operator||(e.type==="number"?"=":"equals"),y=o?.value,g=s=>$r[s]||s,p=s=>{l(s.currentTarget);},I=s=>{t({...o,operator:s,value:y}),l(null);},c={size:"small",fullWidth:true,variant:"outlined",InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}},SelectProps:{MenuProps:{PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,paddingTop:"4px",paddingBottom:"4px",minHeight:"auto"}}}}}},u=e.type||"text";if(u==="date"){let R=(v=>{if(!v)return [null,null];if(Array.isArray(v)&&v.length===2){let z=v[0]?Ee.isDayjs(v[0])?v[0]:Ee(v[0]):null,L=v[1]?Ee.isDayjs(v[1])?v[1]:Ee(v[1]):null;return [z,L]}return Ee.isDayjs(v)||typeof v=="string"?[Ee.isDayjs(v)?v:Ee(v),null]:[null,null]})(y);return jsx(un,{label:e.label,value:R,onChange:v=>t({value:v,operator:"between"})})}if(u==="number"&&S==="between"){let s=()=>{t({value:[a,T],operator:"between"}),i(null);},R=Array.isArray(y)?`${y[0]||""} - ${y[1]||""}`:"";return jsxs(Fragment,{children:[jsx(TextField,{...c,label:e.label,value:R,placeholder:"Min - Max",InputProps:{...c.InputProps,startAdornment:jsx(InputAdornment,{position:"start",children:jsx(Tooltip,{title:g("between"),children:jsx(IconButton,{size:"small",onClick:p,sx:{width:24,height:24,fontSize:Z},children:It.between})})}),readOnly:true},onClick:v=>i(v.currentTarget)}),jsx(Menu,{anchorEl:r,open:!!r,onClose:()=>l(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,minHeight:"auto",py:.5}}},children:gn.map(v=>jsxs(MenuItem,{selected:v===S,onClick:()=>I(v),children:[jsx(Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:It[v]}),jsx(ListItemText,{primary:g(v),primaryTypographyProps:{fontSize:Z}})]},v))}),jsx(Popover,{open:!!n,anchorEl:n,onClose:()=>i(null),anchorOrigin:{vertical:"bottom",horizontal:"left"},children:jsxs(Box,{sx:{p:2,display:"flex",gap:1,alignItems:"center"},children:[jsx(TextField,{size:"small",label:"Min",type:"number",value:a,onChange:v=>d(v.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}}}),jsx(Wr,{color:"action"}),jsx(TextField,{size:"small",label:"Max",type:"number",value:T,onChange:v=>k(v.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}}}),jsx(Button,{variant:"contained",size:"small",onClick:s,children:"OK"})]})})]})}if(u==="select")return jsxs(TextField,{...c,select:true,label:e.label,value:y||"",onChange:s=>t({...o,value:s.target.value,operator:"equals"}),children:[jsx(MenuItem,{value:"",children:jsx("em",{children:"None"})}),e.options?.map(s=>jsx(MenuItem,{value:s.value,children:s.label},s.value))]});if(u==="multi-select"){let s=Array.isArray(y)?y:[],R=e.options?.filter(v=>v.label.toLowerCase().includes(m.toLowerCase()))||[];return jsxs(TextField,{...c,select:true,label:e.label,value:s,onChange:v=>t({...o,value:v.target.value,operator:"anyOf"}),SelectProps:{...c.SelectProps,multiple:true,onClose:()=>{M(""),f("");},renderValue:v=>{if(!Array.isArray(v)||v.length===0)return jsx("em",{children:"None"});let z=V=>e.options?.find(A=>A.value===V)?.label||V,L=v.map(z);return L.length>2?`${L.slice(0,2).join(", ")} +${L.length-2}`:L.join(", ")}},children:[jsx(ListSubheader,{children:jsx(TextField,{size:"small",autoFocus:true,placeholder:"Search...",fullWidth:true,InputProps:{startAdornment:jsx(InputAdornment,{position:"start",children:jsx(mn,{fontSize:"small"})}),sx:{fontSize:Z}},value:E,onChange:v=>M(v.target.value),onKeyDown:v=>{v.key!=="Escape"&&v.stopPropagation();},onClick:v=>v.stopPropagation()})}),R.length>0?R.map(v=>jsxs(MenuItem,{value:v.value,children:[jsx(Checkbox,{checked:s.indexOf(v.value)>-1,size:"small"}),jsx(ListItemText,{primary:v.label,primaryTypographyProps:{fontSize:Z}})]},v.value)):jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"No options found",primaryTypographyProps:{fontSize:Z}})})]})}let b=u==="number"?gn:_r,x=w||y!==void 0&&y!==""&&y!==null||!!r;return jsxs(Fragment,{children:[jsx(TextField,{...c,label:e.label,sx:{minWidth:"120px"},value:y||"",type:u==="number"?"number":"text",onChange:s=>t({...o,value:s.target.value,operator:S}),onFocus:()=>C(true),onBlur:()=>C(false),InputProps:{...c.InputProps,startAdornment:x?jsx(InputAdornment,{position:"start",children:jsx(Tooltip,{title:g(S),children:jsx(IconButton,{size:"small",onClick:p,onMouseDown:s=>s.preventDefault(),sx:{width:24,height:24,fontSize:Z,fontWeight:"bold",color:"primary.main",bgcolor:"action.hover"},children:It[S]})})}):null,endAdornment:e.hasSearchIcon?jsx(InputAdornment,{position:"end",children:jsx(mn,{color:"action"})}):void 0}}),jsx(Menu,{anchorEl:r,open:!!r,onClose:()=>l(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,minHeight:"auto",py:.5}}},children:b.map(s=>jsxs(MenuItem,{selected:s===S,onClick:()=>I(s),children:[jsx(Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:It[s]}),jsx(ListItemText,{primary:g(s),primaryTypographyProps:{fontSize:Z}})]},s))})]})},Xe=({fields:e,filters:o,onFilterChange:t,variants:r=[],currentVariantId:l,onVariantLoad:n,onVariantSave:i,onVariantDelete:a,onVariantSetDefault:d,onSearch:T,loading:k=false,appId:w,tableKey:C,currentLayout:E,currentLayoutId:M,layoutRefs:m,variantService:f})=>{let[S,y]=useState(true),[g,p]=useState(null),[I,c]=useState(e.filter(s=>!s.hidden).map(s=>s.id)),u=(s,R)=>{t({...o,[s]:R});},b=s=>{I.includes(s)?c(I.filter(R=>R!==s)):c([...I,s]);};return jsxs(Paper,{sx:{mb:0,display:"flex",flexDirection:"column",overflow:"visible",position:"relative"},children:[jsxs(Box,{sx:{p:2,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[w?jsx(sn,{appId:w,tableKey:C,currentFilters:{values:o,visibleFields:I},currentLayout:E,currentLayoutId:M,layoutRefs:m,onLoad:s=>{if(!s.filters)return;let R=null;if(Array.isArray(s.filters)){let v=C||"default",z=s.filters.find(L=>L.scope===v);R=z?z.filters:null;}else R=s.filters;R&&(R.values||R.visibleFields?(R.visibleFields&&Array.isArray(R.visibleFields)&&c(R.visibleFields),R.values&&t(R.values)):t(R)),n&&n(s);},variantService:f,currentVariantId:l}):jsx(vt,{variants:r,currentVariantId:l,onLoad:n,onSave:s=>{i&&i({...s,filters:{values:o,visibleFields:I}});},onDelete:a,onSetDefault:d}),jsxs(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsx(Tooltip,{title:"Add Filters",children:jsx(Button,{onClick:s=>p(s.currentTarget),size:"small",color:"primary",startIcon:jsx(zr,{fontSize:"small"}),sx:{textTransform:"none",fontSize:Z},children:"Adapt Filters"})}),jsx(Button,{variant:"contained",size:"small",onClick:T,disabled:k,sx:{minWidth:"40px",fontWeight:"bold"},children:k?"...":"Go"}),jsxs(Menu,{anchorEl:g,open:!!g,onClose:()=>p(null),slotProps:{paper:{style:{maxHeight:400,width:"25ch"}}},children:[jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"Visible Filters"})}),jsx(Divider,{}),e.map(s=>jsxs(MenuItem,{onClick:()=>b(s.id),children:[jsx(Checkbox,{checked:I.includes(s.id),size:"small"}),jsx(ListItemText,{primary:s.label})]},s.id))]})]})]}),jsx(Collapse,{in:S,children:jsx(Box,{sx:{px:2,pb:2},children:jsx(Grid,{container:true,spacing:2,columns:{xs:2,sm:3,md:4,lg:6},children:e.filter(s=>I.includes(s.id)).map(s=>jsx(Grid,{size:1,children:jsx(jr,{field:s,value:o[s.id]||{value:"",operator:s.type==="number"?"=":"equals"},onChange:R=>u(s.id,R)})},s.id))})})}),jsx(Box,{sx:{position:"absolute",bottom:0,left:"50%",transform:"translate(-50%, 50%)",zIndex:10},children:jsx(IconButton,{size:"small",onClick:()=>y(!S),sx:{bgcolor:"background.paper",boxShadow:2,border:"1px solid",borderColor:"divider",width:20,height:20,minHeight:0,p:0,"&:hover":{bgcolor:"background.paper"}},children:S?jsx(Or,{sx:{fontSize:16},color:"action"}):jsx(Ra,{sx:{fontSize:16},color:"action"})})})]})};var Sn=({layouts:e,currentLayoutId:o,onLoad:t,onSave:r,onDelete:l,onSetDefault:n})=>{let[i,a]=useState(null),[d,T]=useState(false),[k,w]=useState(""),[C,E]=useState(""),[M,m]=useState({isDefault:false,isPublic:false}),f=e.find(c=>c.id===o),S=c=>{a(c.currentTarget);},y=()=>{a(null);},g=c=>{t(c),y();},p=()=>{w(""),E(""),m({isDefault:false,isPublic:false}),T(true),y();},I=()=>{k.trim()&&(r({name:k,description:C,...M}),T(false));};return jsxs(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsx(Tooltip,{title:"Save Layout",children:jsx(IconButton,{onClick:p,color:"primary",size:"small",children:jsx(vn,{})})}),jsx(Tooltip,{title:"Layout Options",children:jsx(IconButton,{onClick:S,color:f?"primary":"default",children:jsx(ni,{})})}),jsxs(Menu,{anchorEl:i,open:!!i,onClose:y,PaperProps:{sx:{width:320,maxHeight:400}},children:[jsx(MenuItem,{disabled:true,children:jsx(Typography,{variant:"caption",children:"Select Layout"})}),jsxs(MenuItem,{onClick:p,children:[jsx(ListItemIcon,{children:jsx(vn,{fontSize:"small"})}),jsx(ListItemText,{children:"Save Current Layout..."})]}),jsx(Divider,{}),e.length===0&&jsx(MenuItem,{disabled:true,children:jsx(Typography,{variant:"body2",color:"text.secondary",children:"No saved layouts"})}),e.map((c,u)=>jsx(MenuItem,{onClick:()=>g(c),selected:c.id===o,children:jsxs(Box,{sx:{display:"flex",alignItems:"center",width:"100%",justifyContent:"space-between"},children:[jsxs(Box,{sx:{display:"flex",flexDirection:"column",overflow:"hidden",mr:1},children:[jsx(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:jsx(Typography,{variant:"body2",fontWeight:c.id===o?"bold":"normal",noWrap:true,children:c.name})}),c.description&&jsx(Typography,{variant:"caption",color:"text.secondary",noWrap:true,children:c.description})]}),jsxs(Box,{sx:{display:"flex",alignItems:"center"},onClick:b=>b.stopPropagation(),children:[jsx(Tooltip,{title:c.isDefault?"Remove Default":"Set as Default",children:jsx(IconButton,{size:"small",onClick:b=>{b.stopPropagation(),n(c.id);},children:c.isDefault?jsx(pr,{fontSize:"small",color:"warning"}):jsx(oi,{fontSize:"small"})})}),jsx(Tooltip,{title:"Delete",children:jsx(IconButton,{size:"small",color:"error",onClick:b=>{b.stopPropagation(),l(c.id);},children:jsx(ei,{fontSize:"small"})})})]})]})},c.id||u))]}),jsxs(Dialog,{open:d,onClose:()=>T(false),maxWidth:"xs",fullWidth:true,children:[jsx(DialogTitle,{children:"Save Layout"}),jsx(DialogContent,{children:jsxs(Box,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[jsx(TextField,{label:"Layout Name",value:k,onChange:c=>w(c.target.value),fullWidth:true,autoFocus:true,size:"small",helperText:"e.g., 'Compact View'"}),e.some(c=>c.name===k)&&jsx(Typography,{variant:"caption",color:"warning.main",sx:{ml:1},children:"Warning: Existing layout will be overwritten"}),jsx(TextField,{label:"Description",value:C,onChange:c=>E(c.target.value),fullWidth:true,size:"small"}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:M.isDefault,onChange:c=>m({...M,isDefault:c.target.checked})}),label:"Use as Default Layout"}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:M.isPublic,onChange:c=>m({...M,isPublic:c.target.checked})}),label:"Public (Visible to all users)"})]})}),jsxs(DialogActions,{children:[jsx(Button,{onClick:()=>T(false),children:"Cancel"}),jsx(Button,{onClick:I,variant:"contained",disabled:!k,children:"Save"})]})]})]})};var ai="http://127.0.0.1:8515",wn=({appId:e,tableKey:o="default",currentLayoutData:t,onLayoutLoad:r,targetLayoutId:l,activeLayoutId:n,serviceUrl:i=ai,onError:a,onSuccess:d})=>{let[T,k]=useState([]),[w,C]=useState(""),E=`orbcafe.layouts.${e}.${o}`,M=u=>({id:u.layoutId,name:u.name,description:u.description??"",isDefault:!!u.isDefault,isPublic:!!u.isPublic,createdAt:u.createdAt??new Date().toISOString(),layoutData:u.layout??{}}),m=u=>({appId:e,tableKey:o,layoutId:u.id,name:u.name,description:u.description??"",isDefault:!!u.isDefault,isPublic:!!u.isPublic,createdAt:u.createdAt,layout:u.layoutData}),f=useCallback(()=>{try{let u=localStorage.getItem(E);if(!u)return [];let b=JSON.parse(u);return Array.isArray(b)?b:[]}catch{return []}},[E]),S=useCallback(u=>{try{localStorage.setItem(E,JSON.stringify(u));}catch{}},[E]);useEffect(()=>{n!==void 0&&C(n);},[n]),useEffect(()=>{if(l&&T.length>0){let u=T.find(b=>b.id===l);u&&(C(u.id),r(u));}},[l,T,r]);let y=useCallback(async()=>{if(e)try{let u=await fetch(`${i}/api/layouts?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!u.ok)throw new Error("Failed to fetch layouts");let x=(await u.json()).map(M);k(x);let s=x.find(R=>R.isDefault);s&&!w&&!l&&(C(s.id),r(s));}catch(u){console.error("Error fetching layouts",u);let b=f();k(b);let x=b.find(s=>s.isDefault);x&&!w&&!l&&(C(x.id),r(x)),a&&a("Failed to load layouts from backend, fallback to local storage");}},[e,o,i,a,w,r,l,f]);return useEffect(()=>{y();},[e,o]),jsx(Sn,{layouts:T,currentLayoutId:w,onLoad:u=>{C(u.id),r(u);},onSave:async u=>{let b=T.find(R=>R.name===u.name),x=b?b.id:Date.now().toString(),s={id:x,...u,createdAt:new Date().toISOString(),layoutData:t,isDefault:u.isDefault??false,isPublic:u.isPublic??false};try{if(!(await fetch(`${i}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(m(s))})).ok)throw new Error("Failed to save layout");d&&d("Layout saved successfully"),await y(),C(x),r(s);}catch(R){console.error("Error saving layout",R);let z=T.some(L=>L.id===x)?T.map(L=>L.id===x?s:L):[...T,s];k(z),S(z),C(x),r(s),d&&d("Layout saved to local storage"),a&&a("Backend unavailable, saved to local storage");}},onDelete:async u=>{try{if(!(await fetch(`${i}/api/layouts/${encodeURIComponent(u)}`,{method:"DELETE"})).ok)throw new Error("Failed to delete layout");w===u&&C(""),d&&d("Layout deleted successfully"),await y();}catch(b){console.error("Error deleting layout",b);let x=T.filter(s=>s.id!==u);k(x),S(x),w===u&&C(""),d&&d("Layout deleted from local storage"),a&&a("Backend unavailable, deleted from local storage");}},onSetDefault:async u=>{try{let b=T.find(s=>s.id===u);if(!b)return;if(!(await fetch(`${i}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(m({...b,isDefault:!0}))})).ok)throw new Error("Failed to set default layout");d&&d("Default layout set"),await y();}catch(b){console.error("Error setting default",b);let x=T.map(s=>({...s,isDefault:s.id===u}));k(x),S(x),d&&d("Default layout set in local storage"),a&&a("Backend unavailable, default saved to local storage");}}})};function kn(e,o,t){return o[t]<e[t]?-1:o[t]>e[t]?1:0}function ii(e,o){return e==="desc"?(t,r)=>kn(t,r,o):(t,r)=>-kn(t,r,o)}function li(e,o){let t=e.map((r,l)=>[r,l]);return t.sort((r,l)=>{let n=o(r[0],l[0]);return n!==0?n:r[1]-l[1]}),t.map(r=>r[0])}var Mn=e=>{let o=useCallback(h=>{let B=String(h?.label??h?.id??"").length*9+64,ee=typeof h?.minWidth=="number"?h.minWidth:0;return Math.max(100,ee,B)},[]),[t,r]=useState(""),[l,n]=useState(e.order||"asc"),[i,a]=useState(e.orderBy||""),[d,T]=useState(e.page||0),[k,w]=useState(e.rowsPerPage||20),[C,E]=useState(e.selected||[]),[M,m]=useState(e.columns?e.columns.map(h=>h.id):[]),[f,S]=useState(e.showSummary||false),[y,g]=useState([]),[p,I]=useState(new Set),[c,u]=useState(()=>{let h={};return (e.columns||[]).forEach(D=>{h[D.id]=o(D);}),h}),[b,x]=useState(null),[s,R]=useState(null),[v,z]=useState(null),[L,V]=useState(null),[A,N]=useState(false),[te,Oe]=useState("");useEffect(()=>{e.order!==void 0&&n(e.order),e.orderBy!==void 0&&a(e.orderBy);},[e.order,e.orderBy]),useEffect(()=>{e.selected!==void 0&&E(e.selected);},[e.selected]),useEffect(()=>{e.page!==void 0&&T(e.page);},[e.page]),useEffect(()=>{u(h=>{let D={...h};return (e.columns||[]).forEach(B=>{D[B.id]===void 0&&(D[B.id]=o(B));}),D});},[e.columns,o]);let oe=useMemo(()=>{let h=e.rows||[];return t&&(h=h.filter(D=>Object.keys(D).some(B=>String(D[B]).toLowerCase().includes(t.toLowerCase())))),h},[e.rows,t]),re=useMemo(()=>e.onSortChange||!i?oe:li(oe,ii(l,i)),[oe,l,i,e.onSortChange]),ie=useCallback(h=>{if(y.length===0)return h.map(Y=>({type:"row",data:Y,id:Y[e.rowKey||"id"]}));let D=[...h].sort((Y,q)=>{for(let $ of y){if(Y[$]<q[$])return -1;if(Y[$]>q[$])return 1}return 0}),B=(Y,q=0)=>{if(q>=y.length)return Y;let $=y[q],U={},fe=[];return Y.forEach(se=>{let Be=se[$],ce=`${$}:${Be}`;U[ce]||(U[ce]={key:ce,field:$,value:Be,children:[],count:0,level:q},fe.push(U[ce])),U[ce].children.push(se),U[ce].count++;}),fe.forEach(se=>{se.children&&(se.children=B(se.children,q+1));}),fe},ee=B(D),G=(Y,q="")=>{let $=[];return Y.forEach(U=>{if(U.children){let fe=q?`${q}>${U.key}`:U.key,se=p.has(fe);$.push({type:"group",id:fe,field:U.field,value:U.value,level:U.level,count:U.count,isExpanded:se,childIds:(function Be(ce){let Se=[];return ce.children.forEach($e=>{$e.children?Se=Se.concat(Be($e)):Se.push($e[e.rowKey||"id"]);}),Se})(U)}),se&&($=$.concat(G(U.children,fe)));}else $.push({type:"row",data:U,id:U[e.rowKey||"id"],level:y.length});}),$};return G(ee)},[y,p,e.rowKey]),De=useMemo(()=>ie(re),[re,ie]),nt=useMemo(()=>k>0?De.slice(d*k,d*k+k):De,[De,d,k]),at=h=>{let D=new Set(p);D.has(h)?D.delete(h):D.add(h),I(D);},Ge=h=>{at(h);},Ft=h=>{let D=new Set(p);Array.from(D).forEach(B=>{B.startsWith(h)&&D.delete(B);}),I(D);},Vt=h=>{h||I(new Set);},We=h=>{let D=i===h&&l==="asc",B=i===h&&l==="desc";if(e.onSortChange){D?e.onSortChange(h,"desc"):B?e.onSortChange("","asc"):e.onSortChange(h,"asc");return}D?(n("desc"),a(h)):B?(n("asc"),a("")):(n("asc"),a(h));},rt=(h,D)=>{u(B=>({...B,[h]:D}));},Nt=h=>{if(h.target.checked){let D=oe.map(B=>B[e.rowKey||"id"]);E(D),e.onSelectionChange&&e.onSelectionChange(D);return}E([]),e.onSelectionChange&&e.onSelectionChange([]);},Ht=(h,D)=>{let B=D[e.rowKey||"id"],ee=C.indexOf(B),G=[];ee===-1?G=G.concat(C,B):ee===0?G=G.concat(C.slice(1)):ee===C.length-1?G=G.concat(C.slice(0,-1)):ee>0&&(G=G.concat(C.slice(0,ee),C.slice(ee+1))),E(G),e.onSelectionChange&&e.onSelectionChange(G);},it=h=>{T(h),e.onPageChange&&e.onPageChange(h);},lt=h=>{w(h),T(0),e.onRowsPerPageChange&&e.onRowsPerPageChange(h);},zt=h=>{let D=M.indexOf(h),B=[...M];D===-1?B.push(h):B.splice(D,1),m(B);},st=h=>{let D=y.indexOf(h),B=[...y];D===-1?B.push(h):B.splice(D,1),g(B);},Ot=h=>{e.onLayoutSave&&e.onLayoutSave({visibleColumns:M,order:l,orderBy:i,grouping:y,columnWidths:c});},ct=h=>{h.layout&&(h.layout.visibleColumns&&m(h.layout.visibleColumns),h.layout.order&&n(h.layout.order),h.layout.orderBy&&a(h.layout.orderBy),h.layout.grouping&&g(h.layout.grouping),h.layout.columnWidths&&u(h.layout.columnWidths));},Gt=h=>{let D=h?.layoutData||h?.layout||h||{};D.visibleColumns&&m(D.visibleColumns),D.order&&n(D.order),D.orderBy!==void 0&&a(D.orderBy),D.grouping&&g(D.grouping),D.columnWidths&&u(D.columnWidths),D.showSummary!==void 0&&S(!!D.showSummary),I(new Set),T(0),h?.id&&Oe(h.id);};useEffect(()=>{e.layout&&ct({layout:e.layout});},[e.layout]);let Wt=h=>{h.preventDefault(),V(L===null?{mouseX:h.clientX+2,mouseY:h.clientY-6}:null);},$t=()=>{V(null);},dt=useMemo(()=>{if(!f)return {};let h={};e.columns.forEach(B=>{if(B.numeric){let ee=oe.reduce((G,Y)=>{let q=parseFloat(Y[B.id]);return G+(isNaN(q)?0:q)},0);h[B.id]=ee.toFixed(2);}else h[B.id]="";});let D=e.columns.find(B=>M.includes(B.id));return D&&!D.numeric&&(h[D.id]="Total"),h},[oe,e.columns,f,M]),_t=()=>{if(!e.columns||!oe)return;let h=e.columns.map(Y=>Y.label).join(","),D=oe.map(Y=>e.columns.map(q=>{let $=Y[q.id];return `"${($==null?"":String($)).replace(/"/g,'""')}"`}).join(",")).join(`
|
|
2
|
+
`),B=`data:text/csv;charset=utf-8,${h}
|
|
3
|
+
${D}`,ee=encodeURI(B),G=document.createElement("a");G.setAttribute("href",ee),G.setAttribute("download",`${e.title||"export"}.csv`),document.body.appendChild(G),G.click(),document.body.removeChild(G);},jt=()=>{N(true);},Ut=()=>{N(false);};return {isMobile:false,columns:e.columns,order:l,orderBy:i,filterText:t,setFilterText:r,visibleColumns:M,setVisibleColumns:m,showSummary:f,setShowSummary:S,summaryColumns:[],grouping:y,setGrouping:g,expandedGroups:p,setExpandedGroups:I,groupAnchorEl:s,setGroupAnchorEl:R,summaryAnchorEl:v,setSummaryAnchorEl:z,columnWidths:c,setColumnWidths:u,anchorEl:b,setAnchorEl:x,contextMenu:L,setContextMenu:V,sensors:void 0,sortedAndFilteredRows:re,visibleRows:nt,summaryRow:dt,page:d,setPage:it,rowsPerPage:k,setRowsPerPage:lt,selected:C,setSelected:E,isAllExpanded:false,handleColumnResize:rt,handleRequestSort:We,handleSelectAllClick:Nt,handleClick:Ht,toggleSummaryColumn:()=>{},handleDragEnd:()=>{},handleExport:_t,handleContextMenu:Wt,handleCloseContextMenu:$t,toggleColumnVisibility:zt,toggleGroupExpand:at,toggleGroupField:st,handleToggleAll:Vt,handleExpandGroupRecursively:Ge,handleCollapseGroupRecursively:Ft,handleLayoutLoad:Gt,handleVariantLoad:ct,handleLayoutSave:Ot,effectiveAppId:e.appId||"",currentLayoutData:{visibleColumns:M,order:l,orderBy:i,grouping:y,columnWidths:c},currentLayoutId:te,layoutIdToLoad:"",onPageChange:it,onRowsPerPageChange:lt,graphReportOpen:A,handleOpenGraphReport:jt,handleCloseGraphReport:Ut}};var zc=e=>jsx(di,{...e}),Oc=e=>jsx(Bo,{...e}),Gc=e=>jsx(Rn,{...e}),Wc=e=>jsx(xa,{...e}),$c=e=>jsx(Ca,{...e}),Dt=e=>{let{title:o="Data Table",showToolbar:t=true,selectionMode:r,selected:l=[],onSelectionChange:n,actions:i,extraTools:a,fitContainer:d=false,fullWidth:T=false,maxHeight:k,loading:w=false,page:C=0,rowsPerPage:E=20,rowsPerPageOptions:M=[20,50,100,-1],count:m=0,onPageChange:f,onRowsPerPageChange:S,onLayoutSave:y,filterConfig:g,rowKey:p,tableKey:I="default",graphReport:c}=e,{isMobile:u,columns:b,order:x,orderBy:s,filterText:R,setFilterText:v,visibleColumns:z,showSummary:L,setShowSummary:V,summaryColumns:A,grouping:N,setGrouping:te,expandedGroups:Oe,groupAnchorEl:oe,setGroupAnchorEl:re,summaryAnchorEl:ie,setSummaryAnchorEl:De,columnWidths:nt,anchorEl:at,setAnchorEl:Ge,contextMenu:Ft,sensors:Vt,sortedAndFilteredRows:We,summaryRow:rt,visibleRows:Nt,isAllExpanded:Ht,handleColumnResize:it,handleRequestSort:lt,handleSelectAllClick:zt,handleClick:st,toggleSummaryColumn:Ot,handleDragEnd:ct,handleExport:Gt,handleContextMenu:Wt,handleCloseContextMenu:$t,toggleColumnVisibility:dt,toggleGroupExpand:_t,toggleGroupField:jt,handleToggleAll:Ut,handleExpandGroupRecursively:h,handleCollapseGroupRecursively:D,handleLayoutLoad:B,handleVariantLoad:ee,handleLayoutSave:G,effectiveAppId:Y,currentLayoutData:q,currentLayoutId:$,layoutIdToLoad:U,graphReportOpen:fe,handleOpenGraphReport:se,handleCloseGraphReport:Be}=Mn(e),ce=c?.enabled??false,{model:Se}=en({rows:We,config:{...c,title:c?.title||`${o} Graphic Report`}}),$e=Se.table.columns.map(ut=>({id:ut.id,label:ut.label,align:ut.align||"left",minWidth:120,numeric:ut.align==="right"})),Gn=Y?jsx(wn,{appId:Y,tableKey:I,currentLayoutData:q,onLayoutLoad:B,targetLayoutId:U,activeLayoutId:$,serviceUrl:(g?.variantService,void 0)}):null,Co=jsxs(Fragment,{children:[jsx(_o,{groupAnchorEl:oe,setGroupAnchorEl:re,grouping:N,setGrouping:te,columns:b,toggleGroupField:jt}),jsx(jo,{anchorEl:at,setAnchorEl:Ge,columns:b,visibleColumns:z,toggleColumnVisibility:dt}),jsx(Uo,{anchorEl:ie,setAnchorEl:De,showSummary:L,setShowSummary:V,columns:b,summaryColumns:A,toggleSummaryColumn:Ot}),jsx(Ko,{contextMenu:Ft,handleCloseContextMenu:$t,columns:b,visibleColumns:z,toggleColumnVisibility:dt})]});return u?jsxs(bo,{sx:{display:"flex",flexDirection:"column",gap:2,height:"100%"},children:[g&&jsx(Xe,{fields:g.fields,filters:g.filters,onFilterChange:g.onFilterChange,onSearch:g.onSearch,variants:g.variants||[],currentVariantId:g.currentVariantId,onVariantLoad:g.onVariantLoad,onVariantSave:g.onVariantSave,onVariantDelete:g.onVariantDelete,onVariantSetDefault:g.onVariantSetDefault,appId:g.appId,tableKey:I,currentLayout:[{tableKey:I,layoutData:q}],variantService:g.variantService}),jsx(Wo,{title:o,loading:w,showSummary:L,setShowSummary:V,setAnchorEl:Ge,setSummaryAnchorEl:De,filterText:R,setFilterText:v,sortedAndFilteredRows:We,selected:l,columns:b,visibleColumns:z,summaryRow:rt,handleClick:st,selectionMode:r}),Co]}):jsxs(bo,{sx:{width:T?"100%":"auto",mb:d?0:2,...d?{flex:1,display:"flex",flexDirection:"column",minHeight:0,height:"100%"}:{}},children:[g&&jsx(bo,{sx:{mb:2},children:jsx(Xe,{fields:g.fields,filters:g.filters,onFilterChange:g.onFilterChange,onSearch:g.onSearch,variants:g.variants||[],currentVariantId:g.currentVariantId,onVariantLoad:ee,onVariantSave:g.onVariantSave,onVariantDelete:g.onVariantDelete,onVariantSetDefault:g.onVariantSetDefault,loading:w,appId:g.appId,tableKey:I,currentLayout:[{tableKey:I,layoutData:q}],currentLayoutId:$,layoutRefs:[{tableKey:I,layoutId:$}],variantService:g.variantService})}),jsxs(si,{sx:{width:T?"100%":"auto",mb:d?0:2,display:"flex",flexDirection:"column",overflow:"hidden",...k?{height:k}:d?{flex:1,minHeight:0}:{}},children:[t&&jsx(Lo,{filterText:R,setFilterText:v,onRowsPerPageChange:S,rowsPerPage:E,rowsPerPageOptions:M,page:C,count:m,onPageChange:f,actions:i,extraTools:a,grouping:N,setGroupAnchorEl:re,showSummary:L,setShowSummary:V,setAnchorEl:Ge,setSummaryAnchorEl:De,handleExport:Gt,onLayoutSave:y||g?.variantService&&g?.appId?G:void 0,loading:w,layoutManager:Gn,onOpenGraphReport:ce?se:void 0}),jsx(Rn,{sx:{flex:1,maxHeight:k||"calc(100vh - 320px)",overflowY:"auto",overflowX:"auto",position:"relative",minHeight:0},children:jsx(DndContext,{sensors:Vt,collisionDetection:closestCenter,onDragEnd:ct,modifiers:[restrictToHorizontalAxis],children:jsxs(ci,{sx:{minWidth:T?750:"auto",width:T?"100%":"auto",tableLayout:Object.keys(nt).length>0?"fixed":"auto",borderCollapse:"separate",borderSpacing:0},"aria-labelledby":"tableTitle",size:"small",stickyHeader:true,children:[jsx(Vo,{columns:b,visibleColumns:z,order:x,orderBy:s,onRequestSort:lt,onContextMenu:Wt,selectionMode:r,grouping:N,isAllExpanded:Ht,handleToggleAll:Ut,rowCount:We.length,numSelected:l.length,onSelectAllClick:zt,columnWidths:nt,onColumnResize:it}),jsx(Ho,{visibleRows:Nt,columns:b,visibleColumns:z,selectionMode:r,selected:l,orderBy:s,loading:w,expandedGroups:Oe,toggleGroupExpand:_t,handleExpandGroupRecursively:h,handleCollapseGroupRecursively:D,handleClick:st,onSelectionChange:n,grouping:N,rowKeyProp:p,page:C,rowsPerPage:E}),L&&jsx(Oo,{showSummary:L,columns:b,visibleColumns:z,summaryRow:rt,selectionMode:r?.toString(),orderBy:s,zIndex:3})]})})})]}),Co,ce&&jsx(Zo,{open:fe,onClose:Be,model:Se,tableContent:jsx(Dt,{title:"Data Body",columns:$e,rows:Se.table.rows,rowKey:"id",fullWidth:true,maxHeight:"420px",rowsPerPage:20,rowsPerPageOptions:[20,50,100],graphReport:{enabled:false}})})]})},_c=Dt;var Jc=({title:e,hideHeader:o=true,filterConfig:t,tableProps:r,children:l,spacing:n=1})=>jsxs(Po,{title:e,hideHeader:o,children:[jsxs(Stack,{spacing:n,sx:{height:"100%",overflow:"hidden"},children:[t&&jsx(Box,{sx:{flexShrink:0},children:jsx(Xe,{...t})}),jsx(Box,{sx:{flex:1,minHeight:0,overflow:"hidden"},children:jsx(Dt,{...r,fitContainer:true,filterConfig:void 0})})]}),l]});var td=({metadata:e,fetchData:o})=>{let[t,r]=useState(false),[l,n]=useState([]),[i,a]=useState({}),[d,T]=useState(e.variants||[]),[k,w]=useState(e.layout||null),[C,E]=useState(0),[M,m]=useState(0),[f,S]=useState(10),[y,g]=useState([]),[p,I]=useState("asc"),[c,u]=useState("");useEffect(()=>{let A={};e.filters.forEach(N=>{N.defaultValue!==void 0&&(A[N.id]=N.defaultValue);}),a(A);},[e.filters]);let b=useCallback(async(A,N,te,Oe,oe)=>{r(true);try{let re={...A,page:N+1,limit:te,sort:oe,order:Oe},ie;o?ie=await o(re):typeof e.api=="function"?ie=await e.api(re):e.api&&typeof e.api=="object"?(console.log("Fetching from URL:",e.api.url,re),ie={rows:[],total:0}):(console.warn("No API configured for report"),ie={rows:[],total:0}),ie&&(n(ie.rows||[]),E(ie.total||0));}catch(re){console.error("Failed to fetch report data",re);}finally{r(false);}},[e.api,o]);useEffect(()=>{b(i,M,f,p,c);},[b,M,f,p,c]);let x=()=>{m(0),b(i,0,f,p,c);},s=(A,N)=>{I(N),u(A);},R=A=>{a(A);},v=A=>{if(A.filters){let N=A.filters.find(te=>te.scope==="default"||te.scope===e.id);N&&(a(N.filters),b(N.filters,0,f));}A.layout&&w(A.layout);},z=A=>{let N={...A,id:Date.now().toString(),createdAt:new Date().toISOString()};T(te=>[...te,N]);},L=A=>{w(A);};return {pageProps:{title:e.title,filterConfig:{appId:e.id,fields:e.filters,filters:i,onFilterChange:R,onSearch:x,onVariantLoad:v,onVariantSave:z,onVariantDelete:A=>T(N=>N.filter(te=>te.id!==A)),onVariantSetDefault:A=>{T(N=>N.map(te=>({...te,isDefault:te.id===A})));},variants:d},tableProps:{appId:e.id,columns:e.columns,rows:l,loading:t,rowKey:"id",count:C,page:M,rowsPerPage:f,rowsPerPageOptions:[10,25,50,100],onPageChange:m,onRowsPerPageChange:S,selectionMode:"multiple",selected:y,onSelectionChange:g,onLayoutSave:L,layout:k,title:e.title,showSummary:true,order:p,orderBy:c,onSortChange:s,graphReport:e.graphReport||{enabled:true,title:`${e.title} Graphic Report`}}},filters:i,rows:l,loading:t,refresh:x}};var Nn=64,Ai="#E9EDF2",Fi="linear-gradient(90deg, #F5F7FA 0%, #E9EDF2 50%, #F5F7FA 100%)",Hn=({appTitle:e,logo:o,mode:t="dark",onToggleMode:r,localeLabel:l="EN",searchPlaceholder:n="Ask me...",onSearch:i,user:a,leftSlot:d,rightSlot:T})=>{let w=useTheme().palette.mode==="dark",[C,E]=useState(""),[M,m]=useState(null),f=p=>{p.preventDefault(),i&&i(C.trim());},S=t==="system"?jsx(Di,{fontSize:"small"}):t==="dark"?jsx(Pi,{fontSize:"small"}):jsx(Ei,{fontSize:"small"}),y=t==="system"?"Theme: System":t==="dark"?"Theme: Dark":"Theme: Light",g=!!M;return jsxs(AppBar,{position:"sticky",elevation:0,sx:p=>({top:0,zIndex:p.zIndex.drawer+10,height:Nn,backgroundColor:p.palette.mode==="dark"?"#0D0D0D":Ai,backgroundImage:p.palette.mode==="dark"?["radial-gradient(circle at 18% 22%, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0) 45%)","radial-gradient(circle at 78% 32%, rgba(144,202,249,0.14) 0%, rgba(144,202,249,0) 42%)","linear-gradient(90deg, #0A0A0A 0%, #151515 50%, #0A0A0A 100%)","linear-gradient(rgba(255,255,255,0.04) 1px, transparent 1px)","linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px)"].join(","):["radial-gradient(circle at 22% 22%, rgba(255,255,255,0.7) 0%, rgba(255,255,255,0) 48%)","radial-gradient(circle at 76% 24%, rgba(203,213,225,0.45) 0%, rgba(203,213,225,0) 42%)",Fi,"linear-gradient(rgba(15,23,42,0.05) 1px, transparent 1px)","linear-gradient(90deg, rgba(15,23,42,0.04) 1px, transparent 1px)"].join(","),backgroundSize:"auto, auto, auto, 24px 24px, 24px 24px",borderBottom:"1px solid",borderColor:p.palette.mode==="dark"?"rgba(255,255,255,0.12)":"rgba(15,23,42,0.12)"}),children:[jsxs(Toolbar,{sx:{minHeight:`${Nn}px !important`,px:2,gap:2},children:[jsxs(Stack,{direction:"row",alignItems:"center",spacing:1.5,sx:{minWidth:220},children:[o||jsx(Box,{component:"img",src:"/orbcafe.png",alt:"ORBCAFE Logo",sx:{width:44,height:44,display:"block",objectFit:"contain",flexShrink:0}}),e&&jsx(Typography,{variant:"h6",sx:{fontWeight:700,color:w?"common.white":"#111827"},children:e}),d]}),jsx(Box,{sx:{flex:1,display:"flex",justifyContent:"center",minWidth:0},children:jsx(Box,{component:"form",onSubmit:f,sx:{width:"100%",maxWidth:540},children:jsx(TextField,{size:"small",fullWidth:true,value:C,onChange:p=>E(p.target.value),placeholder:n,InputProps:{startAdornment:jsx(InputAdornment,{position:"start",children:jsx(mn,{sx:{color:w?"rgba(255,255,255,0.7)":"rgba(15,23,42,0.55)",fontSize:18}})}),sx:{color:w?"common.white":"rgba(17,24,39,0.9)",bgcolor:w?"rgba(255,255,255,0.08)":"#ffffff",borderRadius:999,"& .MuiOutlinedInput-notchedOutline":{borderColor:w?"rgba(255,255,255,0.15)":"rgba(15,23,42,0.2)"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:w?"rgba(255,255,255,0.35)":"rgba(15,23,42,0.35)"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:w?"rgba(255,255,255,0.5)":"rgba(15,23,42,0.55)"}}},inputProps:{style:{color:w?"white":"#111827"}}})})}),jsxs(Stack,{direction:"row",alignItems:"center",spacing:1.5,children:[jsxs(Stack,{direction:"row",alignItems:"center",spacing:.5,children:[jsx(Ri,{sx:{color:w?"common.white":"#111827",fontSize:18}}),jsx(Typography,{variant:"caption",sx:{color:w?"common.white":"#111827",fontWeight:500},children:l})]}),jsx(IconButton,{size:"small",sx:{color:w?"common.white":"#111827"},onClick:r,title:y,children:S}),a&&jsxs(Stack,{direction:"row",alignItems:"center",spacing:1,children:[jsxs(Box,{sx:{textAlign:"right",minWidth:0},children:[jsx(Typography,{variant:"body2",sx:{color:w?"common.white":"#111827",fontWeight:700,lineHeight:1.15},children:a.name}),a.subtitle&&jsx(Typography,{variant:"caption",sx:{display:"block",mt:.25,color:w?"rgba(255,255,255,0.72)":"rgba(17,24,39,0.62)",fontSize:"0.72rem",lineHeight:1.1,letterSpacing:"0.01em",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:220},title:a.subtitle,children:a.subtitle})]}),jsx(IconButton,{size:"small",onClick:p=>m(p.currentTarget),sx:{p:0},children:jsx(Avatar,{src:a.avatarSrc,imgProps:{style:{objectFit:"cover"}},sx:{width:34,height:34,bgcolor:"grey.100",color:"grey.700",fontSize:"0.85rem"},children:a.avatarText||a.name.slice(0,1).toUpperCase()})})]}),T]})]}),jsxs(Menu,{anchorEl:M,open:g,onClose:()=>m(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},slotProps:{paper:{sx:{minWidth:160,"& .MuiMenuItem-root":{minHeight:34,py:.5,px:1.25}}}},children:[jsxs(MenuItem,{onClick:()=>m(null),children:[jsx(ListItemIcon,{children:jsx(zr,{sx:{fontSize:18}})}),jsx(ListItemText,{primary:"Setting",slotProps:{primary:{sx:{fontSize:"0.86rem",fontWeight:500}}}})]}),jsxs(MenuItem,{onClick:()=>m(null),children:[jsx(ListItemIcon,{children:jsx(Bi,{sx:{fontSize:18}})}),jsx(ListItemText,{primary:"Logout",slotProps:{primary:{sx:{fontSize:"0.86rem",fontWeight:500}}}})]})]})]})};var zn=({menuData:e=[],initialNavigationCollapsed:o=false}={})=>{let{navigationIslandProps:t}=Do({initialCollapsed:o,content:e}),[r,l]=useState(900);useEffect(()=>{let i=()=>l(window.innerHeight);return i(),window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)},[]);let n=useMemo(()=>Math.max(280,r-100),[r]);return {navigationIslandProps:t,navigationMaxHeight:n}};var Td=({appTitle:e,menuData:o=[],children:t,showNavigation:r=true,localeLabel:l,user:n,logo:i,onSearch:a,rightHeaderSlot:d,leftHeaderSlot:T,contentSx:k})=>{let[w,C]=useState("system"),[E,M]=useState("light"),[m,f]=useState(false),S=w==="system"?m?E:"light":w;useEffect(()=>{f(true);let I=window.matchMedia("(prefers-color-scheme: dark)"),c=()=>{M(I.matches?"dark":"light");};return c(),I.addEventListener("change",c),()=>I.removeEventListener("change",c)},[]);let y=useMemo(()=>createTheme({palette:{mode:S}}),[S]),{navigationIslandProps:g,navigationMaxHeight:p}=zn({menuData:o,initialNavigationCollapsed:false});return jsx(ThemeProvider,{theme:y,children:jsxs(Box,{sx:I=>({minHeight:"100vh",display:"flex",flexDirection:"column",background:I.palette.mode==="dark"?"linear-gradient(180deg, #0A0A0A 0%, #141414 55%, #1A1A1A 100%)":I.palette.background.default}),children:[jsx(Hn,{appTitle:e,logo:i,mode:w,onToggleMode:()=>C(I=>I==="system"?"dark":I==="dark"?"light":"system"),localeLabel:l,user:n,onSearch:a,leftSlot:T,rightSlot:d}),jsxs(Box,{sx:{flex:1,minHeight:0,display:"flex"},children:[r&&jsx(Box,{sx:{p:1.5,display:"flex",alignItems:"flex-start",flexShrink:0},children:jsx(Mo,{...g,maxHeight:p,colorMode:S})}),jsx(Box,{sx:{flex:1,minWidth:0,minHeight:0,overflow:"auto",p:1.5,...k},children:t})]})]})})};export{Yt as Button,Hn as CAppHeader,Td as CAppPageLayout,Sn as CLayoutManagement,wn as CLayoutManager,Po as CPageLayout,Xe as CSmartFilter,_c as CSmartTable,Jc as CStandardPage,Dt as CTable,zc as CTableBody,Oc as CTableCell,Gc as CTableContainer,Wc as CTableHead,$c as CTableRow,vt as CVariantManagement,sn as CVariantManager,Mo as NavigationIsland,Xt as TreeMenu,Un as buttonVariants,Do as useNavigationIsland,zn as usePageLayout,td as useStandardReport};
|