orbcafe-ui 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as React$1 from 'react';
2
- import React__default, { Dispatch, SetStateAction } from 'react';
2
+ import React__default, { Dispatch, SetStateAction, ReactNode } from 'react';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import * as class_variance_authority_types from 'class-variance-authority/types';
5
5
  import { VariantProps } from 'class-variance-authority';
6
+ import { SxProps, Theme } from '@mui/material/styles';
6
7
 
7
8
  interface TreeMenuItem {
8
9
  id: string;
@@ -23,8 +24,9 @@ interface TreeMenuProps {
23
24
  level?: number;
24
25
  expandedIds?: Set<string>;
25
26
  onToggleExpand?: (id: string) => void;
27
+ colorMode?: 'light' | 'dark';
26
28
  }
27
- declare function TreeMenu({ items, onItemClick, className, level, expandedIds, onToggleExpand }: TreeMenuProps): react_jsx_runtime.JSX.Element;
29
+ declare function TreeMenu({ items, onItemClick, className, level, expandedIds, onToggleExpand, colorMode, }: TreeMenuProps): react_jsx_runtime.JSX.Element;
28
30
 
29
31
  /**
30
32
  * @file 10_Frontend/components/ui/molecules/navigation-island.tsx
@@ -54,6 +56,7 @@ interface NavigationIslandProps {
54
56
  className?: string;
55
57
  maxHeight?: number;
56
58
  menuData?: TreeMenuItem[];
59
+ colorMode?: 'light' | 'dark';
57
60
  }
58
61
  declare const NavigationIsland: React__default.FC<NavigationIslandProps>;
59
62
 
@@ -517,4 +520,49 @@ declare const useStandardReport: ({ metadata, fetchData }: UseStandardReportOpti
517
520
  refresh: () => void;
518
521
  };
519
522
 
520
- export { Button, type ButtonProps, CLayoutManagement, type CLayoutManagementProps, CLayoutManager, type CLayoutManagerProps, CPageLayout, type CPageLayoutProps, CSmartFilter, type CSmartFilterProps, CSmartTable, CStandardPage, type CStandardPageProps, CTable, CTableBody, type CTableBodyProps, CTableCell, type CTableCellProps, CTableContainer, type CTableContainerProps, CTableHead, type CTableHeadProps, type CTableProps, CTableRow, type CTableRowProps, CVariantManagement, type CVariantManagementProps, CVariantManager, type DateOperator, type FilterField, type FilterOperator, type FilterType, type FilterValue, type IVariantService, type LayoutMetadata, NavigationIsland, type NavigationIslandProps, type NumberOperator, type ReportColumn, type ReportFilter, type ReportMetadata, type SelectOperator, type TextOperator, TreeMenu, type TreeMenuItem, type UseNavigationIslandOptions, type UseNavigationIslandResult, type UseStandardReportOptions, type VariantMetadata, buttonVariants, useNavigationIsland, useStandardReport };
523
+ interface CAppHeaderUser {
524
+ name: string;
525
+ subtitle?: string;
526
+ avatarText?: string;
527
+ avatarSrc?: string;
528
+ }
529
+ interface CAppHeaderProps {
530
+ appTitle: string;
531
+ logo?: ReactNode;
532
+ mode?: 'light' | 'dark' | 'system';
533
+ onToggleMode?: () => void;
534
+ localeLabel?: string;
535
+ searchPlaceholder?: string;
536
+ onSearch?: (query: string) => void;
537
+ user?: CAppHeaderUser;
538
+ leftSlot?: ReactNode;
539
+ rightSlot?: ReactNode;
540
+ }
541
+ interface CAppPageLayoutProps {
542
+ appTitle: string;
543
+ menuData?: TreeMenuItem[];
544
+ children: ReactNode;
545
+ showNavigation?: boolean;
546
+ localeLabel?: string;
547
+ user?: CAppHeaderUser;
548
+ logo?: ReactNode;
549
+ onSearch?: (query: string) => void;
550
+ rightHeaderSlot?: ReactNode;
551
+ leftHeaderSlot?: ReactNode;
552
+ contentSx?: SxProps<Theme>;
553
+ }
554
+
555
+ declare const CAppPageLayout: ({ appTitle, menuData, children, showNavigation, localeLabel, user, logo, onSearch, rightHeaderSlot, leftHeaderSlot, contentSx, }: CAppPageLayoutProps) => react_jsx_runtime.JSX.Element;
556
+
557
+ declare const CAppHeader: ({ appTitle, logo, mode, onToggleMode, localeLabel, searchPlaceholder, onSearch, user, leftSlot, rightSlot, }: CAppHeaderProps) => react_jsx_runtime.JSX.Element;
558
+
559
+ interface UsePageLayoutOptions {
560
+ menuData?: TreeMenuItem[];
561
+ initialNavigationCollapsed?: boolean;
562
+ }
563
+ declare const usePageLayout: ({ menuData, initialNavigationCollapsed, }?: UsePageLayoutOptions) => {
564
+ navigationIslandProps: Pick<NavigationIslandProps, "onToggle" | "collapsed" | "menuData">;
565
+ navigationMaxHeight: number;
566
+ };
567
+
568
+ export { Button, type ButtonProps, CAppHeader, type CAppHeaderProps, type CAppHeaderUser, CAppPageLayout, type CAppPageLayoutProps, CLayoutManagement, type CLayoutManagementProps, CLayoutManager, type CLayoutManagerProps, CPageLayout, type CPageLayoutProps, CSmartFilter, type CSmartFilterProps, CSmartTable, CStandardPage, type CStandardPageProps, CTable, CTableBody, type CTableBodyProps, CTableCell, type CTableCellProps, CTableContainer, type CTableContainerProps, CTableHead, type CTableHeadProps, type CTableProps, CTableRow, type CTableRowProps, CVariantManagement, type CVariantManagementProps, CVariantManager, type DateOperator, type FilterField, type FilterOperator, type FilterType, type FilterValue, type IVariantService, type LayoutMetadata, NavigationIsland, type NavigationIslandProps, type NumberOperator, type ReportColumn, type ReportFilter, type ReportMetadata, type SelectOperator, type TextOperator, TreeMenu, type TreeMenuItem, type UseNavigationIslandOptions, type UseNavigationIslandResult, type UsePageLayoutOptions, type UseStandardReportOptions, type VariantMetadata, buttonVariants, useNavigationIsland, usePageLayout, useStandardReport };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as React$1 from 'react';
2
- import React__default, { Dispatch, SetStateAction } from 'react';
2
+ import React__default, { Dispatch, SetStateAction, ReactNode } from 'react';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import * as class_variance_authority_types from 'class-variance-authority/types';
5
5
  import { VariantProps } from 'class-variance-authority';
6
+ import { SxProps, Theme } from '@mui/material/styles';
6
7
 
7
8
  interface TreeMenuItem {
8
9
  id: string;
@@ -23,8 +24,9 @@ interface TreeMenuProps {
23
24
  level?: number;
24
25
  expandedIds?: Set<string>;
25
26
  onToggleExpand?: (id: string) => void;
27
+ colorMode?: 'light' | 'dark';
26
28
  }
27
- declare function TreeMenu({ items, onItemClick, className, level, expandedIds, onToggleExpand }: TreeMenuProps): react_jsx_runtime.JSX.Element;
29
+ declare function TreeMenu({ items, onItemClick, className, level, expandedIds, onToggleExpand, colorMode, }: TreeMenuProps): react_jsx_runtime.JSX.Element;
28
30
 
29
31
  /**
30
32
  * @file 10_Frontend/components/ui/molecules/navigation-island.tsx
@@ -54,6 +56,7 @@ interface NavigationIslandProps {
54
56
  className?: string;
55
57
  maxHeight?: number;
56
58
  menuData?: TreeMenuItem[];
59
+ colorMode?: 'light' | 'dark';
57
60
  }
58
61
  declare const NavigationIsland: React__default.FC<NavigationIslandProps>;
59
62
 
@@ -517,4 +520,49 @@ declare const useStandardReport: ({ metadata, fetchData }: UseStandardReportOpti
517
520
  refresh: () => void;
518
521
  };
519
522
 
520
- export { Button, type ButtonProps, CLayoutManagement, type CLayoutManagementProps, CLayoutManager, type CLayoutManagerProps, CPageLayout, type CPageLayoutProps, CSmartFilter, type CSmartFilterProps, CSmartTable, CStandardPage, type CStandardPageProps, CTable, CTableBody, type CTableBodyProps, CTableCell, type CTableCellProps, CTableContainer, type CTableContainerProps, CTableHead, type CTableHeadProps, type CTableProps, CTableRow, type CTableRowProps, CVariantManagement, type CVariantManagementProps, CVariantManager, type DateOperator, type FilterField, type FilterOperator, type FilterType, type FilterValue, type IVariantService, type LayoutMetadata, NavigationIsland, type NavigationIslandProps, type NumberOperator, type ReportColumn, type ReportFilter, type ReportMetadata, type SelectOperator, type TextOperator, TreeMenu, type TreeMenuItem, type UseNavigationIslandOptions, type UseNavigationIslandResult, type UseStandardReportOptions, type VariantMetadata, buttonVariants, useNavigationIsland, useStandardReport };
523
+ interface CAppHeaderUser {
524
+ name: string;
525
+ subtitle?: string;
526
+ avatarText?: string;
527
+ avatarSrc?: string;
528
+ }
529
+ interface CAppHeaderProps {
530
+ appTitle: string;
531
+ logo?: ReactNode;
532
+ mode?: 'light' | 'dark' | 'system';
533
+ onToggleMode?: () => void;
534
+ localeLabel?: string;
535
+ searchPlaceholder?: string;
536
+ onSearch?: (query: string) => void;
537
+ user?: CAppHeaderUser;
538
+ leftSlot?: ReactNode;
539
+ rightSlot?: ReactNode;
540
+ }
541
+ interface CAppPageLayoutProps {
542
+ appTitle: string;
543
+ menuData?: TreeMenuItem[];
544
+ children: ReactNode;
545
+ showNavigation?: boolean;
546
+ localeLabel?: string;
547
+ user?: CAppHeaderUser;
548
+ logo?: ReactNode;
549
+ onSearch?: (query: string) => void;
550
+ rightHeaderSlot?: ReactNode;
551
+ leftHeaderSlot?: ReactNode;
552
+ contentSx?: SxProps<Theme>;
553
+ }
554
+
555
+ declare const CAppPageLayout: ({ appTitle, menuData, children, showNavigation, localeLabel, user, logo, onSearch, rightHeaderSlot, leftHeaderSlot, contentSx, }: CAppPageLayoutProps) => react_jsx_runtime.JSX.Element;
556
+
557
+ declare const CAppHeader: ({ appTitle, logo, mode, onToggleMode, localeLabel, searchPlaceholder, onSearch, user, leftSlot, rightSlot, }: CAppHeaderProps) => react_jsx_runtime.JSX.Element;
558
+
559
+ interface UsePageLayoutOptions {
560
+ menuData?: TreeMenuItem[];
561
+ initialNavigationCollapsed?: boolean;
562
+ }
563
+ declare const usePageLayout: ({ menuData, initialNavigationCollapsed, }?: UsePageLayoutOptions) => {
564
+ navigationIslandProps: Pick<NavigationIslandProps, "onToggle" | "collapsed" | "menuData">;
565
+ navigationMaxHeight: number;
566
+ };
567
+
568
+ export { Button, type ButtonProps, CAppHeader, type CAppHeaderProps, type CAppHeaderUser, CAppPageLayout, type CAppPageLayoutProps, CLayoutManagement, type CLayoutManagementProps, CLayoutManager, type CLayoutManagerProps, CPageLayout, type CPageLayoutProps, CSmartFilter, type CSmartFilterProps, CSmartTable, CStandardPage, type CStandardPageProps, CTable, CTableBody, type CTableBodyProps, CTableCell, type CTableCellProps, CTableContainer, type CTableContainerProps, CTableHead, type CTableHeadProps, type CTableProps, CTableRow, type CTableRowProps, CVariantManagement, type CVariantManagementProps, CVariantManager, type DateOperator, type FilterField, type FilterOperator, type FilterType, type FilterValue, type IVariantService, type LayoutMetadata, NavigationIsland, type NavigationIslandProps, type NumberOperator, type ReportColumn, type ReportFilter, type ReportMetadata, type SelectOperator, type TextOperator, TreeMenu, type TreeMenuItem, type UseNavigationIslandOptions, type UseNavigationIslandResult, type UsePageLayoutOptions, type UseStandardReportOptions, type VariantMetadata, buttonVariants, useNavigationIsland, usePageLayout, useStandardReport };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- 'use strict';var co=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'),io=require('@mui/material/Box'),Wr=require('@mui/material/Paper'),$r=require('@mui/material/Table'),jr=require('@mui/material/TableBody'),xo=require('@mui/material/TableCell'),fn=require('@mui/material/TableContainer'),Zn=require('@mui/material/TableHead'),Qn=require('@mui/material/TableRow'),core=require('@dnd-kit/core'),modifiers=require('@dnd-kit/modifiers'),Zo=require('@mui/icons-material/Search'),$n=require('@mui/icons-material/ViewColumn'),ln=require('@mui/icons-material/Save'),_n=require('@mui/icons-material/Download'),Un=require('@mui/icons-material/AccountTree'),Kn=require('@mui/icons-material/Functions'),Yn=require('@mui/icons-material/Insights'),ea=require('@mui/material/Checkbox'),ta=require('@mui/material/TableSortLabel'),ia=require('@mui/icons-material/KeyboardArrowRight'),la=require('@mui/icons-material/KeyboardArrowDown'),xa=require('@mui/icons-material/Check'),Ca=require('@mui/icons-material/ClearAll'),Ba=require('@mui/icons-material/Close'),br=require('@mui/icons-material/Settings'),xr=require('@mui/icons-material/KeyboardArrowUp'),vr=require('@mui/icons-material/ArrowRightAlt'),_a=require('@mui/icons-material/Star'),DateCalendar=require('@mui/x-date-pickers/DateCalendar'),PickersDay=require('@mui/x-date-pickers/PickersDay'),ir=require('@mui/icons-material/CalendarMonth'),lr=require('@mui/icons-material/Clear'),sr=require('@mui/icons-material/ArrowForward'),Me=require('dayjs'),cr=require('dayjs/plugin/isBetween'),Lr=require('@mui/icons-material/Delete'),Vr=require('@mui/icons-material/StarBorder'),Fr=require('@mui/icons-material/ViewQuilt');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 co__namespace=/*#__PURE__*/_interopNamespace(co);var io__default=/*#__PURE__*/_interopDefault(io);var Wr__default=/*#__PURE__*/_interopDefault(Wr);var $r__default=/*#__PURE__*/_interopDefault($r);var jr__default=/*#__PURE__*/_interopDefault(jr);var xo__default=/*#__PURE__*/_interopDefault(xo);var fn__default=/*#__PURE__*/_interopDefault(fn);var Zn__default=/*#__PURE__*/_interopDefault(Zn);var Qn__default=/*#__PURE__*/_interopDefault(Qn);var Zo__default=/*#__PURE__*/_interopDefault(Zo);var $n__default=/*#__PURE__*/_interopDefault($n);var ln__default=/*#__PURE__*/_interopDefault(ln);var _n__default=/*#__PURE__*/_interopDefault(_n);var Un__default=/*#__PURE__*/_interopDefault(Un);var Kn__default=/*#__PURE__*/_interopDefault(Kn);var Yn__default=/*#__PURE__*/_interopDefault(Yn);var ea__default=/*#__PURE__*/_interopDefault(ea);var ta__default=/*#__PURE__*/_interopDefault(ta);var ia__default=/*#__PURE__*/_interopDefault(ia);var la__default=/*#__PURE__*/_interopDefault(la);var xa__default=/*#__PURE__*/_interopDefault(xa);var Ca__default=/*#__PURE__*/_interopDefault(Ca);var Ba__default=/*#__PURE__*/_interopDefault(Ba);var br__default=/*#__PURE__*/_interopDefault(br);var xr__default=/*#__PURE__*/_interopDefault(xr);var vr__default=/*#__PURE__*/_interopDefault(vr);var _a__default=/*#__PURE__*/_interopDefault(_a);var ir__default=/*#__PURE__*/_interopDefault(ir);var lr__default=/*#__PURE__*/_interopDefault(lr);var sr__default=/*#__PURE__*/_interopDefault(sr);var Me__default=/*#__PURE__*/_interopDefault(Me);var cr__default=/*#__PURE__*/_interopDefault(cr);var Lr__default=/*#__PURE__*/_interopDefault(Lr);var Vr__default=/*#__PURE__*/_interopDefault(Vr);var Fr__default=/*#__PURE__*/_interopDefault(Fr);function le(...e){return tailwindMerge.twMerge(clsx.clsx(e))}var Nt={primary:"#000000",primaryHover:"#333333"},lt={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"},We={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",full:"rounded-full"},so=()=>"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 wn=classVarianceAuthority.cva(so(),{variants:{variant:{default:`${lt.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:`${lt.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:lt.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-[${Nt.primary}] hover:bg-[${Nt.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:We.none,sm:We.sm,md:We.md,full:We.full}},defaultVariants:{variant:"default",size:"default",rounded:"md"}}),Gt=co__namespace.forwardRef(({className:e,variant:o,size:t,asChild:r=false,...c},n)=>jsxRuntime.jsx(r?reactSlot.Slot:"button",{className:le(wn({variant:o,size:t,className:e})),ref:n,...c}));Gt.displayName="Button";function zt({items:e,onItemClick:o,className:t="",level:r=0,expandedIds:c,onToggleExpand:n}){let i=navigation.usePathname(),[l,m]=co.useState(new Set),v=c!==void 0&&n!==void 0,w=v?c:l,D=x=>{if(v)n(x);else {let p=new Set(l);p.has(x)?p.delete(x):p.add(x),m(p);}},b=x=>{x.children&&x.children.length>0&&D(x.id),o&&o(x);};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(x=>{let p=w.has(x.id)||x.isExpanded,f=x.children&&x.children.length>0,k=x.appurl||x.href,T=k?i===k:false;return jsxRuntime.jsxs("div",{className:"tree-menu-item relative",children:[T&&jsxRuntime.jsx("div",{className:"absolute left-0 top-2 bottom-2 w-1 bg-blue-500 rounded-r-full z-10"}),jsxRuntime.jsxs(Gt,{variant:"ghost",className:le("w-full justify-start gap-2 h-auto py-2 relative overflow-hidden group",`ml-${r*4}`,T?"bg-blue-50/80 dark:bg-blue-900/20 text-blue-600 dark:text-blue-400 hover:bg-blue-100/80 dark:hover:bg-blue-900/30":"hover:bg-gray-100/50 dark:hover:bg-gray-800/50 text-gray-700 dark:text-gray-300"),onClick:()=>b(x),children:[f&&jsxRuntime.jsx("div",{className:le("flex-shrink-0 transition-transform duration-200",p&&"rotate-90",T?"text-blue-500":"text-gray-400 group-hover:text-gray-600 dark:text-gray-500 dark:group-hover:text-gray-300"),children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-4 w-4"})}),!f&&jsxRuntime.jsx("div",{className:"w-4 h-4 flex-shrink-0"}),x.icon&&jsxRuntime.jsx("div",{className:le("flex-shrink-0 transition-colors duration-200",T?"text-blue-500":"text-gray-400 group-hover:text-gray-600 dark:text-gray-500 dark:group-hover:text-gray-300"),children:x.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",T?"font-semibold":"font-medium"),children:x.title||x.label}),x.description&&jsxRuntime.jsx("div",{className:le("text-xs truncate transition-colors duration-200",T?"text-blue-400/80 dark:text-blue-300/60":"text-gray-500 dark:text-gray-400"),title:x.description,children:x.description})]})]}),f&&jsxRuntime.jsx("div",{className:le("grid transition-[grid-template-rows] duration-300 ease-in-out",p?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:jsxRuntime.jsx("div",{className:"overflow-hidden",children:jsxRuntime.jsx(zt,{items:x.children,onItemClick:o,level:r+1,expandedIds:c,onToggleExpand:n})})})]},x.id)})})}var wi=({collapsed:e,onToggle:o,className:t="",maxHeight:r,menuData:c=[]})=>{let n=navigation.useRouter(),[i,l]=co.useState(""),[m,v]=co.useState(new Set);co.useEffect(()=>{e&&v(new Set);},[e]);let w=co.useCallback(p=>{let f=[],k=T=>{T.forEach(d=>{f.push(d.id),d.children&&k(d.children);});};return k(p),f},[]),D=co.useMemo(()=>{if(!i.trim())return c;let p=f=>f.reduce((k,T)=>{let d=T.title?.toLowerCase().includes(i.toLowerCase())||T.description?.toLowerCase().includes(i.toLowerCase()),L=T.children?p(T.children):[];return (d||L.length>0)&&k.push({...T,children:L.length>0?L:T.children}),k},[]);return p(c)},[i,c]),b=co.useMemo(()=>i.trim()?new Set(w(c)):m,[i,c,m,w]),x=co.useCallback(async p=>{if(console.log("\u{1F5B1}\uFE0F \u5BFC\u822A\u83DC\u5355\u9879\u70B9\u51FB:",p),p.id==="chat"||p.appurl==="/chat"){console.log("\u{1F4AC} \u68C0\u6D4B\u5230chat\u83DC\u5355\u70B9\u51FB\uFF0C\u8DF3\u8F6C\u5230\u65B0\u7684\u804A\u5929\u89C6\u56FE");try{n.push("/chat?new=true");}catch(k){console.error("\u274C \u65E0\u6CD5\u8DF3\u8F6C\u5230\u65B0\u804A\u5929\u89C6\u56FE:",k),n.push("/chat");}return}let f=p.appurl||p.href;f&&(f.startsWith("http://")||f.startsWith("https://")?window.open(f,"_blank"):n.push(f));},[n]);return jsxRuntime.jsxs("div",{className:`flex flex-col bg-white/10 dark:bg-[#101928] backdrop-blur-xl border border-white/20 dark:border-white/10 shadow-[0_4px_8px_0_rgba(31,38,135,0.1)] ${e?"w-14 rounded-full":"w-[234px] rounded-2xl"} relative ${t}`,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 text-gray-500 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors duration-200",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:i,onChange:p=>l(p.target.value),className:"w-full pl-10 pr-4 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white placeholder-gray-500 dark:placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"}),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 text-gray-400 dark:text-gray-500"})})]})}),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:D.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-gray-500 text-sm",children:e?"\u{1F4C2}":i?"\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(zt,{items:D,onItemClick:x,className:"space-y-1",expandedIds:b,onToggleExpand:p=>{let f=new Set(m);D.some(T=>T.id===p)?f.has(p)?f.delete(p):(D.forEach(T=>{T.id!==p&&f.has(T.id)&&f.delete(T.id);}),f.add(p)):f.has(p)?f.delete(p):f.add(p),v(f);}})}),e&&jsxRuntime.jsx("div",{className:"space-y-2",children:c.map(p=>jsxRuntime.jsx("div",{className:"space-y-1",children:jsxRuntime.jsx("button",{onClick:()=>{o();let f=new Set([p.id]);v(f);},className:"w-full flex items-center justify-center p-2 rounded-lg text-gray-600 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-gray-800 cursor-pointer transition-colors duration-200",title:`\u5C55\u5F00\u67E5\u770B ${p.title}`,children:p.icon||jsxRuntime.jsx("div",{className:"w-6 h-6 bg-blue-100 dark:bg-blue-900/20 rounded text-xs flex items-center justify-center font-medium text-blue-600 dark:text-blue-400",children:p.title?.charAt(0)||"?"})})},p.id))})]})}),!e&&jsxRuntime.jsx("button",{onClick:o,className:"absolute -bottom-1 -right-1 w-6 h-6 bg-transparent hover:bg-white/20 dark:hover:bg-gray-800/50 rounded-full flex items-center justify-center transition-all duration-300 ease-in-out z-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:"dark:border-yellow-400",style:{width:"32px",height:"32px",borderRadius:"16px",border:"3px solid #21BCFF",backgroundColor:"transparent",position:"absolute",top:"-16px",left:"-16px"}})})})]})};var Mi=(e={})=>{let{initialCollapsed:o=false,content:t=[]}=e,[r,c]=co.useState(o),[n,i]=co.useState(t),l=co.useCallback(()=>{c(v=>!v);},[]),m=co.useMemo(()=>({collapsed:r,onToggle:l,menuData:n}),[r,l,n]);return {collapsed:r,setCollapsed:c,toggleCollapsed:l,menuData:n,setMenuData:i,navigationIslandProps:m}};var yo=({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 bo=e=>{let o="0.75rem";return jsxRuntime.jsxs(material.Toolbar,{sx:{pl:{sm:2},pr:{xs:1,sm:1},alignItems:"center"},children:[jsxRuntime.jsx(material.Typography,{sx:{flex:"1 1 100%",fontWeight:"bold"},variant:"h6",id:"tableTitle",component:"div",children:e.title||"Table"}),jsxRuntime.jsxs(material.Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsxRuntime.jsx(material.TextField,{size:"small",placeholder:"Search...",value:e.filterText,onChange:t=>e.setFilterText(t.target.value),InputProps:{sx:{fontSize:o,"& .MuiInputBase-input":{fontSize:o},"& .MuiInputBase-input::placeholder":{fontSize:o,opacity:1}},startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(Zo__default.default,{fontSize:"small"})})},sx:{width:300}}),jsxRuntime.jsx(material.Tooltip,{title:"Group By",children:jsxRuntime.jsx(material.IconButton,{onClick:t=>e.setGroupAnchorEl(t.currentTarget),children:jsxRuntime.jsx(material.Badge,{badgeContent:e.grouping?.length,color:"primary",children:jsxRuntime.jsx(Un__default.default,{})})})}),jsxRuntime.jsx(material.Tooltip,{title:"Summary",children:jsxRuntime.jsx(material.IconButton,{onClick:t=>e.setSummaryAnchorEl(t.currentTarget),color:e.showSummary?"primary":"default",children:jsxRuntime.jsx(Kn__default.default,{})})}),jsxRuntime.jsx(material.Tooltip,{title:"Columns",children:jsxRuntime.jsx(material.IconButton,{onClick:t=>e.setAnchorEl(t.currentTarget),children:jsxRuntime.jsx($n__default.default,{})})}),jsxRuntime.jsx(material.Tooltip,{title:"Export",children:jsxRuntime.jsx(material.IconButton,{onClick:e.handleExport,children:jsxRuntime.jsx(_n__default.default,{})})}),e.onOpenGraphReport&&jsxRuntime.jsx(material.Tooltip,{title:"Graphic Report",children:jsxRuntime.jsx(material.IconButton,{onClick:e.onOpenGraphReport,children:jsxRuntime.jsx(Yn__default.default,{})})}),e.onLayoutSave&&!e.layoutManager&&jsxRuntime.jsx(material.Tooltip,{title:"Save Layout",children:jsxRuntime.jsx(material.IconButton,{onClick:t=>e.onLayoutSave(t),children:jsxRuntime.jsx(ln__default.default,{})})}),e.layoutManager]})]})};var So=e=>{let{onSelectAllClick:o,order:t,orderBy:r,numSelected:c=0,rowCount:n=0,onRequestSort:i,columns:l,visibleColumns:m,selectionMode:v,onColumnResize:w,columnWidths:D}=e,[b,x]=co.useState(null),p=co.useRef(null),f=a=>S=>{b||i(a);},k=(a,S,s)=>{a.preventDefault(),a.stopPropagation(),x(S),p.current={startX:a.clientX,startWidth:s,colId:S},document.addEventListener("mousemove",T),document.addEventListener("mouseup",d),document.body.style.cursor="col-resize";},T=a=>{if(!p.current)return;let{startX:S,startWidth:s,colId:h}=p.current,I=a.clientX-S,C=Math.max(50,s+I);w&&w(h,C);},d=()=>{x(null),p.current=null,document.removeEventListener("mousemove",T),document.removeEventListener("mouseup",d),document.body.style.cursor="";};return co.useEffect(()=>()=>{document.removeEventListener("mousemove",T),document.removeEventListener("mouseup",d);},[]),jsxRuntime.jsx(Zn__default.default,{children:jsxRuntime.jsxs(Qn__default.default,{children:[(v==="multiple"||v==="single")&&jsxRuntime.jsx(xo__default.default,{padding:"checkbox",sx:a=>({width:48,backgroundColor:a.palette.mode==="dark"?"#000000":"#f5f5f5",color:a.palette.mode==="dark"?"#ffffff":a.palette.text.primary}),children:jsxRuntime.jsx(ea__default.default,{color:"primary",indeterminate:c>0&&c<n,checked:n>0&&c===n,onChange:o,disabled:v==="single"})}),l.filter(a=>m.includes(a.id)).map(a=>{let S=D?.[a.id]||a.minWidth||100;return jsxRuntime.jsxs(xo__default.default,{align:"left",padding:a.disablePadding?"none":"normal",sortDirection:r===a.id?t:false,style:{width:S,minWidth:S,maxWidth:S},sx:s=>({position:"relative",backgroundColor:s.palette.mode==="dark"?"#000000":"#f5f5f5",color:s.palette.mode==="dark"?"#ffffff":s.palette.text.primary,fontWeight:"bold",userSelect:"none"}),children:[jsxRuntime.jsx(ta__default.default,{active:r===a.id,direction:r===a.id?t:"asc",onClick:f(a.id),sx:s=>({"&.MuiTableSortLabel-root":{width:"100%"},"& .MuiTableSortLabel-icon":{color:s.palette.mode==="dark"?"#ffffff":s.palette.text.primary,opacity:r===a.id?1:0,transition:"opacity 0.2s"},"&:hover .MuiTableSortLabel-icon":{opacity:.5},"&.Mui-active .MuiTableSortLabel-icon":{opacity:1,color:s.palette.mode==="dark"?"#ffffff":s.palette.text.primary},fontWeight:"bold",color:s.palette.mode==="dark"?"#ffffff":s.palette.text.primary}),children:jsxRuntime.jsx(io__default.default,{component:"span",sx:{overflow:"visible",textOverflow:"clip",whiteSpace:"normal",lineHeight:1.2,wordBreak:"break-word",pr:1},children:a.label})}),jsxRuntime.jsx(io__default.default,{onMouseDown:s=>k(s,a.id,typeof S=="number"?S:100),onClick:s=>s.stopPropagation(),sx:{position:"absolute",right:0,top:0,bottom:0,width:5,cursor:"col-resize","&:hover":{backgroundColor:"primary.main",opacity:.5},zIndex:1}})]},a.id)})]})})};var wo=e=>{let{visibleRows:o,visibleColumns:t,selected:r=[],handleClick:c,columns:n,toggleGroupExpand:i,expandedGroups:l=new Set,selectionMode:m}=e,v=b=>r.indexOf(b)!==-1,w=m==="multiple"||m==="single",D=t.length+(w?1:0);return jsxRuntime.jsxs(material.TableBody,{children:[o.map((b,x)=>{if(b.type==="group"){let p=l.has(b.id),f=b.childIds||[],k=f.filter(a=>v(a)).length,T=f.length>0&&k===f.length,d=k>0&&k<f.length,L=a=>{if(a.stopPropagation(),!!e.onSelectionChange)if(T){let S=r.filter(s=>!f.includes(s));e.onSelectionChange(S);}else {let S=Array.from(new Set([...r,...f]));e.onSelectionChange(S);}};return jsxRuntime.jsx(material.TableRow,{sx:{backgroundColor:"#f5f5f5"},children:jsxRuntime.jsx(material.TableCell,{colSpan:D,sx:{py:1,pl:b.level*4+2},children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center"},children:[jsxRuntime.jsx(material.IconButton,{size:"small",onClick:()=>i&&i(b.id),sx:{mr:1},children:p?jsxRuntime.jsx(la__default.default,{}):jsxRuntime.jsx(ia__default.default,{})}),w&&jsxRuntime.jsx(material.Checkbox,{size:"small",checked:T,indeterminate:d,onChange:L,onClick:a=>a.stopPropagation(),sx:{mr:1,p:.5}}),jsxRuntime.jsxs(material.Typography,{variant:"body2",fontWeight:"bold",children:[b.field,": ",b.value," (",b.count,")"]})]})})},b.id)}else {let p=b.data||b,f=b.id||p.id||x,k=v(f),T=`enhanced-table-checkbox-${x}`,L=(b.level!==void 0?b.level:0)*4;return jsxRuntime.jsxs(material.TableRow,{hover:true,onClick:a=>c&&c(a,p),role:"checkbox","aria-checked":k,tabIndex:-1,selected:k,sx:{cursor:"pointer"},children:[w&&jsxRuntime.jsx(material.TableCell,{padding:"checkbox",sx:{pl:L>0?L+1:void 0},children:jsxRuntime.jsx(material.Checkbox,{color:"primary",checked:k,inputProps:{"aria-labelledby":T}})}),n.filter(a=>t.includes(a.id)).map((a,S)=>{let h=!w&&S===0&&L>0?{pl:L+2}:{};return jsxRuntime.jsx(material.TableCell,{align:"left",sx:h,children:a.render?a.render(p[a.id],p):(function(){let C=p[a.id];if(a.numeric){if(typeof C=="number")return C.toLocaleString();if(typeof C=="string"&&C.trim()!==""&&!isNaN(Number(C)))return Number(C).toLocaleString()}return C})()},a.id)})]},f)}}),o.length===0&&jsxRuntime.jsx(material.TableRow,{children:jsxRuntime.jsx(material.TableCell,{colSpan:D,align:"center",children:"No data"})})]})};var Io=e=>{let{visibleColumns:o,summaryRow:t,selectionMode:r}=e;if(!e.showSummary)return null;let c=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:[c&&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 l=t[n];return l==null||l===""?"":typeof l=="number"?l.toLocaleString():typeof l=="string"&&l.trim()!==""&&!isNaN(Number(l))?Number(l).toLocaleString():l})()},n))]})})};var Mo=e=>jsxRuntime.jsx(material.Box,{sx:{p:2},children:jsxRuntime.jsx(material.Typography,{children:"Mobile View Not Implemented"})});var Po=({groupAnchorEl:e,setGroupAnchorEl:o,grouping:t,setGrouping:r,columns:c,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(Ca__default.default,{}),children:"Clear All"})]}),jsxRuntime.jsx(material.Divider,{}),c.map(i=>{let l=t.includes(i.id),m=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:l,size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:i.label}),l&&jsxRuntime.jsx(material.Badge,{badgeContent:m,color:"primary",sx:{mr:2}})]})},i.id)})]}),Eo=({anchorEl:e,setAnchorEl:o,columns:t,visibleColumns:r,toggleColumnVisibility:c})=>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:()=>c(n.id),children:[jsxRuntime.jsx(material.Checkbox,{checked:r.includes(n.id),size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:n.label})]},n.id))]}),Bo=({anchorEl:e,setAnchorEl:o,showSummary:t,setShowSummary:r,columns:c,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:l=>r(l.target.checked),size:"small"}),label:"Show Summary Row"})}),jsxRuntime.jsx(material.Divider,{}),c.filter(l=>l.numeric).map(l=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>i(l.id),disabled:!t,children:[jsxRuntime.jsx(material.Checkbox,{checked:n.includes(l.id),size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:l.label})]},l.id)),c.filter(l=>l.numeric).length===0&&jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.ListItemText,{primary:"No numeric columns"})})]}),Lo=({contextMenu:e,handleCloseContextMenu:o,columns:t,visibleColumns:r,toggleColumnVisibility:c})=>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:()=>c(n.id),children:[jsxRuntime.jsx(material.ListItemIcon,{children:r.includes(n.id)&&jsxRuntime.jsx(xa__default.default,{fontSize:"small"})}),jsxRuntime.jsx(material.ListItemText,{children:n.label})]},n.id))]});var $e=(e,o=2)=>e.toLocaleString(void 0,{maximumFractionDigits:o}),Vo=({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 pt=["#1E88E5","#1ABC9C","#FBC02D","#EF5350","#7E57C2","#78909C"],ka=({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))})},Ia=({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))})},Ra=({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((c,n)=>{let i=o;return o+=c.percent,`${pt[n%pt.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((c,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:pt[n%pt.length]}}),jsxRuntime.jsx(material.Typography,{variant:"caption",sx:{flex:1},children:c.name}),jsxRuntime.jsxs(material.Typography,{variant:"caption",sx:{fontWeight:700},children:[c.percent.toFixed(0),"%"]})]},c.name))})]})},Yt=({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]}),Fo=({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(Yt,{title:"Billable by Dimension",subtitle:"Top values by billable hours",children:jsxRuntime.jsx(ka,{data:e})}),jsxRuntime.jsx(Yt,{title:"Efficiency by Person",subtitle:"Lowest efficiency first",children:jsxRuntime.jsx(Ia,{data:o})}),jsxRuntime.jsx(Yt,{title:"Status Distribution",subtitle:"Record ratio by status",children:jsxRuntime.jsx(Ra,{data:t})})]});var Go=({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(Ba__default.default,{})})]})}),jsxRuntime.jsxs(material.Box,{sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,overflow:"auto",minHeight:0},children:[jsxRuntime.jsx(Vo,{kpis:t.kpis}),jsxRuntime.jsx(Fo,{billableByPrimary:t.charts.billableByPrimary,efficiencyBySecondary:t.charts.efficiencyBySecondary,statusDistribution:t.charts.statusDistribution}),r]})]})});var ve={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"]},La=5,Oo=e=>e.toLowerCase().replace(/[\s_-]/g,""),Se=(e,o,t,r)=>{if(o)return o;if(e.length===0)return r;let c=Object.keys(e[0]),n=new Map(c.map(i=>[Oo(i),i]));for(let i of t){let l=n.get(Oo(i));if(l)return l}return c[0]||r},ye=e=>{if(typeof e=="number")return Number.isFinite(e)?e:0;if(typeof e=="string"){let o=Number(e.replace(/,/g,"").trim());return Number.isFinite(o)?o:0}return 0},he=(e,o)=>e==null||e===""?o:String(e),Aa=(e,o,t,r)=>{let c=new Map;return e.forEach(n=>{let i=he(n[o],"Unassigned");c.set(i,(c.get(i)||0)+ye(n[t]));}),Array.from(c.entries()).map(([n,i])=>({name:n,value:i})).sort((n,i)=>i.value-n.value).slice(0,r)},Va=(e,o,t,r,c)=>{let n=new Map;return e.forEach(i=>{let l=he(i[o],"Unassigned"),m=n.get(l)||{report:0,billable:0};m.report+=ye(i[t]),m.billable+=ye(i[r]),n.set(l,m);}),Array.from(n.entries()).map(([i,l])=>({name:i,value:l.report>0?l.billable/l.report*100:0})).sort((i,l)=>i.value-l.value).slice(0,c)},Fa=(e,o)=>{let t=e.length;if(t===0)return [];let r=new Map;return e.forEach(c=>{let n=he(c[o],"Unassigned");r.set(n,(r.get(n)||0)+1);}),Array.from(r.entries()).map(([c,n])=>({name:c,value:n,percent:n/t*100}))},zo=({rows:e,config:o})=>{let t=co.useMemo(()=>{let m=o?.fieldMapping;return {primaryDimension:Se(e,m?.primaryDimension,ve.primaryDimension,"Category"),secondaryDimension:Se(e,m?.secondaryDimension,ve.secondaryDimension,"Owner"),status:Se(e,m?.status,ve.status,"Status"),date:Se(e,m?.date,ve.date,"Date"),description:Se(e,m?.description,ve.description,"Description"),reportHours:Se(e,m?.reportHours,ve.reportHours,"ReportHours"),billableHours:Se(e,m?.billableHours,ve.billableHours,"BillableHours"),amount:Se(e,m?.amount,ve.amount,"Amount")}},[e,o?.fieldMapping]),r=co.useMemo(()=>e.map((m,v)=>{let w=ye(m[t.reportHours]),D=ye(m[t.billableHours]),b=ye(m[t.amount]),x=w>0?D/w*100:0;return {id:`graph-row-${v}`,Date:he(m[t.date],""),Primary:he(m[t.primaryDimension],"Unassigned"),Secondary:he(m[t.secondaryDimension],"Unassigned"),Description:he(m[t.description],""),ReportHours:w,BillableHours:D,Amount:b,Efficiency:x,Status:he(m[t.status],"Unassigned")}}),[e,t]),c=co.useMemo(()=>{let m=r.length,v=r.reduce((f,k)=>f+ye(k.ReportHours),0),w=r.reduce((f,k)=>f+ye(k.BillableHours),0),D=r.reduce((f,k)=>f+ye(k.Amount),0),b=v>0?w/v*100:0,x=o?.statusFlagValues||["flag","flagged","warning","risk"],p=r.filter(f=>x.includes(he(f.Status,"").toLowerCase())).length;return {totalRecords:m,totalReportHours:v,totalBillableHours:w,efficiency:b,totalAmount:D,flaggedCount:p}},[r,o?.statusFlagValues]),n=o?.topN||La,i=co.useMemo(()=>({billableByPrimary:Aa(r,"Primary","BillableHours",n),efficiencyBySecondary:Va(r,"Secondary","ReportHours","BillableHours",n),statusDistribution:Fa(r,"Status")}),[r,n]),l=co.useMemo(()=>({title:o?.title||"Graphic Report",kpis:c,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,c,r]);return {fieldMapping:t,model:l}};var gt=({variants:e,currentVariantId:o,onLoad:t,onSave:r,onDelete:c,onSetDefault:n})=>{let i="0.75rem",[l,m]=co.useState(false),[v,w]=co.useState(""),[D,b]=co.useState(false),[x,p]=co.useState(false),f=e.find(d=>d.id===o);return jsxRuntime.jsxs(material.Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsxRuntime.jsx(material.Typography,{variant:"body2",sx:{fontWeight:"bold",minWidth:"fit-content",fontSize: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:d=>d.name+(d.isDefault?" (Default)":""),value:f||null,onChange:(d,L)=>{L&&t(L);},renderInput:d=>jsxRuntime.jsx(material.TextField,{...d,variant:"outlined",size:"small",InputProps:{...d.InputProps,sx:{fontSize:i}},placeholder:"Select Variant"}),renderOption:(d,L)=>jsxRuntime.jsx("li",{...d,children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsxRuntime.jsx(material.Typography,{sx:{flex:1,fontSize:i},children:L.name}),L.isDefault&&jsxRuntime.jsx(_a__default.default,{fontSize:"small",color:"action"})]})})}),jsxRuntime.jsx(material.Tooltip,{title:"Save View",children:jsxRuntime.jsx(material.IconButton,{onClick:()=>{w(f?.name||"New Variant"),b(f?.isDefault||false),p(f?.isPublic||false),m(true);},size:"small",color:"primary",children:jsxRuntime.jsx(ln__default.default,{})})}),jsxRuntime.jsxs(material.Dialog,{open:l,onClose:()=>m(false),children:[jsxRuntime.jsx(material.DialogTitle,{children:"Save View"}),jsxRuntime.jsxs(material.DialogContent,{children:[jsxRuntime.jsx(material.TextField,{autoFocus:true,margin:"dense",label:"View Name",fullWidth:true,variant:"outlined",value:v,onChange:d=>w(d.target.value)}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:D,onChange:d=>b(d.target.checked)}),label:"Set as Default"}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:x,onChange:d=>p(d.target.checked)}),label:"Public (All Users)"})]}),jsxRuntime.jsxs(material.DialogActions,{children:[jsxRuntime.jsx(material.Button,{onClick:()=>m(false),children:"Cancel"}),jsxRuntime.jsx(material.Button,{onClick:()=>{r({name:v,isDefault:D,isPublic:x,description:""}),m(false);},variant:"contained",children:"Save"})]})]})]})};var Ya="http://127.0.0.1:8515",Ko=({appId:e,tableKey:o="default",currentFilters:t,currentLayoutId:r,layoutRefs:c,onLoad:n,serviceUrl:i=Ya,onError:l,onSuccess:m,currentVariantId:v,onVariantChange:w})=>{let[D,b]=co.useState([]),[x,p]=co.useState(""),f=v!==void 0?v:x,k=s=>{v===void 0&&p(s),w&&w(s);},T=co.useCallback(async()=>{if(!e)return [];try{let s=await fetch(`${i}/api/variants?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!s.ok)throw new Error("Failed to fetch variants");let h=await s.json();b(h);let I=h.find(C=>C.isDefault);return I&&!f&&(k(I.id),n(I)),h}catch(s){return console.error("Error fetching variants",s),l&&l("Failed to load variants"),[]}},[e,o,i,l,f,n]);return co.useEffect(()=>{T();},[e,o]),jsxRuntime.jsx(gt,{variants:D,currentVariantId:f,onLoad:s=>{k(s.id),n(s);},onSave:async s=>{try{let h=D.find(A=>A.name===s.name),I=h?h.id:Date.now().toString(),C=[];if(h&&(Array.isArray(h.filters)?C=[...h.filters]:h.filters&&(C=[{scope:"default",filters:h.filters}])),s.scope==="Search"||s.scope==="Both"){let A=(Array.isArray(t),t);if(A)if(Array.isArray(A)&&A.length>0&&A[0].scope)A.forEach(F=>{let E=C.findIndex(G=>G.scope===F.scope);E>=0?C[E]=F:C.push(F);});else {let F={scope:o,filters:A},E=C.findIndex(G=>G.scope===o);E>=0?C[E]=F:C.push(F);}}let u=h?.layout||{},M=[];if(h&&Array.isArray(h.layoutRefs)&&(M=[...h.layoutRefs]),s.scope==="Layout"||s.scope==="Both")if(c&&c.length>0)c.forEach(A=>{let F=M.findIndex(E=>E.tableKey===A.tableKey);F>=0?M[F]=A:M.push(A);});else {let A={tableKey:o,layoutId:r||null},F=M.findIndex(E=>E.tableKey===o);F>=0?M[F]=A:M.push(A);}let g={appId:e,tableKey:o,...s,id:I,createdAt:new Date().toISOString(),filters:C,layout:u,layoutRefs:M};if(!(await fetch(`${i}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)})).ok)throw new Error("Failed to save variant");m&&m("Variant saved successfully"),await T(),k(I),n(g);}catch(h){console.error("Error saving variant",h),l&&l("Failed to save variant");}},onDelete:async s=>{try{if(!(await fetch(`${i}/api/variants/${s}`,{method:"DELETE"})).ok)throw new Error("Failed to delete variant");f===s&&k(""),T(),m&&m("Variant deleted successfully");}catch(h){console.error("Error deleting variant",h),l&&l("Failed to delete variant");}},onSetDefault:async s=>{try{let h=D.find(u=>u.id===s);if(!h)return;let I={appId:e,tableKey:o,...h,isDefault:!0};if(!(await fetch(`${i}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(I)})).ok)throw new Error("Failed to set default variant");await T(),m&&m("Default variant updated");}catch(h){console.error("Error setting default variant",h),l&&l("Failed to update default variant");}}})};Me__default.default.extend(cr__default.default);var dr=[null,null],eo="0.75rem",ur=material.styled(PickersDay.PickersDay,{shouldForwardProp:e=>e!=="isInRange"&&e!=="isStart"&&e!=="isEnd"&&e!=="isHovered"})(({theme:e,isInRange:o,isStart:t,isEnd:r,isHovered:c})=>({...o&&{borderRadius:0,backgroundColor:e.palette.primary.light,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.main}},...c&&!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%"}})),Xo=({label:e="Date Range",value:o=dr,onChange:t})=>{let[r,c]=co.useState(null),[n,i]=co.useState(o),[l,m]=co.useState("start"),[v,w]=co.useState(null),[D,b]=co.useState(o[0]||Me__default.default()),x=co__namespace.default.useRef(o);co.useEffect(()=>{let[I,C]=o,[u,M]=x.current,g=F=>F&&typeof F.isSame=="function",W=!(I===null&&u===null||g(I)&&g(u)&&I.isSame(u,"day")),A=!(C===null&&M===null||g(C)&&g(M)&&C.isSame(M,"day"));(W||A)&&(i(o),o[0]&&g(o[0])&&b(o[0])),x.current=o;},[o]);let p=I=>{c(I.currentTarget);},f=()=>{c(null),m("start"),w(null);},k=!!r,T=I=>{if(!I)return;let C=[...n];if(l==="start")C=[I,null],m("end");else {let u=C[0];u&&I.isBefore(u)?(C=[I,null],m("end")):(C=[u,I],m("start"));}i(C);},d=I=>{let C=Me__default.default(),u=[null,null];switch(I){case "today":u=[C,C];break;case "week":u=[C.startOf("week"),C.endOf("week")];break;case "month":u=[C.startOf("month"),C.endOf("month")];break}i(u),m("start"),b(C);},L=()=>{i([null,null]),m("start"),b(Me__default.default());},a=()=>{t&&t(n),f();},S=()=>{i(o),m("start"),f();},s=co.useCallback(I=>{let{day:C,...u}=I,[M,g]=n,W=M?C.isSame(M,"day"):false,A=g?C.isSame(g,"day"):false,F=M&&g?C.isBetween(M,g,"day","()"):false,E=false;return l==="end"&&M&&!g&&v&&C.isAfter(M,"day")&&C.isBefore(v.add(1,"day"),"day")&&(E=true),jsxRuntime.jsx(ur,{...u,day:C,disableMargin:true,isStart:W,isEnd:A,isInRange:F||E,onMouseEnter:()=>w(C)})},[n,l,v]),h=I=>I?I.format("YYYY-MM-DD"):"";return jsxRuntime.jsxs(material.Box,{children:[jsxRuntime.jsx(material.TextField,{label:e,value:n[0]?`${h(n[0])} - ${h(n[1])}`:"",onClick:p,fullWidth:true,size:"small",InputLabelProps:{sx:{fontSize:eo}},InputProps:{readOnly:true,sx:{fontSize:eo,"& .MuiOutlinedInput-input":{fontSize:eo},paddingRight:"4px"},endAdornment:jsxRuntime.jsxs(material.InputAdornment,{position:"end",sx:{ml:0},children:[(n[0]||n[1])&&jsxRuntime.jsx(material.IconButton,{size:"small",onClick:I=>{I.stopPropagation(),L();},edge:"end",sx:{mr:.5,padding:"2px"},children:jsxRuntime.jsx(lr__default.default,{sx:{fontSize:"1rem"}})}),jsxRuntime.jsx(material.IconButton,{size:"small",edge:"end",onClick:p,sx:{padding:"2px"},children:jsxRuntime.jsx(ir__default.default,{sx:{fontSize:"1rem"},color:"action"})})]})}}),jsxRuntime.jsxs(material.Popover,{open:k,anchorEl:r,onClose:f,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:l==="start"?"primary.main":"divider",borderRadius:1,bgcolor:l==="start"?"action.hover":"transparent",flex:1,cursor:"pointer"},onClick:()=>m("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(sr__default.default,{color:"action",fontSize:"small"}),jsxRuntime.jsxs(material.Box,{sx:{p:1,border:1,borderColor:l==="end"?"primary.main":"divider",borderRadius:1,bgcolor:l==="end"?"action.hover":"transparent",flex:1,cursor:"pointer"},onClick:()=>{n[0]&&m("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:()=>d("today"),clickable:true,size:"small",variant:"outlined"}),jsxRuntime.jsx(material.Chip,{label:"This Week",onClick:()=>d("week"),clickable:true,size:"small",variant:"outlined"}),jsxRuntime.jsx(material.Chip,{label:"This Month",onClick:()=>d("month"),clickable:true,size:"small",variant:"outlined"})]})}),jsxRuntime.jsx(DateCalendar.DateCalendar,{value:null,referenceDate:D,onMonthChange:b,onYearChange:b,onChange:T,slots:{day:s},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:S,color:"inherit",children:"Cancel"}),jsxRuntime.jsx(material.Button,{size:"small",variant:"contained",onClick:a,children:"Done"})]})]})]})};var xt={equals:"=",contains:"\u2287",notContains:"\u2285",wildcard:"*","=":"=","!=":"!=",">":">","<":"<",">=":"\u2265","<=":"\u2264",between:"\u2194"},Sr={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"},Tr=["equals","contains","notContains","wildcard"],Qo=["=","!=",">","<",">=","<=","between"],Z="0.75rem",wr=({field:e,value:o,onChange:t})=>{let[r,c]=co.useState(null),[n,i]=co.useState(null),[l,m]=co.useState(""),[v,w]=co.useState(""),[D,b]=co.useState(false),[x,p]=co.useState(""),[f,k]=co.useState("");co.useEffect(()=>{let u=setTimeout(()=>{k(x);},1e3);return ()=>clearTimeout(u)},[x]);let T=o?.operator||(e.type==="number"?"=":"equals"),d=o?.value,L=u=>Sr[u]||u,a=u=>{c(u.currentTarget);},S=u=>{t({...o,operator:u,value:d}),c(null);},s={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"}}}}}},h=e.type||"text";if(h==="date"){let M=(g=>{if(!g)return [null,null];if(Array.isArray(g)&&g.length===2){let W=g[0]?Me__default.default.isDayjs(g[0])?g[0]:Me__default.default(g[0]):null,A=g[1]?Me__default.default.isDayjs(g[1])?g[1]:Me__default.default(g[1]):null;return [W,A]}return Me__default.default.isDayjs(g)||typeof g=="string"?[Me__default.default.isDayjs(g)?g:Me__default.default(g),null]:[null,null]})(d);return jsxRuntime.jsx(Xo,{label:e.label,value:M,onChange:g=>t({value:g,operator:"between"})})}if(h==="number"&&T==="between"){let u=()=>{t({value:[l,v],operator:"between"}),i(null);},M=Array.isArray(d)?`${d[0]||""} - ${d[1]||""}`:"";return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(material.TextField,{...s,label:e.label,value:M,placeholder:"Min - Max",InputProps:{...s.InputProps,startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(material.Tooltip,{title:L("between"),children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:a,sx:{width:24,height:24,fontSize:Z},children:xt.between})})}),readOnly:true},onClick:g=>i(g.currentTarget)}),jsxRuntime.jsx(material.Menu,{anchorEl:r,open:!!r,onClose:()=>c(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,minHeight:"auto",py:.5}}},children:Qo.map(g=>jsxRuntime.jsxs(material.MenuItem,{selected:g===T,onClick:()=>S(g),children:[jsxRuntime.jsx(material.Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:xt[g]}),jsxRuntime.jsx(material.ListItemText,{primary:L(g),primaryTypographyProps:{fontSize:Z}})]},g))}),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:l,onChange:g=>m(g.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}}}),jsxRuntime.jsx(vr__default.default,{color:"action"}),jsxRuntime.jsx(material.TextField,{size:"small",label:"Max",type:"number",value:v,onChange:g=>w(g.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}}}),jsxRuntime.jsx(material.Button,{variant:"contained",size:"small",onClick:u,children:"OK"})]})})]})}if(h==="select")return jsxRuntime.jsxs(material.TextField,{...s,select:true,label:e.label,value:d||"",onChange:u=>t({...o,value:u.target.value,operator:"equals"}),children:[jsxRuntime.jsx(material.MenuItem,{value:"",children:jsxRuntime.jsx("em",{children:"None"})}),e.options?.map(u=>jsxRuntime.jsx(material.MenuItem,{value:u.value,children:u.label},u.value))]});if(h==="multi-select"){let u=Array.isArray(d)?d:[],M=e.options?.filter(g=>g.label.toLowerCase().includes(f.toLowerCase()))||[];return jsxRuntime.jsxs(material.TextField,{...s,select:true,label:e.label,value:u,onChange:g=>t({...o,value:g.target.value,operator:"anyOf"}),SelectProps:{...s.SelectProps,multiple:true,onClose:()=>{p(""),k("");},renderValue:g=>{if(!Array.isArray(g)||g.length===0)return jsxRuntime.jsx("em",{children:"None"});let W=F=>e.options?.find(E=>E.value===F)?.label||F,A=g.map(W);return A.length>2?`${A.slice(0,2).join(", ")} +${A.length-2}`:A.join(", ")}},children:[jsxRuntime.jsx(material.ListSubheader,{children:jsxRuntime.jsx(material.TextField,{size:"small",autoFocus:true,placeholder:"Search...",fullWidth:true,InputProps:{startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(Zo__default.default,{fontSize:"small"})}),sx:{fontSize:Z}},value:x,onChange:g=>p(g.target.value),onKeyDown:g=>{g.key!=="Escape"&&g.stopPropagation();},onClick:g=>g.stopPropagation()})}),M.length>0?M.map(g=>jsxRuntime.jsxs(material.MenuItem,{value:g.value,children:[jsxRuntime.jsx(material.Checkbox,{checked:u.indexOf(g.value)>-1,size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:g.label,primaryTypographyProps:{fontSize:Z}})]},g.value)):jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.ListItemText,{primary:"No options found",primaryTypographyProps:{fontSize:Z}})})]})}let I=h==="number"?Qo:Tr,C=D||d!==void 0&&d!==""&&d!==null||!!r;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(material.TextField,{...s,label:e.label,sx:{minWidth:"120px"},value:d||"",type:h==="number"?"number":"text",onChange:u=>t({...o,value:u.target.value,operator:T}),onFocus:()=>b(true),onBlur:()=>b(false),InputProps:{...s.InputProps,startAdornment:C?jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(material.Tooltip,{title:L(T),children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:a,onMouseDown:u=>u.preventDefault(),sx:{width:24,height:24,fontSize:Z,fontWeight:"bold",color:"primary.main",bgcolor:"action.hover"},children:xt[T]})})}):null,endAdornment:e.hasSearchIcon?jsxRuntime.jsx(material.InputAdornment,{position:"end",children:jsxRuntime.jsx(Zo__default.default,{color:"action"})}):void 0}}),jsxRuntime.jsx(material.Menu,{anchorEl:r,open:!!r,onClose:()=>c(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,minHeight:"auto",py:.5}}},children:I.map(u=>jsxRuntime.jsxs(material.MenuItem,{selected:u===T,onClick:()=>S(u),children:[jsxRuntime.jsx(material.Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:xt[u]}),jsxRuntime.jsx(material.ListItemText,{primary:L(u),primaryTypographyProps:{fontSize:Z}})]},u))})]})},Ye=({fields:e,filters:o,onFilterChange:t,variants:r=[],currentVariantId:c,onVariantLoad:n,onVariantSave:i,onVariantDelete:l,onVariantSetDefault:m,onSearch:v,loading:w=false,appId:D,tableKey:b,currentLayout:x,currentLayoutId:p,layoutRefs:f,variantService:k})=>{let[T,d]=co.useState(true),[L,a]=co.useState(null),[S,s]=co.useState(e.filter(u=>!u.hidden).map(u=>u.id)),h=(u,M)=>{t({...o,[u]:M});},I=u=>{S.includes(u)?s(S.filter(M=>M!==u)):s([...S,u]);};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:[D?jsxRuntime.jsx(Ko,{appId:D,tableKey:b,currentFilters:{values:o,visibleFields:S},currentLayout:x,currentLayoutId:p,layoutRefs:f,onLoad:u=>{if(!u.filters)return;let M=null;if(Array.isArray(u.filters)){let g=b||"default",W=u.filters.find(A=>A.scope===g);M=W?W.filters:null;}else M=u.filters;M&&(M.values||M.visibleFields?(M.visibleFields&&Array.isArray(M.visibleFields)&&s(M.visibleFields),M.values&&t(M.values)):t(M)),n&&n(u);},variantService:k,currentVariantId:c}):jsxRuntime.jsx(gt,{variants:r,currentVariantId:c,onLoad:n,onSave:u=>{i&&i({...u,filters:{values:o,visibleFields:S}});},onDelete:l,onSetDefault:m}),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:u=>a(u.currentTarget),size:"small",color:"primary",startIcon:jsxRuntime.jsx(br__default.default,{fontSize:"small"}),sx:{textTransform:"none",fontSize:Z},children:"Adapt Filters"})}),jsxRuntime.jsx(material.Button,{variant:"contained",size:"small",onClick:v,disabled:w,sx:{minWidth:"40px",fontWeight:"bold"},children:w?"...":"Go"}),jsxRuntime.jsxs(material.Menu,{anchorEl:L,open:!!L,onClose:()=>a(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(u=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>I(u.id),children:[jsxRuntime.jsx(material.Checkbox,{checked:S.includes(u.id),size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:u.label})]},u.id))]})]})]}),jsxRuntime.jsx(material.Collapse,{in:T,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(u=>S.includes(u.id)).map(u=>jsxRuntime.jsx(material.Grid,{size:1,children:jsxRuntime.jsx(wr,{field:u,value:o[u.id]||{value:"",operator:u.type==="number"?"=":"equals"},onChange:M=>h(u.id,M)})},u.id))})})}),jsxRuntime.jsx(material.Box,{sx:{position:"absolute",bottom:0,left:"50%",transform:"translate(-50%, 50%)",zIndex:10},children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:()=>d(!T),sx:{bgcolor:"background.paper",boxShadow:2,border:"1px solid",borderColor:"divider",width:20,height:20,minHeight:0,p:0,"&:hover":{bgcolor:"background.paper"}},children:T?jsxRuntime.jsx(xr__default.default,{sx:{fontSize:16},color:"action"}):jsxRuntime.jsx(la__default.default,{sx:{fontSize:16},color:"action"})})})]})};var sn=({layouts:e,currentLayoutId:o,onLoad:t,onSave:r,onDelete:c,onSetDefault:n})=>{let[i,l]=co.useState(null),[m,v]=co.useState(false),[w,D]=co.useState(""),[b,x]=co.useState(""),[p,f]=co.useState({isDefault:false,isPublic:false}),k=e.find(s=>s.id===o),T=s=>{l(s.currentTarget);},d=()=>{l(null);},L=s=>{t(s),d();},a=()=>{D(""),x(""),f({isDefault:false,isPublic:false}),v(true),d();},S=()=>{w.trim()&&(r({name:w,description:b,...p}),v(false));};return jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsxRuntime.jsx(material.Tooltip,{title:"Save Layout",children:jsxRuntime.jsx(material.IconButton,{onClick:a,color:"primary",size:"small",children:jsxRuntime.jsx(ln__default.default,{})})}),jsxRuntime.jsx(material.Tooltip,{title:"Layout Options",children:jsxRuntime.jsx(material.IconButton,{onClick:T,color:k?"primary":"default",children:jsxRuntime.jsx(Fr__default.default,{})})}),jsxRuntime.jsxs(material.Menu,{anchorEl:i,open:!!i,onClose:d,PaperProps:{sx:{width:320,maxHeight:400}},children:[jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.Typography,{variant:"caption",children:"Select Layout"})}),jsxRuntime.jsxs(material.MenuItem,{onClick:a,children:[jsxRuntime.jsx(material.ListItemIcon,{children:jsxRuntime.jsx(ln__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((s,h)=>jsxRuntime.jsx(material.MenuItem,{onClick:()=>L(s),selected:s.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:s.id===o?"bold":"normal",noWrap:true,children:s.name})}),s.description&&jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",noWrap:true,children:s.description})]}),jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center"},onClick:I=>I.stopPropagation(),children:[jsxRuntime.jsx(material.Tooltip,{title:s.isDefault?"Remove Default":"Set as Default",children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:I=>{I.stopPropagation(),n(s.id);},children:s.isDefault?jsxRuntime.jsx(_a__default.default,{fontSize:"small",color:"warning"}):jsxRuntime.jsx(Vr__default.default,{fontSize:"small"})})}),jsxRuntime.jsx(material.Tooltip,{title:"Delete",children:jsxRuntime.jsx(material.IconButton,{size:"small",color:"error",onClick:I=>{I.stopPropagation(),c(s.id);},children:jsxRuntime.jsx(Lr__default.default,{fontSize:"small"})})})]})]})},s.id||h))]}),jsxRuntime.jsxs(material.Dialog,{open:m,onClose:()=>v(false),maxWidth:"xs",fullWidth:true,children:[jsxRuntime.jsx(material.DialogTitle,{children:"Save Layout"}),jsxRuntime.jsx(material.DialogContent,{children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[jsxRuntime.jsx(material.TextField,{label:"Layout Name",value:w,onChange:s=>D(s.target.value),fullWidth:true,autoFocus:true,size:"small",helperText:"e.g., 'Compact View'"}),e.some(s=>s.name===w)&&jsxRuntime.jsx(material.Typography,{variant:"caption",color:"warning.main",sx:{ml:1},children:"Warning: Existing layout will be overwritten"}),jsxRuntime.jsx(material.TextField,{label:"Description",value:b,onChange:s=>x(s.target.value),fullWidth:true,size:"small"}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:p.isDefault,onChange:s=>f({...p,isDefault:s.target.checked})}),label:"Use as Default Layout"}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:p.isPublic,onChange:s=>f({...p,isPublic:s.target.checked})}),label:"Public (Visible to all users)"})]})}),jsxRuntime.jsxs(material.DialogActions,{children:[jsxRuntime.jsx(material.Button,{onClick:()=>v(false),children:"Cancel"}),jsxRuntime.jsx(material.Button,{onClick:S,variant:"contained",disabled:!w,children:"Save"})]})]})]})};var Gr="http://127.0.0.1:8515",dn=({appId:e,tableKey:o="default",currentLayoutData:t,onLayoutLoad:r,targetLayoutId:c,activeLayoutId:n,serviceUrl:i=Gr,onError:l,onSuccess:m})=>{let[v,w]=co.useState([]),[D,b]=co.useState(""),x=a=>({id:a.layoutId,name:a.name,description:a.description??"",isDefault:!!a.isDefault,isPublic:!!a.isPublic,createdAt:a.createdAt??new Date().toISOString(),layoutData:a.layout??{}}),p=a=>({appId:e,tableKey:o,layoutId:a.id,name:a.name,description:a.description??"",isDefault:!!a.isDefault,isPublic:!!a.isPublic,createdAt:a.createdAt,layout:a.layoutData});co.useEffect(()=>{n!==void 0&&b(n);},[n]),co.useEffect(()=>{if(c&&v.length>0){let a=v.find(S=>S.id===c);a&&(b(a.id),r(a));}},[c,v,r]);let f=co.useCallback(async()=>{if(e)try{let a=await fetch(`${i}/api/layouts?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!a.ok)throw new Error("Failed to fetch layouts");let s=(await a.json()).map(x);w(s);let h=s.find(I=>I.isDefault);h&&!D&&!c&&(b(h.id),r(h));}catch(a){console.error("Error fetching layouts",a),l&&l("Failed to load layouts");}},[e,o,i,l,D,r,c]);return co.useEffect(()=>{f();},[e,o]),jsxRuntime.jsx(sn,{layouts:v,currentLayoutId:D,onLoad:a=>{b(a.id),r(a);},onSave:async a=>{try{let S=v.find(C=>C.name===a.name),s=S?S.id:Date.now().toString(),h={id:s,...a,createdAt:new Date().toISOString(),layoutData:t,isDefault:a.isDefault??!1,isPublic:a.isPublic??!1};if(!(await fetch(`${i}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(p(h))})).ok)throw new Error("Failed to save layout");m&&m("Layout saved successfully"),await f(),b(s),r(h);}catch(S){console.error("Error saving layout",S),l&&l("Failed to save layout");}},onDelete:async a=>{try{if(!(await fetch(`${i}/api/layouts/${encodeURIComponent(a)}`,{method:"DELETE"})).ok)throw new Error("Failed to delete layout");D===a&&b(""),m&&m("Layout deleted successfully"),await f();}catch(S){console.error("Error deleting layout",S),l&&l("Failed to delete layout");}},onSetDefault:async a=>{try{let S=v.find(h=>h.id===a);if(!S)return;if(!(await fetch(`${i}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(p({...S,isDefault:!0}))})).ok)throw new Error("Failed to set default layout");m&&m("Default layout set"),await f();}catch(S){console.error("Error setting default",S),l&&l("Failed to set default layout");}}})};function pn(e,o,t){return o[t]<e[t]?-1:o[t]>e[t]?1:0}function zr(e,o){return e==="desc"?(t,r)=>pn(t,r,o):(t,r)=>-pn(t,r,o)}function Hr(e,o){let t=e.map((r,c)=>[r,c]);return t.sort((r,c)=>{let n=o(r[0],c[0]);return n!==0?n:r[1]-c[1]}),t.map(r=>r[0])}var mn=e=>{let o=co.useCallback(y=>{let B=String(y?.label??y?.id??"").length*9+64,Q=typeof y?.minWidth=="number"?y.minWidth:0;return Math.max(100,Q,B)},[]),[t,r]=co.useState(""),[c,n]=co.useState(e.order||"asc"),[i,l]=co.useState(e.orderBy||""),[m,v]=co.useState(e.page||0),[w,D]=co.useState(e.rowsPerPage||20),[b,x]=co.useState(e.selected||[]),[p,f]=co.useState(e.columns?e.columns.map(y=>y.id):[]),[k,T]=co.useState(e.showSummary||false),[d,L]=co.useState([]),[a,S]=co.useState(new Set),[s,h]=co.useState(()=>{let y={};return (e.columns||[]).forEach(P=>{y[P.id]=o(P);}),y}),[I,C]=co.useState(null),[u,M]=co.useState(null),[g,W]=co.useState(null),[A,F]=co.useState(null),[E,G]=co.useState(false);co.useEffect(()=>{e.order!==void 0&&n(e.order),e.orderBy!==void 0&&l(e.orderBy);},[e.order,e.orderBy]),co.useEffect(()=>{e.selected!==void 0&&x(e.selected);},[e.selected]),co.useEffect(()=>{e.page!==void 0&&v(e.page);},[e.page]),co.useEffect(()=>{h(y=>{let P={...y};return (e.columns||[]).forEach(B=>{P[B.id]===void 0&&(P[B.id]=o(B));}),P});},[e.columns,o]);let O=co.useMemo(()=>{let y=e.rows||[];return t&&(y=y.filter(P=>Object.keys(P).some(B=>String(P[B]).toLowerCase().includes(t.toLowerCase())))),y},[e.rows,t]),ke=co.useMemo(()=>e.onSortChange||!i?O:Hr(O,zr(c,i)),[O,c,i,e.onSortChange]),Ie=co.useCallback(y=>{if(d.length===0)return y.map(Y=>({type:"row",data:Y,id:Y[e.rowKey||"id"]}));let P=[...y].sort((Y,J)=>{for(let U of d){if(Y[U]<J[U])return -1;if(Y[U]>J[U])return 1}return 0}),B=(Y,J=0)=>{if(J>=d.length)return Y;let U=d[J],$={},re=[];return Y.forEach(ie=>{let Pe=ie[U],ue=`${U}:${Pe}`;$[ue]||($[ue]={key:ue,field:U,value:Pe,children:[],count:0,level:J},re.push($[ue])),$[ue].children.push(ie),$[ue].count++;}),re.forEach(ie=>{ie.children&&(ie.children=B(ie.children,J+1));}),re},Q=B(P),z=(Y,J="")=>{let U=[];return Y.forEach($=>{if($.children){let re=J?`${J}>${$.key}`:$.key,ie=a.has(re);U.push({type:"group",id:re,field:$.field,value:$.value,level:$.level,count:$.count,isExpanded:ie,childIds:(function Pe(ue){let Ee=[];return ue.children.forEach(Be=>{Be.children?Ee=Ee.concat(Pe(Be)):Ee.push(Be[e.rowKey||"id"]);}),Ee})($)}),ie&&(U=U.concat(z($.children,re)));}else U.push({type:"row",data:$,id:$[e.rowKey||"id"],level:d.length});}),U};return z(Q)},[d,a,e.rowKey]),ae=co.useMemo(()=>Ie(ke),[ke,Ie]),te=co.useMemo(()=>w>0?ae.slice(m*w,m*w+w):ae,[ae,m,w]),Oe=y=>{let P=new Set(a);P.has(y)?P.delete(y):P.add(y),S(P);},kt=y=>{Oe(y);},ze=y=>{let P=new Set(a);Array.from(P).forEach(B=>{B.startsWith(y)&&P.delete(B);}),S(P);},It=y=>{y||S(new Set);},Rt=y=>{let P=i===y&&c==="asc",B=i===y&&c==="desc";if(e.onSortChange){P?e.onSortChange(y,"desc"):B?e.onSortChange("","asc"):e.onSortChange(y,"asc");return}P?(n("desc"),l(y)):B?(n("asc"),l("")):(n("asc"),l(y));},He=(y,P)=>{h(B=>({...B,[y]:P}));},et=y=>{if(y.target.checked){let P=O.map(B=>B[e.rowKey||"id"]);x(P),e.onSelectionChange&&e.onSelectionChange(P);return}x([]),e.onSelectionChange&&e.onSelectionChange([]);},Mt=(y,P)=>{let B=P[e.rowKey||"id"],Q=b.indexOf(B),z=[];Q===-1?z=z.concat(b,B):Q===0?z=z.concat(b.slice(1)):Q===b.length-1?z=z.concat(b.slice(0,-1)):Q>0&&(z=z.concat(b.slice(0,Q),b.slice(Q+1))),x(z),e.onSelectionChange&&e.onSelectionChange(z);},tt=y=>{v(y),e.onPageChange&&e.onPageChange(y);},ot=y=>{D(y),v(0),e.onRowsPerPageChange&&e.onRowsPerPageChange(y);},Dt=y=>{let P=p.indexOf(y),B=[...p];P===-1?B.push(y):B.splice(P,1),f(B);},Pt=y=>{let P=d.indexOf(y),B=[...d];P===-1?B.push(y):B.splice(P,1),L(B);},nt=y=>{e.onLayoutSave&&e.onLayoutSave({visibleColumns:p,order:c,orderBy:i,grouping:d,columnWidths:s});},at=y=>{y.layout&&(y.layout.visibleColumns&&f(y.layout.visibleColumns),y.layout.order&&n(y.layout.order),y.layout.orderBy&&l(y.layout.orderBy),y.layout.grouping&&L(y.layout.grouping),y.layout.columnWidths&&h(y.layout.columnWidths));};co.useEffect(()=>{e.layout&&at({layout:e.layout});},[e.layout]);let Et=y=>{y.preventDefault(),F(A===null?{mouseX:y.clientX+2,mouseY:y.clientY-6}:null);},Bt=()=>{F(null);},Lt=co.useMemo(()=>{if(!k)return {};let y={};e.columns.forEach(B=>{if(B.numeric){let Q=O.reduce((z,Y)=>{let J=parseFloat(Y[B.id]);return z+(isNaN(J)?0:J)},0);y[B.id]=Q.toFixed(2);}else y[B.id]="";});let P=e.columns.find(B=>p.includes(B.id));return P&&!P.numeric&&(y[P.id]="Total"),y},[O,e.columns,k,p]),At=()=>{if(!e.columns||!O)return;let y=e.columns.map(Y=>Y.label).join(","),P=O.map(Y=>e.columns.map(J=>{let U=Y[J.id];return `"${(U==null?"":String(U)).replace(/"/g,'""')}"`}).join(",")).join(`
2
- `),B=`data:text/csv;charset=utf-8,${y}
3
- ${P}`,Q=encodeURI(B),z=document.createElement("a");z.setAttribute("href",Q),z.setAttribute("download",`${e.title||"export"}.csv`),document.body.appendChild(z),z.click(),document.body.removeChild(z);},rt=()=>{G(true);},Vt=()=>{G(false);};return {isMobile:false,columns:e.columns,order:c,orderBy:i,filterText:t,setFilterText:r,visibleColumns:p,setVisibleColumns:f,showSummary:k,setShowSummary:T,summaryColumns:[],grouping:d,setGrouping:L,expandedGroups:a,setExpandedGroups:S,groupAnchorEl:u,setGroupAnchorEl:M,summaryAnchorEl:g,setSummaryAnchorEl:W,columnWidths:s,setColumnWidths:h,anchorEl:I,setAnchorEl:C,contextMenu:A,setContextMenu:F,sensors:void 0,sortedAndFilteredRows:ke,visibleRows:te,summaryRow:Lt,page:m,setPage:tt,rowsPerPage:w,setRowsPerPage:ot,selected:b,setSelected:x,isAllExpanded:false,handleColumnResize:He,handleRequestSort:Rt,handleSelectAllClick:et,handleClick:Mt,toggleSummaryColumn:()=>{},handleDragEnd:()=>{},handleExport:At,handleContextMenu:Et,handleCloseContextMenu:Bt,toggleColumnVisibility:Dt,toggleGroupExpand:Oe,toggleGroupField:Pt,handleToggleAll:It,handleExpandGroupRecursively:kt,handleCollapseGroupRecursively:ze,handleLayoutLoad:()=>{},handleVariantLoad:at,handleLayoutSave:nt,effectiveAppId:e.appId||"",currentLayoutData:{visibleColumns:p,order:c,orderBy:i,grouping:d,columnWidths:s},currentLayoutId:"",layoutIdToLoad:"",onPageChange:tt,onRowsPerPageChange:ot,graphReportOpen:E,handleOpenGraphReport:rt,handleCloseGraphReport:Vt}};var Js=e=>jsxRuntime.jsx(jr__default.default,{...e}),Zs=e=>jsxRuntime.jsx(xo__default.default,{...e}),Qs=e=>jsxRuntime.jsx(fn__default.default,{...e}),ec=e=>jsxRuntime.jsx(Zn__default.default,{...e}),tc=e=>jsxRuntime.jsx(Qn__default.default,{...e}),Tt=e=>{let{title:o="Data Table",selectionMode:t,selected:r=[],onSelectionChange:c,actions:n,extraTools:i,fitContainer:l=false,fullWidth:m=false,maxHeight:v,loading:w=false,page:D=0,rowsPerPage:b=20,rowsPerPageOptions:x=[20,50,100,-1],count:p=0,onPageChange:f,onRowsPerPageChange:k,onLayoutSave:T,filterConfig:d,rowKey:L,tableKey:a="default",graphReport:S}=e,{isMobile:s,columns:h,order:I,orderBy:C,filterText:u,setFilterText:M,visibleColumns:g,showSummary:W,setShowSummary:A,summaryColumns:F,grouping:E,setGrouping:G,expandedGroups:O,groupAnchorEl:ke,setGroupAnchorEl:Ie,summaryAnchorEl:ae,setSummaryAnchorEl:te,columnWidths:Oe,anchorEl:kt,setAnchorEl:ze,contextMenu:It,sensors:Rt,sortedAndFilteredRows:He,summaryRow:et,visibleRows:Mt,isAllExpanded:tt,handleColumnResize:ot,handleRequestSort:Dt,handleSelectAllClick:Pt,handleClick:nt,toggleSummaryColumn:at,handleDragEnd:Et,handleExport:Bt,handleContextMenu:Lt,handleCloseContextMenu:At,toggleColumnVisibility:rt,toggleGroupExpand:Vt,toggleGroupField:y,handleToggleAll:P,handleExpandGroupRecursively:B,handleCollapseGroupRecursively:Q,handleLayoutLoad:z,handleVariantLoad:Y,handleLayoutSave:J,effectiveAppId:U,currentLayoutData:$,currentLayoutId:re,layoutIdToLoad:ie,graphReportOpen:Pe,handleOpenGraphReport:ue,handleCloseGraphReport:Ee}=mn(e),Be=S?.enabled??false,{model:Ft}=zo({rows:He,config:{...S,title:S?.title||`${o} Graphic Report`}}),bn=Ft.table.columns.map(it=>({id:it.id,label:it.label,align:it.align||"left",minWidth:120,numeric:it.align==="right"})),xn=U?jsxRuntime.jsx(dn,{appId:U,tableKey:a,currentLayoutData:$,onLayoutLoad:z,targetLayoutId:ie,activeLayoutId:re,serviceUrl:(d?.variantService,void 0)}):null,lo=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Po,{groupAnchorEl:ke,setGroupAnchorEl:Ie,grouping:E,setGrouping:G,columns:h,toggleGroupField:y}),jsxRuntime.jsx(Eo,{anchorEl:kt,setAnchorEl:ze,columns:h,visibleColumns:g,toggleColumnVisibility:rt}),jsxRuntime.jsx(Bo,{anchorEl:ae,setAnchorEl:te,showSummary:W,setShowSummary:A,columns:h,summaryColumns:F,toggleSummaryColumn:at}),jsxRuntime.jsx(Lo,{contextMenu:It,handleCloseContextMenu:At,columns:h,visibleColumns:g,toggleColumnVisibility:rt})]});return s?jsxRuntime.jsxs(io__default.default,{sx:{display:"flex",flexDirection:"column",gap:2,height:"100%"},children:[d&&jsxRuntime.jsx(Ye,{fields:d.fields,filters:d.filters,onFilterChange:d.onFilterChange,onSearch:d.onSearch,variants:d.variants||[],currentVariantId:d.currentVariantId,onVariantLoad:d.onVariantLoad,onVariantSave:d.onVariantSave,onVariantDelete:d.onVariantDelete,onVariantSetDefault:d.onVariantSetDefault,appId:d.appId,tableKey:a,currentLayout:[{tableKey:a,layoutData:$}],variantService:d.variantService}),jsxRuntime.jsx(Mo,{title:o,loading:w,showSummary:W,setShowSummary:A,setAnchorEl:ze,setSummaryAnchorEl:te,filterText:u,setFilterText:M,sortedAndFilteredRows:He,selected:r,columns:h,visibleColumns:g,summaryRow:et,handleClick:nt,selectionMode:t}),lo]}):jsxRuntime.jsxs(io__default.default,{sx:{width:m?"100%":"auto",mb:l?0:2,...l?{flex:1,display:"flex",flexDirection:"column",minHeight:0,height:"100%"}:{}},children:[d&&jsxRuntime.jsx(io__default.default,{sx:{mb:2},children:jsxRuntime.jsx(Ye,{fields:d.fields,filters:d.filters,onFilterChange:d.onFilterChange,onSearch:d.onSearch,variants:d.variants||[],currentVariantId:d.currentVariantId,onVariantLoad:Y,onVariantSave:d.onVariantSave,onVariantDelete:d.onVariantDelete,onVariantSetDefault:d.onVariantSetDefault,loading:w,appId:d.appId,tableKey:a,currentLayout:[{tableKey:a,layoutData:$}],currentLayoutId:re,layoutRefs:[{tableKey:a,layoutId:re}],variantService:d.variantService})}),jsxRuntime.jsxs(Wr__default.default,{sx:{width:m?"100%":"auto",mb:l?0:2,display:"flex",flexDirection:"column",overflow:"hidden",...v?{height:v}:l?{flex:1,minHeight:0}:{}},children:[jsxRuntime.jsx(bo,{filterText:u,setFilterText:M,onRowsPerPageChange:k,rowsPerPage:b,rowsPerPageOptions:x,page:D,count:p,onPageChange:f,actions:n,extraTools:i,grouping:E,setGroupAnchorEl:Ie,showSummary:W,setShowSummary:A,setAnchorEl:ze,setSummaryAnchorEl:te,handleExport:Bt,onLayoutSave:T||d?.variantService&&d?.appId?J:void 0,loading:w,layoutManager:xn,onOpenGraphReport:Be?ue:void 0}),jsxRuntime.jsx(fn__default.default,{sx:{flex:1,maxHeight:v||"calc(100vh - 320px)",overflowY:"auto",overflowX:"auto",position:"relative",minHeight:0},children:jsxRuntime.jsx(core.DndContext,{sensors:Rt,collisionDetection:core.closestCenter,onDragEnd:Et,modifiers:[modifiers.restrictToHorizontalAxis],children:jsxRuntime.jsxs($r__default.default,{sx:{minWidth:m?750:"auto",width:m?"100%":"auto",tableLayout:Object.keys(Oe).length>0?"fixed":"auto",borderCollapse:"separate",borderSpacing:0},"aria-labelledby":"tableTitle",size:"small",stickyHeader:true,children:[jsxRuntime.jsx(So,{columns:h,visibleColumns:g,order:I,orderBy:C,onRequestSort:Dt,onContextMenu:Lt,selectionMode:t,grouping:E,isAllExpanded:tt,handleToggleAll:P,rowCount:He.length,numSelected:r.length,onSelectAllClick:Pt,columnWidths:Oe,onColumnResize:ot}),jsxRuntime.jsx(wo,{visibleRows:Mt,columns:h,visibleColumns:g,selectionMode:t,selected:r,orderBy:C,loading:w,expandedGroups:O,toggleGroupExpand:Vt,handleExpandGroupRecursively:B,handleCollapseGroupRecursively:Q,handleClick:nt,onSelectionChange:c,grouping:E,rowKeyProp:L,page:D,rowsPerPage:b}),W&&jsxRuntime.jsx(Io,{showSummary:W,columns:h,visibleColumns:g,summaryRow:et,selectionMode:t?.toString(),orderBy:C,zIndex:3})]})})})]}),lo,Be&&jsxRuntime.jsx(Go,{open:Pe,onClose:Ee,model:Ft,tableContent:jsxRuntime.jsx(Tt,{title:"Data Body",columns:bn,rows:Ft.table.rows,rowKey:"id",fullWidth:true,maxHeight:"420px",rowsPerPage:20,rowsPerPageOptions:[20,50,100],graphReport:{enabled:false}})})]})},oc=Tt;var cc=({title:e,hideHeader:o=true,filterConfig:t,tableProps:r,children:c,spacing:n=1})=>jsxRuntime.jsxs(yo,{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(Ye,{...t})}),jsxRuntime.jsx(material.Box,{sx:{flex:1,minHeight:0,overflow:"hidden"},children:jsxRuntime.jsx(Tt,{...r,fitContainer:true,filterConfig:void 0})})]}),c]});var mc=({metadata:e,fetchData:o})=>{let[t,r]=co.useState(false),[c,n]=co.useState([]),[i,l]=co.useState({}),[m,v]=co.useState(e.variants||[]),[w,D]=co.useState(e.layout||null),[b,x]=co.useState(0),[p,f]=co.useState(0),[k,T]=co.useState(10),[d,L]=co.useState([]),[a,S]=co.useState("asc"),[s,h]=co.useState("");co.useEffect(()=>{let E={};e.filters.forEach(G=>{G.defaultValue!==void 0&&(E[G.id]=G.defaultValue);}),l(E);},[e.filters]);let I=co.useCallback(async(E,G,O,ke,Ie)=>{r(true);try{let ae={...E,page:G+1,limit:O,sort:Ie,order:ke},te;o?te=await o(ae):typeof e.api=="function"?te=await e.api(ae):e.api&&typeof e.api=="object"?(console.log("Fetching from URL:",e.api.url,ae),te={rows:[],total:0}):(console.warn("No API configured for report"),te={rows:[],total:0}),te&&(n(te.rows||[]),x(te.total||0));}catch(ae){console.error("Failed to fetch report data",ae);}finally{r(false);}},[e.api,o]);co.useEffect(()=>{I(i,p,k,a,s);},[I,p,k,a,s]);let C=()=>{f(0),I(i,0,k,a,s);},u=(E,G)=>{S(G),h(E);},M=E=>{l(E);},g=E=>{if(E.filters){let G=E.filters.find(O=>O.scope==="default"||O.scope===e.id);G&&(l(G.filters),I(G.filters,0,k));}E.layout&&D(E.layout);},W=E=>{let G={...E,id:Date.now().toString(),createdAt:new Date().toISOString()};v(O=>[...O,G]);},A=E=>{D(E);};return {pageProps:{title:e.title,filterConfig:{appId:e.id,fields:e.filters,filters:i,onFilterChange:M,onSearch:C,onVariantLoad:g,onVariantSave:W,onVariantDelete:E=>v(G=>G.filter(O=>O.id!==E)),onVariantSetDefault:E=>{v(G=>G.map(O=>({...O,isDefault:O.id===E})));},variants:m},tableProps:{appId:e.id,columns:e.columns,rows:c,loading:t,rowKey:"id",count:b,page:p,rowsPerPage:k,rowsPerPageOptions:[10,25,50,100],onPageChange:f,onRowsPerPageChange:T,selectionMode:"multiple",selected:d,onSelectionChange:L,onLayoutSave:A,layout:w,title:e.title,showSummary:true,order:a,orderBy:s,onSortChange:u,graphReport:e.graphReport||{enabled:true,title:`${e.title} Graphic Report`}}},filters:i,rows:c,loading:t,refresh:C}};exports.Button=Gt;exports.CLayoutManagement=sn;exports.CLayoutManager=dn;exports.CPageLayout=yo;exports.CSmartFilter=Ye;exports.CSmartTable=oc;exports.CStandardPage=cc;exports.CTable=Tt;exports.CTableBody=Js;exports.CTableCell=Zs;exports.CTableContainer=Qs;exports.CTableHead=ec;exports.CTableRow=tc;exports.CVariantManagement=gt;exports.CVariantManager=Ko;exports.NavigationIsland=wi;exports.TreeMenu=zt;exports.buttonVariants=wn;exports.useNavigationIsland=Mi;exports.useStandardReport=mc;
1
+ 'use strict';var bo=require('react'),navigation=require('next/navigation'),lucideReact=require('lucide-react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),reactSlot=require('@radix-ui/react-slot'),classVarianceAuthority=require('class-variance-authority'),jsxRuntime=require('react/jsx-runtime'),material=require('@mui/material'),mo=require('@mui/material/Box'),oi=require('@mui/material/Paper'),ni=require('@mui/material/Table'),ai=require('@mui/material/TableBody'),Do=require('@mui/material/TableCell'),wn=require('@mui/material/TableContainer'),pa=require('@mui/material/TableHead'),ma=require('@mui/material/TableRow'),core=require('@dnd-kit/core'),modifiers=require('@dnd-kit/modifiers'),cn=require('@mui/icons-material/Search'),na=require('@mui/icons-material/ViewColumn'),yn=require('@mui/icons-material/Save'),ra=require('@mui/icons-material/Download'),ia=require('@mui/icons-material/AccountTree'),la=require('@mui/icons-material/Functions'),sa=require('@mui/icons-material/Insights'),ga=require('@mui/material/Checkbox'),fa=require('@mui/material/TableSortLabel'),Ca=require('@mui/icons-material/KeyboardArrowRight'),va=require('@mui/icons-material/KeyboardArrowDown'),La=require('@mui/icons-material/Check'),Aa=require('@mui/icons-material/ClearAll'),Ua=require('@mui/icons-material/Close'),Br=require('@mui/icons-material/Settings'),Lr=require('@mui/icons-material/KeyboardArrowUp'),Fr=require('@mui/icons-material/ArrowRightAlt'),rr=require('@mui/icons-material/Star'),DateCalendar=require('@mui/x-date-pickers/DateCalendar'),PickersDay=require('@mui/x-date-pickers/PickersDay'),Cr=require('@mui/icons-material/CalendarMonth'),vr=require('@mui/icons-material/Clear'),Sr=require('@mui/icons-material/ArrowForward'),De=require('dayjs'),Tr=require('dayjs/plugin/isBetween'),Kr=require('@mui/icons-material/Delete'),qr=require('@mui/icons-material/StarBorder'),Xr=require('@mui/icons-material/ViewQuilt'),Ti=require('@mui/icons-material/Language'),wi=require('@mui/icons-material/DesktopWindows'),Ii=require('@mui/icons-material/DarkMode'),ki=require('@mui/icons-material/LightMode');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var bo__namespace=/*#__PURE__*/_interopNamespace(bo);var mo__default=/*#__PURE__*/_interopDefault(mo);var oi__default=/*#__PURE__*/_interopDefault(oi);var ni__default=/*#__PURE__*/_interopDefault(ni);var ai__default=/*#__PURE__*/_interopDefault(ai);var Do__default=/*#__PURE__*/_interopDefault(Do);var wn__default=/*#__PURE__*/_interopDefault(wn);var pa__default=/*#__PURE__*/_interopDefault(pa);var ma__default=/*#__PURE__*/_interopDefault(ma);var cn__default=/*#__PURE__*/_interopDefault(cn);var na__default=/*#__PURE__*/_interopDefault(na);var yn__default=/*#__PURE__*/_interopDefault(yn);var ra__default=/*#__PURE__*/_interopDefault(ra);var ia__default=/*#__PURE__*/_interopDefault(ia);var la__default=/*#__PURE__*/_interopDefault(la);var sa__default=/*#__PURE__*/_interopDefault(sa);var ga__default=/*#__PURE__*/_interopDefault(ga);var fa__default=/*#__PURE__*/_interopDefault(fa);var Ca__default=/*#__PURE__*/_interopDefault(Ca);var va__default=/*#__PURE__*/_interopDefault(va);var La__default=/*#__PURE__*/_interopDefault(La);var Aa__default=/*#__PURE__*/_interopDefault(Aa);var Ua__default=/*#__PURE__*/_interopDefault(Ua);var Br__default=/*#__PURE__*/_interopDefault(Br);var Lr__default=/*#__PURE__*/_interopDefault(Lr);var Fr__default=/*#__PURE__*/_interopDefault(Fr);var rr__default=/*#__PURE__*/_interopDefault(rr);var Cr__default=/*#__PURE__*/_interopDefault(Cr);var vr__default=/*#__PURE__*/_interopDefault(vr);var Sr__default=/*#__PURE__*/_interopDefault(Sr);var De__default=/*#__PURE__*/_interopDefault(De);var Tr__default=/*#__PURE__*/_interopDefault(Tr);var Kr__default=/*#__PURE__*/_interopDefault(Kr);var qr__default=/*#__PURE__*/_interopDefault(qr);var Xr__default=/*#__PURE__*/_interopDefault(Xr);var Ti__default=/*#__PURE__*/_interopDefault(Ti);var wi__default=/*#__PURE__*/_interopDefault(wi);var Ii__default=/*#__PURE__*/_interopDefault(Ii);var ki__default=/*#__PURE__*/_interopDefault(ki);function re(...e){return tailwindMerge.twMerge(clsx.clsx(e))}var $t={primary:"#000000",primaryHover:"#333333"},dt={primary:"bg-primary text-primary-foreground hover:bg-primary/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",ghost:"hover:bg-accent hover:text-accent-foreground"},$e={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",full:"rounded-full"},yo=()=>"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50";var Hn=classVarianceAuthority.cva(yo(),{variants:{variant:{default:`${dt.primary} shadow-sm`,destructive:"bg-red-500 text-white hover:bg-red-600 active:bg-red-700 dark:bg-red-600 dark:hover:bg-red-500 dark:active:bg-red-700 shadow-sm",outline:`${dt.outline} shadow-sm`,secondary:"bg-gray-200 text-gray-700 hover:bg-gray-300 active:bg-gray-400 dark:bg-gray-700 dark:text-gray-200 dark:hover:bg-gray-600 dark:active:bg-gray-500 shadow-sm",ghost:dt.ghost,link:"text-blue-600 dark:text-blue-400 underline-offset-4 hover:underline hover:text-blue-700 dark:hover:text-blue-300 active:text-blue-800 dark:active:text-blue-200","chat-tool":"bg-[var(--orbai-surface-2)] border border-[var(--orbai-border-soft)] text-[var(--orbai-text-2)] hover:bg-[var(--orbai-surface-3)] hover:border-[var(--orbai-border-strong)] hover:text-[var(--orbai-text-1)] active:scale-95 transition-all duration-200","chat-send":`bg-[${$t.primary}] hover:bg-[${$t.primaryHover}] text-white border border-[var(--orbai-border-strong)] shadow-[var(--orbai-shadow-soft-sm)] hover:shadow-[var(--orbai-shadow-soft-md)] active:scale-95 transition-all duration-200`,"chat-stop":"bg-red-500 hover:bg-red-600 border border-[var(--orbai-border-strong)] shadow-[var(--orbai-shadow-soft-sm)] hover:shadow-[var(--orbai-shadow-soft-md)] active:scale-95 text-white transition-all duration-200","chat-disabled":"cursor-not-allowed opacity-50 bg-[var(--orbai-surface-2)] border border-[var(--orbai-border-soft)] text-[var(--orbai-muted)]"},size:{default:"h-10 px-4 py-2",sm:"h-9 px-3",lg:"h-11 px-8",icon:"h-10 w-10","chat-sm":"h-8 w-8 rounded-full","chat-md":"h-10 w-10 rounded-full","chat-lg":"h-12 w-12 rounded-full"},rounded:{none:$e.none,sm:$e.sm,md:$e.md,full:$e.full}},defaultVariants:{variant:"default",size:"default",rounded:"md"}}),_t=bo__namespace.forwardRef(({className:e,variant:o,size:t,asChild:i=false,...s},a)=>jsxRuntime.jsx(i?reactSlot.Slot:"button",{className:re(Hn({variant:o,size:t,className:e})),ref:a,...s}));_t.displayName="Button";function Ut({items:e,onItemClick:o,className:t="",level:i=0,expandedIds:s,onToggleExpand:a,colorMode:l="light"}){let n=l==="dark",u=navigation.usePathname(),[v,w]=bo.useState(new Set),S=s!==void 0&&a!==void 0,x=S?s:v,P=m=>{if(S)a(m);else {let g=new Set(v);g.has(m)?g.delete(m):g.add(m),w(g);}},k=m=>{m.children&&m.children.length>0&&P(m.id),o&&o(m);};return !e||!Array.isArray(e)?jsxRuntime.jsx("div",{className:re("tree-menu",t),children:jsxRuntime.jsx("div",{className:"text-sm text-gray-500 p-2",children:"No items to display"})}):jsxRuntime.jsx("div",{className:re("tree-menu",t),children:e.map(m=>{let g=x.has(m.id)||m.isExpanded,y=m.children&&m.children.length>0,d=m.appurl||m.href,I=d?u===d:false;return jsxRuntime.jsxs("div",{className:"tree-menu-item relative",children:[I&&jsxRuntime.jsx("div",{className:re("absolute left-0 top-2 bottom-2 w-[3px] rounded-r-full z-10",n?"bg-[#90caf9]":"bg-[#1976d2]")}),jsxRuntime.jsxs(_t,{variant:"ghost",className:re("w-full justify-start gap-2 h-auto py-2 relative overflow-hidden group",`ml-${i*4}`,I?n?"bg-transparent text-[#90caf9] hover:bg-gray-800/35":"bg-transparent text-[#1976d2] hover:bg-gray-100/60":n?"hover:bg-gray-800/50 text-gray-300":"hover:bg-gray-100/50 text-gray-700"),onClick:()=>k(m),children:[y&&jsxRuntime.jsx("div",{className:re("flex-shrink-0 transition-transform duration-200",g&&"rotate-90",I?n?"text-[#90caf9]":"text-[#1976d2]":n?"text-gray-500 group-hover:text-gray-300":"text-gray-400 group-hover:text-gray-600"),children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-4 w-4"})}),!y&&jsxRuntime.jsx("div",{className:"w-4 h-4 flex-shrink-0"}),m.icon&&jsxRuntime.jsx("div",{className:re("flex-shrink-0 transition-colors duration-200",I?n?"text-[#90caf9]":"text-[#1976d2]":n?"text-gray-500 group-hover:text-gray-300":"text-gray-400 group-hover:text-gray-600"),children:m.icon}),jsxRuntime.jsxs("div",{className:"flex-1 text-left overflow-hidden z-10",children:[jsxRuntime.jsx("div",{className:re("text-sm truncate transition-colors duration-200",I?"font-semibold":"font-medium"),children:m.title||m.label}),m.description&&jsxRuntime.jsx("div",{className:re("text-xs truncate transition-colors duration-200",I?n?"text-[#90caf9]/70":"text-[#1976d2]/75":n?"text-gray-400":"text-gray-500"),title:m.description,children:m.description})]})]}),y&&jsxRuntime.jsx("div",{className:re("grid transition-[grid-template-rows] duration-300 ease-in-out",g?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:jsxRuntime.jsx("div",{className:"overflow-hidden",children:jsxRuntime.jsx(Ut,{items:m.children,onItemClick:o,level:i+1,expandedIds:s,onToggleExpand:a,colorMode:l})})})]},m.id)})})}var To=({collapsed:e,onToggle:o,className:t="",maxHeight:i,menuData:s=[],colorMode:a="light"})=>{let l=a==="dark",n=navigation.useRouter(),[u,v]=bo.useState(""),[w,S]=bo.useState(new Set);bo.useEffect(()=>{e&&S(new Set);},[e]);let x=bo.useCallback(g=>{let y=[],d=I=>{I.forEach(r=>{y.push(r.id),r.children&&d(r.children);});};return d(g),y},[]),P=bo.useMemo(()=>{if(!u.trim())return s;let g=y=>y.reduce((d,I)=>{let r=I.title?.toLowerCase().includes(u.toLowerCase())||I.description?.toLowerCase().includes(u.toLowerCase()),b=I.children?g(I.children):[];return (r||b.length>0)&&d.push({...I,children:b.length>0?b:I.children}),d},[]);return g(s)},[u,s]),k=bo.useMemo(()=>u.trim()?new Set(x(s)):w,[u,s,w,x]),m=bo.useCallback(async g=>{if(console.log("\u{1F5B1}\uFE0F \u5BFC\u822A\u83DC\u5355\u9879\u70B9\u51FB:",g),g.id==="chat"||g.appurl==="/chat"){console.log("\u{1F4AC} \u68C0\u6D4B\u5230chat\u83DC\u5355\u70B9\u51FB\uFF0C\u8DF3\u8F6C\u5230\u65B0\u7684\u804A\u5929\u89C6\u56FE");try{n.push("/chat?new=true");}catch(d){console.error("\u274C \u65E0\u6CD5\u8DF3\u8F6C\u5230\u65B0\u804A\u5929\u89C6\u56FE:",d),n.push("/chat");}return}let y=g.appurl||g.href;y&&(y.startsWith("http://")||y.startsWith("https://")?window.open(y,"_blank"):n.push(y));},[n]);return jsxRuntime.jsxs("div",{className:`flex flex-col backdrop-blur-xl border shadow-[0_4px_8px_0_rgba(31,38,135,0.1)] ${e?"w-14 rounded-full":"w-[234px] rounded-2xl"} relative ${t} ${l?"bg-[#111111] border-white/10":"bg-white/70 border-white/30"}`,style:{backdropFilter:"blur(16px) saturate(180%)",WebkitBackdropFilter:"blur(16px) saturate(180%)",transition:"width 400ms cubic-bezier(0.4, 0.0, 0.2, 1), border-radius 0ms cubic-bezier(0.4, 0.0, 0.2, 1), box-shadow 400ms ease-out",maxHeight:i?`${i}px`:void 0},children:[jsxRuntime.jsx("div",{className:`pt-4 pb-2 transition-all duration-500 ease-in-out ${e?"px-1":"px-2"}`,children:e?jsxRuntime.jsx("div",{className:"flex justify-center",children:jsxRuntime.jsx("button",{onClick:o,className:`w-10 h-10 flex items-center justify-center rounded-lg transition-colors duration-200 ${l?"text-gray-300 hover:bg-gray-800":"text-gray-500 hover:bg-gray-50"}`,title:"\u5C55\u5F00\u5BFC\u822A",children:jsxRuntime.jsx(lucideReact.Search,{className:"h-5 w-5"})})}):jsxRuntime.jsxs("div",{className:`relative transition-opacity duration-300 ${e?"opacity-0":"opacity-100 delay-200"}`,children:[jsxRuntime.jsx("input",{type:"text",placeholder:"\u641C\u7D22\u83DC\u5355...",value:u,onChange:g=>v(g.target.value),className:`w-full pl-10 pr-4 py-2 text-sm border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent ${l?"border-gray-700 bg-[#1A1A1A] text-white placeholder-gray-400":"border-gray-300 bg-white text-gray-900 placeholder-gray-500"}`}),jsxRuntime.jsx("div",{className:"absolute left-3 top-1/2 transform -translate-y-1/2 pointer-events-none",children:jsxRuntime.jsx(lucideReact.Search,{className:`h-4 w-4 ${l?"text-gray-500":"text-gray-400"}`})})]})}),jsxRuntime.jsx("nav",{className:`flex-1 pb-4 transition-all duration-500 ease-in-out overflow-y-auto min-h-0 ${e?"px-1":"px-2"}`,children:P.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8 text-gray-500 text-sm",children:e?"\u{1F4C2}":u?"\u672A\u627E\u5230\u5339\u914D\u7684\u83DC\u5355\u9879":"\u6682\u65E0\u53EF\u8BBF\u95EE\u7684\u5E94\u7528"}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[!e&&jsxRuntime.jsx("div",{className:`transition-opacity duration-300 ${e?"opacity-0":"opacity-100 delay-200"}`,children:jsxRuntime.jsx(Ut,{items:P,onItemClick:m,className:"space-y-1",expandedIds:k,colorMode:a,onToggleExpand:g=>{let y=new Set(w);P.some(I=>I.id===g)?y.has(g)?y.delete(g):(P.forEach(I=>{I.id!==g&&y.has(I.id)&&y.delete(I.id);}),y.add(g)):y.has(g)?y.delete(g):y.add(g),S(y);}})}),e&&jsxRuntime.jsx("div",{className:"space-y-2",children:s.map(g=>jsxRuntime.jsx("div",{className:"space-y-1",children:jsxRuntime.jsx("button",{onClick:()=>{o();let y=new Set([g.id]);S(y);},className:`w-full flex items-center justify-center p-2 rounded-lg cursor-pointer transition-colors duration-200 ${l?"text-gray-400 hover:bg-gray-800":"text-gray-600 hover:bg-gray-50"}`,title:`\u5C55\u5F00\u67E5\u770B ${g.title}`,children:g.icon||jsxRuntime.jsx("div",{className:`w-6 h-6 rounded text-xs flex items-center justify-center font-medium ${l?"bg-[#90caf9] text-[#0b0b0b]":"bg-[#1976d2] text-white"}`,children:g.title?.charAt(0)||"?"})})},g.id))})]})}),!e&&jsxRuntime.jsx("button",{onClick:o,className:`absolute -bottom-1 -right-1 w-6 h-6 bg-transparent rounded-full flex items-center justify-center transition-all duration-300 ease-in-out z-20 ${l?"hover:bg-gray-800/50":"hover:bg-white/20"}`,title:"\u6298\u53E0\u5BFC\u822A",children:jsxRuntime.jsx("div",{className:"absolute",style:{bottom:"0px",right:"0px",width:"16px",height:"16px",overflow:"hidden"},children:jsxRuntime.jsx("div",{className:l?"border-yellow-400":"",style:{width:"32px",height:"32px",borderRadius:"16px",border:"3px solid #21BCFF",backgroundColor:"transparent",position:"absolute",top:"-16px",left:"-16px"}})})})]})};var Io=(e={})=>{let{initialCollapsed:o=false,content:t=[]}=e,[i,s]=bo.useState(o),[a,l]=bo.useState(t),n=bo.useCallback(()=>{s(v=>!v);},[]),u=bo.useMemo(()=>({collapsed:i,onToggle:n,menuData:a}),[i,n,a]);return {collapsed:i,setCollapsed:s,toggleCollapsed:n,menuData:a,setMenuData:l,navigationIslandProps:u}};var ko=({title:e,hideHeader:o,children:t})=>jsxRuntime.jsxs(material.Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[!o&&jsxRuntime.jsx(material.Box,{sx:{mb:2},children:jsxRuntime.jsx(material.Typography,{variant:"h4",children:e})}),jsxRuntime.jsx(material.Box,{sx:{flex:1,overflow:"hidden"},children:t})]});var Ro=e=>{let o="0.75rem";return jsxRuntime.jsxs(material.Toolbar,{sx:{pl:{sm:2},pr:{xs:1,sm:1},alignItems:"center"},children:[jsxRuntime.jsx(material.Typography,{sx:{flex:"1 1 100%",fontWeight:"bold"},variant:"h6",id:"tableTitle",component:"div",children:e.title||"Table"}),jsxRuntime.jsxs(material.Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsxRuntime.jsx(material.TextField,{size:"small",placeholder:"Search...",value:e.filterText,onChange:t=>e.setFilterText(t.target.value),InputProps:{sx:{fontSize:o,"& .MuiInputBase-input":{fontSize:o},"& .MuiInputBase-input::placeholder":{fontSize:o,opacity:1}},startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(cn__default.default,{fontSize:"small"})})},sx:{width:300}}),jsxRuntime.jsx(material.Tooltip,{title:"Group By",children:jsxRuntime.jsx(material.IconButton,{onClick:t=>e.setGroupAnchorEl(t.currentTarget),children:jsxRuntime.jsx(material.Badge,{badgeContent:e.grouping?.length,color:"primary",children:jsxRuntime.jsx(ia__default.default,{})})})}),jsxRuntime.jsx(material.Tooltip,{title:"Summary",children:jsxRuntime.jsx(material.IconButton,{onClick:t=>e.setSummaryAnchorEl(t.currentTarget),color:e.showSummary?"primary":"default",children:jsxRuntime.jsx(la__default.default,{})})}),jsxRuntime.jsx(material.Tooltip,{title:"Columns",children:jsxRuntime.jsx(material.IconButton,{onClick:t=>e.setAnchorEl(t.currentTarget),children:jsxRuntime.jsx(na__default.default,{})})}),jsxRuntime.jsx(material.Tooltip,{title:"Export",children:jsxRuntime.jsx(material.IconButton,{onClick:e.handleExport,children:jsxRuntime.jsx(ra__default.default,{})})}),e.onOpenGraphReport&&jsxRuntime.jsx(material.Tooltip,{title:"Graphic Report",children:jsxRuntime.jsx(material.IconButton,{onClick:e.onOpenGraphReport,children:jsxRuntime.jsx(sa__default.default,{})})}),e.onLayoutSave&&!e.layoutManager&&jsxRuntime.jsx(material.Tooltip,{title:"Save Layout",children:jsxRuntime.jsx(material.IconButton,{onClick:t=>e.onLayoutSave(t),children:jsxRuntime.jsx(yn__default.default,{})})}),e.layoutManager]})]})};var Bo=e=>{let{onSelectAllClick:o,order:t,orderBy:i,numSelected:s=0,rowCount:a=0,onRequestSort:l,columns:n,visibleColumns:u,selectionMode:v,onColumnResize:w,columnWidths:S}=e,[x,P]=bo.useState(null),k=bo.useRef(null),m=r=>b=>{x||l(r);},g=(r,b,c)=>{r.preventDefault(),r.stopPropagation(),P(b),k.current={startX:r.clientX,startWidth:c,colId:b},document.addEventListener("mousemove",y),document.addEventListener("mouseup",d),document.body.style.cursor="col-resize";},y=r=>{if(!k.current)return;let{startX:b,startWidth:c,colId:C}=k.current,M=r.clientX-b,T=Math.max(50,c+M);w&&w(C,T);},d=()=>{P(null),k.current=null,document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",d),document.body.style.cursor="";};return bo.useEffect(()=>()=>{document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",d);},[]),jsxRuntime.jsx(pa__default.default,{children:jsxRuntime.jsxs(ma__default.default,{children:[(v==="multiple"||v==="single")&&jsxRuntime.jsx(Do__default.default,{padding:"checkbox",sx:r=>({width:48,backgroundColor:r.palette.mode==="dark"?"#000000":"#f5f5f5",color:r.palette.mode==="dark"?"#ffffff":r.palette.text.primary}),children:jsxRuntime.jsx(ga__default.default,{color:"primary",indeterminate:s>0&&s<a,checked:a>0&&s===a,onChange:o,disabled:v==="single"})}),n.filter(r=>u.includes(r.id)).map(r=>{let b=S?.[r.id]||r.minWidth||100;return jsxRuntime.jsxs(Do__default.default,{align:"left",padding:r.disablePadding?"none":"normal",sortDirection:i===r.id?t:false,style:{width:b,minWidth:b,maxWidth:b},sx:c=>({position:"relative",backgroundColor:c.palette.mode==="dark"?"#000000":"#f5f5f5",color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary,fontWeight:"bold",userSelect:"none"}),children:[jsxRuntime.jsx(fa__default.default,{active:i===r.id,direction:i===r.id?t:"asc",onClick:m(r.id),sx:c=>({"&.MuiTableSortLabel-root":{width:"100%"},"& .MuiTableSortLabel-icon":{color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary,opacity:i===r.id?1:0,transition:"opacity 0.2s"},"&:hover .MuiTableSortLabel-icon":{opacity:.5},"&.Mui-active .MuiTableSortLabel-icon":{opacity:1,color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary},fontWeight:"bold",color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary}),children:jsxRuntime.jsx(mo__default.default,{component:"span",sx:{overflow:"visible",textOverflow:"clip",whiteSpace:"normal",lineHeight:1.2,wordBreak:"break-word",pr:1},children:r.label})}),jsxRuntime.jsx(mo__default.default,{onMouseDown:c=>g(c,r.id,typeof b=="number"?b:100),onClick:c=>c.stopPropagation(),sx:{position:"absolute",right:0,top:0,bottom:0,width:5,cursor:"col-resize","&:hover":{backgroundColor:"primary.main",opacity:.5},zIndex:1}})]},r.id)})]})})};var Ao=e=>{let{visibleRows:o,visibleColumns:t,selected:i=[],handleClick:s,columns:a,toggleGroupExpand:l,expandedGroups:n=new Set,selectionMode:u}=e,v=x=>i.indexOf(x)!==-1,w=u==="multiple"||u==="single",S=t.length+(w?1:0);return jsxRuntime.jsxs(material.TableBody,{children:[o.map((x,P)=>{if(x.type==="group"){let k=n.has(x.id),m=x.childIds||[],g=m.filter(r=>v(r)).length,y=m.length>0&&g===m.length,d=g>0&&g<m.length,I=r=>{if(r.stopPropagation(),!!e.onSelectionChange)if(y){let b=i.filter(c=>!m.includes(c));e.onSelectionChange(b);}else {let b=Array.from(new Set([...i,...m]));e.onSelectionChange(b);}};return jsxRuntime.jsx(material.TableRow,{sx:{backgroundColor:"#f5f5f5"},children:jsxRuntime.jsx(material.TableCell,{colSpan:S,sx:{py:1,pl:x.level*4+2},children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center"},children:[jsxRuntime.jsx(material.IconButton,{size:"small",onClick:()=>l&&l(x.id),sx:{mr:1},children:k?jsxRuntime.jsx(va__default.default,{}):jsxRuntime.jsx(Ca__default.default,{})}),w&&jsxRuntime.jsx(material.Checkbox,{size:"small",checked:y,indeterminate:d,onChange:I,onClick:r=>r.stopPropagation(),sx:{mr:1,p:.5}}),jsxRuntime.jsxs(material.Typography,{variant:"body2",fontWeight:"bold",children:[x.field,": ",x.value," (",x.count,")"]})]})})},x.id)}else {let k=x.data||x,m=x.id||k.id||P,g=v(m),y=`enhanced-table-checkbox-${P}`,I=(x.level!==void 0?x.level:0)*4;return jsxRuntime.jsxs(material.TableRow,{hover:true,onClick:r=>s&&s(r,k),role:"checkbox","aria-checked":g,tabIndex:-1,selected:g,sx:{cursor:"pointer"},children:[w&&jsxRuntime.jsx(material.TableCell,{padding:"checkbox",sx:{pl:I>0?I+1:void 0},children:jsxRuntime.jsx(material.Checkbox,{color:"primary",checked:g,inputProps:{"aria-labelledby":y}})}),a.filter(r=>t.includes(r.id)).map((r,b)=>{let C=!w&&b===0&&I>0?{pl:I+2}:{};return jsxRuntime.jsx(material.TableCell,{align:"left",sx:C,children:r.render?r.render(k[r.id],k):(function(){let T=k[r.id];if(r.numeric){if(typeof T=="number")return T.toLocaleString();if(typeof T=="string"&&T.trim()!==""&&!isNaN(Number(T)))return Number(T).toLocaleString()}return T})()},r.id)})]},m)}}),o.length===0&&jsxRuntime.jsx(material.TableRow,{children:jsxRuntime.jsx(material.TableCell,{colSpan:S,align:"center",children:"No data"})})]})};var Vo=e=>{let{visibleColumns:o,summaryRow:t,selectionMode:i}=e;if(!e.showSummary)return null;let s=i==="multiple"||i==="single";return jsxRuntime.jsx(material.TableFooter,{sx:{position:"sticky",bottom:0,zIndex:e.zIndex,bgcolor:"background.paper"},children:jsxRuntime.jsxs(material.TableRow,{children:[s&&jsxRuntime.jsx(material.TableCell,{padding:"checkbox",sx:{bgcolor:"background.paper"}}),o.map(a=>jsxRuntime.jsx(material.TableCell,{sx:{fontWeight:"bold",fontSize:"0.875rem",bgcolor:"background.paper",color:"text.primary"},children:(function(){let n=t[a];return n==null||n===""?"":typeof n=="number"?n.toLocaleString():typeof n=="string"&&n.trim()!==""&&!isNaN(Number(n))?Number(n).toLocaleString():n})()},a))]})})};var Ho=e=>jsxRuntime.jsx(material.Box,{sx:{p:2},children:jsxRuntime.jsx(material.Typography,{children:"Mobile View Not Implemented"})});var Oo=({groupAnchorEl:e,setGroupAnchorEl:o,grouping:t,setGrouping:i,columns:s,toggleGroupField:a})=>jsxRuntime.jsxs(material.Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsxRuntime.jsxs(material.Box,{sx:{p:1,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[jsxRuntime.jsx(material.Typography,{variant:"subtitle2",sx:{px:1},children:"Group By"}),t.length>0&&jsxRuntime.jsx(material.Button,{size:"small",color:"error",onClick:()=>i([]),startIcon:jsxRuntime.jsx(Aa__default.default,{}),children:"Clear All"})]}),jsxRuntime.jsx(material.Divider,{}),s.map(l=>{let n=t.includes(l.id),u=t.indexOf(l.id)+1;return jsxRuntime.jsx(material.MenuItem,{onClick:()=>a(l.id),children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsxRuntime.jsx(material.Checkbox,{checked:n,size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:l.label}),n&&jsxRuntime.jsx(material.Badge,{badgeContent:u,color:"primary",sx:{mr:2}})]})},l.id)})]}),Go=({anchorEl:e,setAnchorEl:o,columns:t,visibleColumns:i,toggleColumnVisibility:s})=>jsxRuntime.jsxs(material.Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.ListItemText,{primary:"Visible Columns"})}),jsxRuntime.jsx(material.Divider,{}),t.map(a=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>s(a.id),children:[jsxRuntime.jsx(material.Checkbox,{checked:i.includes(a.id),size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:a.label})]},a.id))]}),Wo=({anchorEl:e,setAnchorEl:o,showSummary:t,setShowSummary:i,columns:s,summaryColumns:a,toggleSummaryColumn:l})=>jsxRuntime.jsxs(material.Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsxRuntime.jsx(material.MenuItem,{children:jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Switch,{checked:t,onChange:n=>i(n.target.checked),size:"small"}),label:"Show Summary Row"})}),jsxRuntime.jsx(material.Divider,{}),s.filter(n=>n.numeric).map(n=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>l(n.id),disabled:!t,children:[jsxRuntime.jsx(material.Checkbox,{checked:a.includes(n.id),size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:n.label})]},n.id)),s.filter(n=>n.numeric).length===0&&jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.ListItemText,{primary:"No numeric columns"})})]}),$o=({contextMenu:e,handleCloseContextMenu:o,columns:t,visibleColumns:i,toggleColumnVisibility:s})=>jsxRuntime.jsxs(material.Menu,{open:e!==null,onClose:o,anchorReference:"anchorPosition",anchorPosition:e!==null?{top:e.mouseY,left:e.mouseX}:void 0,children:[jsxRuntime.jsx(material.MenuItem,{onClick:o,children:"Copy"}),jsxRuntime.jsx(material.Divider,{}),jsxRuntime.jsx(material.MenuItem,{disabled:true,children:"Visible Columns"}),t.map(a=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>s(a.id),children:[jsxRuntime.jsx(material.ListItemIcon,{children:i.includes(a.id)&&jsxRuntime.jsx(La__default.default,{fontSize:"small"})}),jsxRuntime.jsx(material.ListItemText,{children:a.label})]},a.id))]});var _e=(e,o=2)=>e.toLocaleString(void 0,{maximumFractionDigits:o}),jo=({kpis:e})=>{let o=[{label:"Total Records",value:_e(e.totalRecords,0),color:"text.primary"},{label:"Total Report",value:_e(e.totalReportHours),color:"text.primary"},{label:"Total Billable",value:_e(e.totalBillableHours),color:"success.main"},{label:"Efficiency",value:`${e.efficiency.toFixed(2)}%`,color:"warning.main"},{label:"Amount",value:_e(e.totalAmount),color:"info.main"},{label:"Flagged",value:_e(e.flaggedCount,0),color:"error.main"}];return jsxRuntime.jsx(material.Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"repeat(2, minmax(0, 1fr))",lg:"repeat(6, minmax(0, 1fr))"},gap:1.5},children:o.map(t=>jsxRuntime.jsxs(material.Paper,{variant:"outlined",sx:{p:1.5,borderRadius:2,minHeight:96,display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",children:t.label}),jsxRuntime.jsx(material.Typography,{variant:"h4",fontWeight:800,sx:{color:t.color},children:t.value})]},t.label))})};var ft=["#1E88E5","#1ABC9C","#FBC02D","#EF5350","#7E57C2","#78909C"],za=({data:e})=>{let o=Math.max(...e.map(t=>t.value),1);return jsxRuntime.jsx(material.Stack,{spacing:1,children:e.map(t=>jsxRuntime.jsxs(material.Box,{sx:{display:"grid",gridTemplateColumns:"140px 1fr 64px",gap:1},children:[jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",noWrap:true,title:t.name,children:t.name}),jsxRuntime.jsx(material.Box,{sx:{alignSelf:"center",bgcolor:"action.hover",height:10,borderRadius:999,overflow:"hidden"},children:jsxRuntime.jsx(material.Box,{sx:{width:`${t.value/o*100}%`,height:"100%",bgcolor:"primary.main"}})}),jsxRuntime.jsx(material.Typography,{variant:"caption",sx:{textAlign:"right",fontWeight:600},children:t.value.toFixed(1)})]},t.name))})},Oa=({data:e})=>{let o=Math.max(...e.map(t=>t.value),1);return jsxRuntime.jsx(material.Box,{sx:{display:"flex",gap:1,alignItems:"flex-end",minHeight:210},children:e.map(t=>jsxRuntime.jsxs(material.Box,{sx:{flex:1,minWidth:0},children:[jsxRuntime.jsx(material.Box,{sx:{height:`${Math.max(t.value/o*180,6)}px`,bgcolor:"primary.main",borderRadius:"8px 8px 0 0"}}),jsxRuntime.jsx(material.Typography,{variant:"caption",noWrap:true,title:t.name,sx:{display:"block",mt:.5},children:t.name}),jsxRuntime.jsxs(material.Typography,{variant:"caption",color:"text.secondary",children:[t.value.toFixed(1),"%"]})]},t.name))})},Ga=({data:e})=>{if(e.length===0)return jsxRuntime.jsx(material.Typography,{variant:"body2",color:"text.secondary",children:"No data"});let o=0,i=`conic-gradient(${e.map((s,a)=>{let l=o;return o+=s.percent,`${ft[a%ft.length]} ${l}% ${o}%`}).join(", ")})`;return jsxRuntime.jsxs(material.Stack,{direction:{xs:"column",sm:"row"},spacing:2,alignItems:"center",children:[jsxRuntime.jsx(material.Box,{sx:{width:180,height:180,borderRadius:"50%",background:i,position:"relative"},children:jsxRuntime.jsx(material.Box,{sx:{position:"absolute",inset:30,bgcolor:"background.paper",borderRadius:"50%"}})}),jsxRuntime.jsx(material.Stack,{spacing:1,sx:{minWidth:180},children:e.map((s,a)=>jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsxRuntime.jsx(material.Box,{sx:{width:10,height:10,borderRadius:"50%",bgcolor:ft[a%ft.length]}}),jsxRuntime.jsx(material.Typography,{variant:"caption",sx:{flex:1},children:s.name}),jsxRuntime.jsxs(material.Typography,{variant:"caption",sx:{fontWeight:700},children:[s.percent.toFixed(0),"%"]})]},s.name))})]})},eo=({title:e,subtitle:o,children:t})=>jsxRuntime.jsxs(material.Paper,{variant:"outlined",sx:{p:2,borderRadius:2},children:[jsxRuntime.jsx(material.Typography,{variant:"subtitle1",fontWeight:700,children:e}),jsxRuntime.jsx(material.Typography,{variant:"body2",color:"text.secondary",sx:{mb:2},children:o}),t]}),Uo=({billableByPrimary:e,efficiencyBySecondary:o,statusDistribution:t})=>jsxRuntime.jsxs(material.Box,{sx:{display:"grid",gap:1.5,gridTemplateColumns:{xs:"1fr",lg:"1.2fr 1.2fr 1fr"}},children:[jsxRuntime.jsx(eo,{title:"Billable by Dimension",subtitle:"Top values by billable hours",children:jsxRuntime.jsx(za,{data:e})}),jsxRuntime.jsx(eo,{title:"Efficiency by Person",subtitle:"Lowest efficiency first",children:jsxRuntime.jsx(Oa,{data:o})}),jsxRuntime.jsx(eo,{title:"Status Distribution",subtitle:"Record ratio by status",children:jsxRuntime.jsx(Ga,{data:t})})]});var Yo=({open:e,onClose:o,model:t,tableContent:i})=>jsxRuntime.jsx(material.Dialog,{open:e,onClose:o,fullScreen:true,children:jsxRuntime.jsxs(material.Box,{sx:{height:"100%",display:"flex",flexDirection:"column",bgcolor:"background.default"},children:[jsxRuntime.jsx(material.Box,{sx:{p:2,borderBottom:1,borderColor:"divider"},children:jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",justifyContent:"space-between",spacing:2,children:[jsxRuntime.jsxs(material.Stack,{direction:"row",spacing:1.5,alignItems:"center",children:[jsxRuntime.jsx(material.Typography,{variant:"h5",fontWeight:800,children:t.title}),jsxRuntime.jsx(material.Chip,{size:"small",label:`${t.kpis.totalRecords} records`})]}),jsxRuntime.jsx(material.IconButton,{onClick:o,children:jsxRuntime.jsx(Ua__default.default,{})})]})}),jsxRuntime.jsxs(material.Box,{sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,overflow:"auto",minHeight:0},children:[jsxRuntime.jsx(jo,{kpis:t.kpis}),jsxRuntime.jsx(Uo,{billableByPrimary:t.charts.billableByPrimary,efficiencyBySecondary:t.charts.efficiencyBySecondary,statusDistribution:t.charts.statusDistribution}),i]})]})});var Se={primaryDimension:["Client","Customer","Category","Project"],secondaryDimension:["Person","Consultant","Owner","Name"],status:["Status","state"],date:["Date","WorkDate","CreatedAt"],description:["Description","Task","Title","Memo"],reportHours:["Report_Hour","Report Hours","Hours","ReportHours"],billableHours:["Billable_Hour","Billable Hours","BillableHours"],amount:["Amount","Billable_Amount","Total_Amount","Value"]},Ka=5,qo=e=>e.toLowerCase().replace(/[\s_-]/g,""),Te=(e,o,t,i)=>{if(o)return o;if(e.length===0)return i;let s=Object.keys(e[0]),a=new Map(s.map(l=>[qo(l),l]));for(let l of t){let n=a.get(qo(l));if(n)return n}return s[0]||i},ye=e=>{if(typeof e=="number")return Number.isFinite(e)?e:0;if(typeof e=="string"){let o=Number(e.replace(/,/g,"").trim());return Number.isFinite(o)?o:0}return 0},be=(e,o)=>e==null||e===""?o:String(e),Ya=(e,o,t,i)=>{let s=new Map;return e.forEach(a=>{let l=be(a[o],"Unassigned");s.set(l,(s.get(l)||0)+ye(a[t]));}),Array.from(s.entries()).map(([a,l])=>({name:a,value:l})).sort((a,l)=>l.value-a.value).slice(0,i)},qa=(e,o,t,i,s)=>{let a=new Map;return e.forEach(l=>{let n=be(l[o],"Unassigned"),u=a.get(n)||{report:0,billable:0};u.report+=ye(l[t]),u.billable+=ye(l[i]),a.set(n,u);}),Array.from(a.entries()).map(([l,n])=>({name:l,value:n.report>0?n.billable/n.report*100:0})).sort((l,n)=>l.value-n.value).slice(0,s)},Xa=(e,o)=>{let t=e.length;if(t===0)return [];let i=new Map;return e.forEach(s=>{let a=be(s[o],"Unassigned");i.set(a,(i.get(a)||0)+1);}),Array.from(i.entries()).map(([s,a])=>({name:s,value:a,percent:a/t*100}))},Xo=({rows:e,config:o})=>{let t=bo.useMemo(()=>{let u=o?.fieldMapping;return {primaryDimension:Te(e,u?.primaryDimension,Se.primaryDimension,"Category"),secondaryDimension:Te(e,u?.secondaryDimension,Se.secondaryDimension,"Owner"),status:Te(e,u?.status,Se.status,"Status"),date:Te(e,u?.date,Se.date,"Date"),description:Te(e,u?.description,Se.description,"Description"),reportHours:Te(e,u?.reportHours,Se.reportHours,"ReportHours"),billableHours:Te(e,u?.billableHours,Se.billableHours,"BillableHours"),amount:Te(e,u?.amount,Se.amount,"Amount")}},[e,o?.fieldMapping]),i=bo.useMemo(()=>e.map((u,v)=>{let w=ye(u[t.reportHours]),S=ye(u[t.billableHours]),x=ye(u[t.amount]),P=w>0?S/w*100:0;return {id:`graph-row-${v}`,Date:be(u[t.date],""),Primary:be(u[t.primaryDimension],"Unassigned"),Secondary:be(u[t.secondaryDimension],"Unassigned"),Description:be(u[t.description],""),ReportHours:w,BillableHours:S,Amount:x,Efficiency:P,Status:be(u[t.status],"Unassigned")}}),[e,t]),s=bo.useMemo(()=>{let u=i.length,v=i.reduce((m,g)=>m+ye(g.ReportHours),0),w=i.reduce((m,g)=>m+ye(g.BillableHours),0),S=i.reduce((m,g)=>m+ye(g.Amount),0),x=v>0?w/v*100:0,P=o?.statusFlagValues||["flag","flagged","warning","risk"],k=i.filter(m=>P.includes(be(m.Status,"").toLowerCase())).length;return {totalRecords:u,totalReportHours:v,totalBillableHours:w,efficiency:x,totalAmount:S,flaggedCount:k}},[i,o?.statusFlagValues]),a=o?.topN||Ka,l=bo.useMemo(()=>({billableByPrimary:Ya(i,"Primary","BillableHours",a),efficiencyBySecondary:qa(i,"Secondary","ReportHours","BillableHours",a),statusDistribution:Xa(i,"Status")}),[i,a]),n=bo.useMemo(()=>({title:o?.title||"Graphic Report",kpis:s,charts:l,table:{columns:[{id:"Date",label:t.date},{id:"Primary",label:t.primaryDimension},{id:"Secondary",label:t.secondaryDimension},{id:"Description",label:t.description},{id:"ReportHours",label:"Report Hours",align:"right"},{id:"BillableHours",label:"Billable Hours",align:"right"},{id:"Amount",label:"Amount",align:"right"},{id:"Efficiency",label:"Efficiency",align:"right"},{id:"Status",label:t.status}],rows:i}}),[l,o?.title,t,s,i]);return {fieldMapping:t,model:n}};var bt=({variants:e,currentVariantId:o,onLoad:t,onSave:i,onDelete:s,onSetDefault:a})=>{let l="0.75rem",[n,u]=bo.useState(false),[v,w]=bo.useState(""),[S,x]=bo.useState(false),[P,k]=bo.useState(false),m=e.find(d=>d.id===o);return jsxRuntime.jsxs(material.Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsxRuntime.jsx(material.Typography,{variant:"body2",sx:{fontWeight:"bold",minWidth:"fit-content",fontSize:l},children:"Variant:"}),jsxRuntime.jsx(material.Autocomplete,{size:"small",sx:{width:200,"& .MuiInputBase-root":{fontSize:l},"& .MuiInputBase-input":{fontSize:l},"& .MuiAutocomplete-noOptions":{fontSize:l}},noOptionsText:jsxRuntime.jsx(material.Typography,{sx:{fontSize:l},children:"No options"}),options:e,getOptionLabel:d=>d.name+(d.isDefault?" (Default)":""),value:m||null,onChange:(d,I)=>{I&&t(I);},renderInput:d=>jsxRuntime.jsx(material.TextField,{...d,variant:"outlined",size:"small",InputProps:{...d.InputProps,sx:{fontSize:l}},placeholder:"Select Variant"}),renderOption:(d,I)=>jsxRuntime.jsx("li",{...d,children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsxRuntime.jsx(material.Typography,{sx:{flex:1,fontSize:l},children:I.name}),I.isDefault&&jsxRuntime.jsx(rr__default.default,{fontSize:"small",color:"action"})]})})}),jsxRuntime.jsx(material.Tooltip,{title:"Save View",children:jsxRuntime.jsx(material.IconButton,{onClick:()=>{w(m?.name||"New Variant"),x(m?.isDefault||false),k(m?.isPublic||false),u(true);},size:"small",color:"primary",children:jsxRuntime.jsx(yn__default.default,{})})}),jsxRuntime.jsxs(material.Dialog,{open:n,onClose:()=>u(false),children:[jsxRuntime.jsx(material.DialogTitle,{children:"Save View"}),jsxRuntime.jsxs(material.DialogContent,{children:[jsxRuntime.jsx(material.TextField,{autoFocus:true,margin:"dense",label:"View Name",fullWidth:true,variant:"outlined",value:v,onChange:d=>w(d.target.value)}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:S,onChange:d=>x(d.target.checked)}),label:"Set as Default"}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:P,onChange:d=>k(d.target.checked)}),label:"Public (All Users)"})]}),jsxRuntime.jsxs(material.DialogActions,{children:[jsxRuntime.jsx(material.Button,{onClick:()=>u(false),children:"Cancel"}),jsxRuntime.jsx(material.Button,{onClick:()=>{i({name:v,isDefault:S,isPublic:P,description:""}),u(false);},variant:"contained",children:"Save"})]})]})]})};var sr="http://127.0.0.1:8515",nn=({appId:e,tableKey:o="default",currentFilters:t,currentLayoutId:i,layoutRefs:s,onLoad:a,serviceUrl:l=sr,onError:n,onSuccess:u,currentVariantId:v,onVariantChange:w})=>{let[S,x]=bo.useState([]),[P,k]=bo.useState(""),m=v!==void 0?v:P,g=c=>{v===void 0&&k(c),w&&w(c);},y=bo.useCallback(async()=>{if(!e)return [];try{let c=await fetch(`${l}/api/variants?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!c.ok)throw new Error("Failed to fetch variants");let C=await c.json();x(C);let M=C.find(T=>T.isDefault);return M&&!m&&(g(M.id),a(M)),C}catch(c){return console.error("Error fetching variants",c),n&&n("Failed to load variants"),[]}},[e,o,l,n,m,a]);return bo.useEffect(()=>{y();},[e,o]),jsxRuntime.jsx(bt,{variants:S,currentVariantId:m,onLoad:c=>{g(c.id),a(c);},onSave:async c=>{try{let C=S.find(A=>A.name===c.name),M=C?C.id:Date.now().toString(),T=[];if(C&&(Array.isArray(C.filters)?T=[...C.filters]:C.filters&&(T=[{scope:"default",filters:C.filters}])),c.scope==="Search"||c.scope==="Both"){let A=(Array.isArray(t),t);if(A)if(Array.isArray(A)&&A.length>0&&A[0].scope)A.forEach(V=>{let B=T.findIndex(H=>H.scope===V.scope);B>=0?T[B]=V:T.push(V);});else {let V={scope:o,filters:A},B=T.findIndex(H=>H.scope===o);B>=0?T[B]=V:T.push(V);}}let p=C?.layout||{},D=[];if(C&&Array.isArray(C.layoutRefs)&&(D=[...C.layoutRefs]),c.scope==="Layout"||c.scope==="Both")if(s&&s.length>0)s.forEach(A=>{let V=D.findIndex(B=>B.tableKey===A.tableKey);V>=0?D[V]=A:D.push(A);});else {let A={tableKey:o,layoutId:i||null},V=D.findIndex(B=>B.tableKey===o);V>=0?D[V]=A:D.push(A);}let f={appId:e,tableKey:o,...c,id:M,createdAt:new Date().toISOString(),filters:T,layout:p,layoutRefs:D};if(!(await fetch(`${l}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(f)})).ok)throw new Error("Failed to save variant");u&&u("Variant saved successfully"),await y(),g(M),a(f);}catch(C){console.error("Error saving variant",C),n&&n("Failed to save variant");}},onDelete:async c=>{try{if(!(await fetch(`${l}/api/variants/${c}`,{method:"DELETE"})).ok)throw new Error("Failed to delete variant");m===c&&g(""),y(),u&&u("Variant deleted successfully");}catch(C){console.error("Error deleting variant",C),n&&n("Failed to delete variant");}},onSetDefault:async c=>{try{let C=S.find(p=>p.id===c);if(!C)return;let M={appId:e,tableKey:o,...C,isDefault:!0};if(!(await fetch(`${l}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(M)})).ok)throw new Error("Failed to set default variant");await y(),u&&u("Default variant updated");}catch(C){console.error("Error setting default variant",C),n&&n("Failed to update default variant");}}})};De__default.default.extend(Tr__default.default);var wr=[null,null],io="0.75rem",Ir=material.styled(PickersDay.PickersDay,{shouldForwardProp:e=>e!=="isInRange"&&e!=="isStart"&&e!=="isEnd"&&e!=="isHovered"})(({theme:e,isInRange:o,isStart:t,isEnd:i,isHovered:s})=>({...o&&{borderRadius:0,backgroundColor:e.palette.primary.light,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.main}},...s&&!o&&!t&&!i&&{borderRadius:0,backgroundColor:e.palette.action.hover,border:`1px dashed ${e.palette.primary.main}`},...t&&{borderRadius:"50% 0 0 50%",backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.dark}},...i&&{borderRadius:"0 50% 50% 0",backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.dark}},...t&&i&&{borderRadius:"50%"}})),ln=({label:e="Date Range",value:o=wr,onChange:t})=>{let[i,s]=bo.useState(null),[a,l]=bo.useState(o),[n,u]=bo.useState("start"),[v,w]=bo.useState(null),[S,x]=bo.useState(o[0]||De__default.default()),P=bo__namespace.default.useRef(o);bo.useEffect(()=>{let[M,T]=o,[p,D]=P.current,f=V=>V&&typeof V.isSame=="function",W=!(M===null&&p===null||f(M)&&f(p)&&M.isSame(p,"day")),A=!(T===null&&D===null||f(T)&&f(D)&&T.isSame(D,"day"));(W||A)&&(l(o),o[0]&&f(o[0])&&x(o[0])),P.current=o;},[o]);let k=M=>{s(M.currentTarget);},m=()=>{s(null),u("start"),w(null);},g=!!i,y=M=>{if(!M)return;let T=[...a];if(n==="start")T=[M,null],u("end");else {let p=T[0];p&&M.isBefore(p)?(T=[M,null],u("end")):(T=[p,M],u("start"));}l(T);},d=M=>{let T=De__default.default(),p=[null,null];switch(M){case "today":p=[T,T];break;case "week":p=[T.startOf("week"),T.endOf("week")];break;case "month":p=[T.startOf("month"),T.endOf("month")];break}l(p),u("start"),x(T);},I=()=>{l([null,null]),u("start"),x(De__default.default());},r=()=>{t&&t(a),m();},b=()=>{l(o),u("start"),m();},c=bo.useCallback(M=>{let{day:T,...p}=M,[D,f]=a,W=D?T.isSame(D,"day"):false,A=f?T.isSame(f,"day"):false,V=D&&f?T.isBetween(D,f,"day","()"):false,B=false;return n==="end"&&D&&!f&&v&&T.isAfter(D,"day")&&T.isBefore(v.add(1,"day"),"day")&&(B=true),jsxRuntime.jsx(Ir,{...p,day:T,disableMargin:true,isStart:W,isEnd:A,isInRange:V||B,onMouseEnter:()=>w(T)})},[a,n,v]),C=M=>M?M.format("YYYY-MM-DD"):"";return jsxRuntime.jsxs(material.Box,{children:[jsxRuntime.jsx(material.TextField,{label:e,value:a[0]?`${C(a[0])} - ${C(a[1])}`:"",onClick:k,fullWidth:true,size:"small",InputLabelProps:{sx:{fontSize:io}},InputProps:{readOnly:true,sx:{fontSize:io,"& .MuiOutlinedInput-input":{fontSize:io},paddingRight:"4px"},endAdornment:jsxRuntime.jsxs(material.InputAdornment,{position:"end",sx:{ml:0},children:[(a[0]||a[1])&&jsxRuntime.jsx(material.IconButton,{size:"small",onClick:M=>{M.stopPropagation(),I();},edge:"end",sx:{mr:.5,padding:"2px"},children:jsxRuntime.jsx(vr__default.default,{sx:{fontSize:"1rem"}})}),jsxRuntime.jsx(material.IconButton,{size:"small",edge:"end",onClick:k,sx:{padding:"2px"},children:jsxRuntime.jsx(Cr__default.default,{sx:{fontSize:"1rem"},color:"action"})})]})}}),jsxRuntime.jsxs(material.Popover,{open:g,anchorEl:i,onClose:m,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},slotProps:{paper:{sx:{display:"flex",flexDirection:"column",p:0,minWidth:320}}},children:[jsxRuntime.jsx(material.Box,{sx:{p:2,bgcolor:"background.default",borderBottom:1,borderColor:"divider"},children:jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:2,justifyContent:"space-between",children:[jsxRuntime.jsxs(material.Box,{sx:{p:1,border:1,borderColor:n==="start"?"primary.main":"divider",borderRadius:1,bgcolor:n==="start"?"action.hover":"transparent",flex:1,cursor:"pointer"},onClick:()=>u("start"),children:[jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",display:"block",children:"Start Date"}),jsxRuntime.jsx(material.Typography,{variant:"body2",fontWeight:500,children:a[0]?a[0].format("MMM DD, YYYY"):"Select..."})]}),jsxRuntime.jsx(Sr__default.default,{color:"action",fontSize:"small"}),jsxRuntime.jsxs(material.Box,{sx:{p:1,border:1,borderColor:n==="end"?"primary.main":"divider",borderRadius:1,bgcolor:n==="end"?"action.hover":"transparent",flex:1,cursor:"pointer"},onClick:()=>{a[0]&&u("end");},children:[jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",display:"block",children:"End Date"}),jsxRuntime.jsx(material.Typography,{variant:"body2",fontWeight:500,children:a[1]?a[1].format("MMM DD, YYYY"):"Select..."})]})]})}),jsxRuntime.jsx(material.Box,{sx:{p:2,pb:0},children:jsxRuntime.jsxs(material.Stack,{direction:"row",spacing:1,justifyContent:"center",children:[jsxRuntime.jsx(material.Chip,{label:"Today",onClick:()=>d("today"),clickable:true,size:"small",variant:"outlined"}),jsxRuntime.jsx(material.Chip,{label:"This Week",onClick:()=>d("week"),clickable:true,size:"small",variant:"outlined"}),jsxRuntime.jsx(material.Chip,{label:"This Month",onClick:()=>d("month"),clickable:true,size:"small",variant:"outlined"})]})}),jsxRuntime.jsx(DateCalendar.DateCalendar,{value:null,referenceDate:S,onMonthChange:x,onYearChange:x,onChange:y,slots:{day:c},views:["day"],showDaysOutsideCurrentMonth:true,sx:{m:0}}),jsxRuntime.jsx(material.Divider,{}),jsxRuntime.jsxs(material.Stack,{direction:"row",justifyContent:"flex-end",spacing:1,sx:{p:2},children:[jsxRuntime.jsx(material.Button,{size:"small",onClick:b,color:"inherit",children:"Cancel"}),jsxRuntime.jsx(material.Button,{size:"small",variant:"contained",onClick:r,children:"Done"})]})]})]})};var St={equals:"=",contains:"\u2287",notContains:"\u2285",wildcard:"*","=":"=","!=":"!=",">":">","<":"<",">=":"\u2265","<=":"\u2264",between:"\u2194"},Vr={equals:"Equals",contains:"Contains",notContains:"Does Not Contain",wildcard:"Wildcard Search","=":"Equals","!=":"Not Equals",">":"Greater Than","<":"Less Than",">=":"Greater Than or Equal","<=":"Less Than or Equal",between:"Between"},Nr=["equals","contains","notContains","wildcard"],dn=["=","!=",">","<",">=","<=","between"],Z="0.75rem",Hr=({field:e,value:o,onChange:t})=>{let[i,s]=bo.useState(null),[a,l]=bo.useState(null),[n,u]=bo.useState(""),[v,w]=bo.useState(""),[S,x]=bo.useState(false),[P,k]=bo.useState(""),[m,g]=bo.useState("");bo.useEffect(()=>{let p=setTimeout(()=>{g(P);},1e3);return ()=>clearTimeout(p)},[P]);let y=o?.operator||(e.type==="number"?"=":"equals"),d=o?.value,I=p=>Vr[p]||p,r=p=>{s(p.currentTarget);},b=p=>{t({...o,operator:p,value:d}),s(null);},c={size:"small",fullWidth:true,variant:"outlined",InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}},SelectProps:{MenuProps:{PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,paddingTop:"4px",paddingBottom:"4px",minHeight:"auto"}}}}}},C=e.type||"text";if(C==="date"){let D=(f=>{if(!f)return [null,null];if(Array.isArray(f)&&f.length===2){let W=f[0]?De__default.default.isDayjs(f[0])?f[0]:De__default.default(f[0]):null,A=f[1]?De__default.default.isDayjs(f[1])?f[1]:De__default.default(f[1]):null;return [W,A]}return De__default.default.isDayjs(f)||typeof f=="string"?[De__default.default.isDayjs(f)?f:De__default.default(f),null]:[null,null]})(d);return jsxRuntime.jsx(ln,{label:e.label,value:D,onChange:f=>t({value:f,operator:"between"})})}if(C==="number"&&y==="between"){let p=()=>{t({value:[n,v],operator:"between"}),l(null);},D=Array.isArray(d)?`${d[0]||""} - ${d[1]||""}`:"";return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(material.TextField,{...c,label:e.label,value:D,placeholder:"Min - Max",InputProps:{...c.InputProps,startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(material.Tooltip,{title:I("between"),children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:r,sx:{width:24,height:24,fontSize:Z},children:St.between})})}),readOnly:true},onClick:f=>l(f.currentTarget)}),jsxRuntime.jsx(material.Menu,{anchorEl:i,open:!!i,onClose:()=>s(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,minHeight:"auto",py:.5}}},children:dn.map(f=>jsxRuntime.jsxs(material.MenuItem,{selected:f===y,onClick:()=>b(f),children:[jsxRuntime.jsx(material.Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:St[f]}),jsxRuntime.jsx(material.ListItemText,{primary:I(f),primaryTypographyProps:{fontSize:Z}})]},f))}),jsxRuntime.jsx(material.Popover,{open:!!a,anchorEl:a,onClose:()=>l(null),anchorOrigin:{vertical:"bottom",horizontal:"left"},children:jsxRuntime.jsxs(material.Box,{sx:{p:2,display:"flex",gap:1,alignItems:"center"},children:[jsxRuntime.jsx(material.TextField,{size:"small",label:"Min",type:"number",value:n,onChange:f=>u(f.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}}}),jsxRuntime.jsx(Fr__default.default,{color:"action"}),jsxRuntime.jsx(material.TextField,{size:"small",label:"Max",type:"number",value:v,onChange:f=>w(f.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}}}),jsxRuntime.jsx(material.Button,{variant:"contained",size:"small",onClick:p,children:"OK"})]})})]})}if(C==="select")return jsxRuntime.jsxs(material.TextField,{...c,select:true,label:e.label,value:d||"",onChange:p=>t({...o,value:p.target.value,operator:"equals"}),children:[jsxRuntime.jsx(material.MenuItem,{value:"",children:jsxRuntime.jsx("em",{children:"None"})}),e.options?.map(p=>jsxRuntime.jsx(material.MenuItem,{value:p.value,children:p.label},p.value))]});if(C==="multi-select"){let p=Array.isArray(d)?d:[],D=e.options?.filter(f=>f.label.toLowerCase().includes(m.toLowerCase()))||[];return jsxRuntime.jsxs(material.TextField,{...c,select:true,label:e.label,value:p,onChange:f=>t({...o,value:f.target.value,operator:"anyOf"}),SelectProps:{...c.SelectProps,multiple:true,onClose:()=>{k(""),g("");},renderValue:f=>{if(!Array.isArray(f)||f.length===0)return jsxRuntime.jsx("em",{children:"None"});let W=V=>e.options?.find(B=>B.value===V)?.label||V,A=f.map(W);return A.length>2?`${A.slice(0,2).join(", ")} +${A.length-2}`:A.join(", ")}},children:[jsxRuntime.jsx(material.ListSubheader,{children:jsxRuntime.jsx(material.TextField,{size:"small",autoFocus:true,placeholder:"Search...",fullWidth:true,InputProps:{startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(cn__default.default,{fontSize:"small"})}),sx:{fontSize:Z}},value:P,onChange:f=>k(f.target.value),onKeyDown:f=>{f.key!=="Escape"&&f.stopPropagation();},onClick:f=>f.stopPropagation()})}),D.length>0?D.map(f=>jsxRuntime.jsxs(material.MenuItem,{value:f.value,children:[jsxRuntime.jsx(material.Checkbox,{checked:p.indexOf(f.value)>-1,size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:f.label,primaryTypographyProps:{fontSize:Z}})]},f.value)):jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.ListItemText,{primary:"No options found",primaryTypographyProps:{fontSize:Z}})})]})}let M=C==="number"?dn:Nr,T=S||d!==void 0&&d!==""&&d!==null||!!i;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(material.TextField,{...c,label:e.label,sx:{minWidth:"120px"},value:d||"",type:C==="number"?"number":"text",onChange:p=>t({...o,value:p.target.value,operator:y}),onFocus:()=>x(true),onBlur:()=>x(false),InputProps:{...c.InputProps,startAdornment:T?jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(material.Tooltip,{title:I(y),children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:r,onMouseDown:p=>p.preventDefault(),sx:{width:24,height:24,fontSize:Z,fontWeight:"bold",color:"primary.main",bgcolor:"action.hover"},children:St[y]})})}):null,endAdornment:e.hasSearchIcon?jsxRuntime.jsx(material.InputAdornment,{position:"end",children:jsxRuntime.jsx(cn__default.default,{color:"action"})}):void 0}}),jsxRuntime.jsx(material.Menu,{anchorEl:i,open:!!i,onClose:()=>s(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,minHeight:"auto",py:.5}}},children:M.map(p=>jsxRuntime.jsxs(material.MenuItem,{selected:p===y,onClick:()=>b(p),children:[jsxRuntime.jsx(material.Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:St[p]}),jsxRuntime.jsx(material.ListItemText,{primary:I(p),primaryTypographyProps:{fontSize:Z}})]},p))})]})},qe=({fields:e,filters:o,onFilterChange:t,variants:i=[],currentVariantId:s,onVariantLoad:a,onVariantSave:l,onVariantDelete:n,onVariantSetDefault:u,onSearch:v,loading:w=false,appId:S,tableKey:x,currentLayout:P,currentLayoutId:k,layoutRefs:m,variantService:g})=>{let[y,d]=bo.useState(true),[I,r]=bo.useState(null),[b,c]=bo.useState(e.filter(p=>!p.hidden).map(p=>p.id)),C=(p,D)=>{t({...o,[p]:D});},M=p=>{b.includes(p)?c(b.filter(D=>D!==p)):c([...b,p]);};return jsxRuntime.jsxs(material.Paper,{sx:{mb:0,display:"flex",flexDirection:"column",overflow:"visible",position:"relative"},children:[jsxRuntime.jsxs(material.Box,{sx:{p:2,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[S?jsxRuntime.jsx(nn,{appId:S,tableKey:x,currentFilters:{values:o,visibleFields:b},currentLayout:P,currentLayoutId:k,layoutRefs:m,onLoad:p=>{if(!p.filters)return;let D=null;if(Array.isArray(p.filters)){let f=x||"default",W=p.filters.find(A=>A.scope===f);D=W?W.filters:null;}else D=p.filters;D&&(D.values||D.visibleFields?(D.visibleFields&&Array.isArray(D.visibleFields)&&c(D.visibleFields),D.values&&t(D.values)):t(D)),a&&a(p);},variantService:g,currentVariantId:s}):jsxRuntime.jsx(bt,{variants:i,currentVariantId:s,onLoad:a,onSave:p=>{l&&l({...p,filters:{values:o,visibleFields:b}});},onDelete:n,onSetDefault:u}),jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsxRuntime.jsx(material.Tooltip,{title:"Add Filters",children:jsxRuntime.jsx(material.Button,{onClick:p=>r(p.currentTarget),size:"small",color:"primary",startIcon:jsxRuntime.jsx(Br__default.default,{fontSize:"small"}),sx:{textTransform:"none",fontSize:Z},children:"Adapt Filters"})}),jsxRuntime.jsx(material.Button,{variant:"contained",size:"small",onClick:v,disabled:w,sx:{minWidth:"40px",fontWeight:"bold"},children:w?"...":"Go"}),jsxRuntime.jsxs(material.Menu,{anchorEl:I,open:!!I,onClose:()=>r(null),slotProps:{paper:{style:{maxHeight:400,width:"25ch"}}},children:[jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.ListItemText,{primary:"Visible Filters"})}),jsxRuntime.jsx(material.Divider,{}),e.map(p=>jsxRuntime.jsxs(material.MenuItem,{onClick:()=>M(p.id),children:[jsxRuntime.jsx(material.Checkbox,{checked:b.includes(p.id),size:"small"}),jsxRuntime.jsx(material.ListItemText,{primary:p.label})]},p.id))]})]})]}),jsxRuntime.jsx(material.Collapse,{in:y,children:jsxRuntime.jsx(material.Box,{sx:{px:2,pb:2},children:jsxRuntime.jsx(material.Grid,{container:true,spacing:2,columns:{xs:2,sm:3,md:4,lg:6},children:e.filter(p=>b.includes(p.id)).map(p=>jsxRuntime.jsx(material.Grid,{size:1,children:jsxRuntime.jsx(Hr,{field:p,value:o[p.id]||{value:"",operator:p.type==="number"?"=":"equals"},onChange:D=>C(p.id,D)})},p.id))})})}),jsxRuntime.jsx(material.Box,{sx:{position:"absolute",bottom:0,left:"50%",transform:"translate(-50%, 50%)",zIndex:10},children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:()=>d(!y),sx:{bgcolor:"background.paper",boxShadow:2,border:"1px solid",borderColor:"divider",width:20,height:20,minHeight:0,p:0,"&:hover":{bgcolor:"background.paper"}},children:y?jsxRuntime.jsx(Lr__default.default,{sx:{fontSize:16},color:"action"}):jsxRuntime.jsx(va__default.default,{sx:{fontSize:16},color:"action"})})})]})};var bn=({layouts:e,currentLayoutId:o,onLoad:t,onSave:i,onDelete:s,onSetDefault:a})=>{let[l,n]=bo.useState(null),[u,v]=bo.useState(false),[w,S]=bo.useState(""),[x,P]=bo.useState(""),[k,m]=bo.useState({isDefault:false,isPublic:false}),g=e.find(c=>c.id===o),y=c=>{n(c.currentTarget);},d=()=>{n(null);},I=c=>{t(c),d();},r=()=>{S(""),P(""),m({isDefault:false,isPublic:false}),v(true),d();},b=()=>{w.trim()&&(i({name:w,description:x,...k}),v(false));};return jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsxRuntime.jsx(material.Tooltip,{title:"Save Layout",children:jsxRuntime.jsx(material.IconButton,{onClick:r,color:"primary",size:"small",children:jsxRuntime.jsx(yn__default.default,{})})}),jsxRuntime.jsx(material.Tooltip,{title:"Layout Options",children:jsxRuntime.jsx(material.IconButton,{onClick:y,color:g?"primary":"default",children:jsxRuntime.jsx(Xr__default.default,{})})}),jsxRuntime.jsxs(material.Menu,{anchorEl:l,open:!!l,onClose:d,PaperProps:{sx:{width:320,maxHeight:400}},children:[jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.Typography,{variant:"caption",children:"Select Layout"})}),jsxRuntime.jsxs(material.MenuItem,{onClick:r,children:[jsxRuntime.jsx(material.ListItemIcon,{children:jsxRuntime.jsx(yn__default.default,{fontSize:"small"})}),jsxRuntime.jsx(material.ListItemText,{children:"Save Current Layout..."})]}),jsxRuntime.jsx(material.Divider,{}),e.length===0&&jsxRuntime.jsx(material.MenuItem,{disabled:true,children:jsxRuntime.jsx(material.Typography,{variant:"body2",color:"text.secondary",children:"No saved layouts"})}),e.map((c,C)=>jsxRuntime.jsx(material.MenuItem,{onClick:()=>I(c),selected:c.id===o,children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center",width:"100%",justifyContent:"space-between"},children:[jsxRuntime.jsxs(material.Box,{sx:{display:"flex",flexDirection:"column",overflow:"hidden",mr:1},children:[jsxRuntime.jsx(material.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:jsxRuntime.jsx(material.Typography,{variant:"body2",fontWeight:c.id===o?"bold":"normal",noWrap:true,children:c.name})}),c.description&&jsxRuntime.jsx(material.Typography,{variant:"caption",color:"text.secondary",noWrap:true,children:c.description})]}),jsxRuntime.jsxs(material.Box,{sx:{display:"flex",alignItems:"center"},onClick:M=>M.stopPropagation(),children:[jsxRuntime.jsx(material.Tooltip,{title:c.isDefault?"Remove Default":"Set as Default",children:jsxRuntime.jsx(material.IconButton,{size:"small",onClick:M=>{M.stopPropagation(),a(c.id);},children:c.isDefault?jsxRuntime.jsx(rr__default.default,{fontSize:"small",color:"warning"}):jsxRuntime.jsx(qr__default.default,{fontSize:"small"})})}),jsxRuntime.jsx(material.Tooltip,{title:"Delete",children:jsxRuntime.jsx(material.IconButton,{size:"small",color:"error",onClick:M=>{M.stopPropagation(),s(c.id);},children:jsxRuntime.jsx(Kr__default.default,{fontSize:"small"})})})]})]})},c.id||C))]}),jsxRuntime.jsxs(material.Dialog,{open:u,onClose:()=>v(false),maxWidth:"xs",fullWidth:true,children:[jsxRuntime.jsx(material.DialogTitle,{children:"Save Layout"}),jsxRuntime.jsx(material.DialogContent,{children:jsxRuntime.jsxs(material.Box,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[jsxRuntime.jsx(material.TextField,{label:"Layout Name",value:w,onChange:c=>S(c.target.value),fullWidth:true,autoFocus:true,size:"small",helperText:"e.g., 'Compact View'"}),e.some(c=>c.name===w)&&jsxRuntime.jsx(material.Typography,{variant:"caption",color:"warning.main",sx:{ml:1},children:"Warning: Existing layout will be overwritten"}),jsxRuntime.jsx(material.TextField,{label:"Description",value:x,onChange:c=>P(c.target.value),fullWidth:true,size:"small"}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:k.isDefault,onChange:c=>m({...k,isDefault:c.target.checked})}),label:"Use as Default Layout"}),jsxRuntime.jsx(material.FormControlLabel,{control:jsxRuntime.jsx(material.Checkbox,{checked:k.isPublic,onChange:c=>m({...k,isPublic:c.target.checked})}),label:"Public (Visible to all users)"})]})}),jsxRuntime.jsxs(material.DialogActions,{children:[jsxRuntime.jsx(material.Button,{onClick:()=>v(false),children:"Cancel"}),jsxRuntime.jsx(material.Button,{onClick:b,variant:"contained",disabled:!w,children:"Save"})]})]})]})};var Zr="http://127.0.0.1:8515",Cn=({appId:e,tableKey:o="default",currentLayoutData:t,onLayoutLoad:i,targetLayoutId:s,activeLayoutId:a,serviceUrl:l=Zr,onError:n,onSuccess:u})=>{let[v,w]=bo.useState([]),[S,x]=bo.useState(""),P=r=>({id:r.layoutId,name:r.name,description:r.description??"",isDefault:!!r.isDefault,isPublic:!!r.isPublic,createdAt:r.createdAt??new Date().toISOString(),layoutData:r.layout??{}}),k=r=>({appId:e,tableKey:o,layoutId:r.id,name:r.name,description:r.description??"",isDefault:!!r.isDefault,isPublic:!!r.isPublic,createdAt:r.createdAt,layout:r.layoutData});bo.useEffect(()=>{a!==void 0&&x(a);},[a]),bo.useEffect(()=>{if(s&&v.length>0){let r=v.find(b=>b.id===s);r&&(x(r.id),i(r));}},[s,v,i]);let m=bo.useCallback(async()=>{if(e)try{let r=await fetch(`${l}/api/layouts?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!r.ok)throw new Error("Failed to fetch layouts");let c=(await r.json()).map(P);w(c);let C=c.find(M=>M.isDefault);C&&!S&&!s&&(x(C.id),i(C));}catch(r){console.error("Error fetching layouts",r),n&&n("Failed to load layouts");}},[e,o,l,n,S,i,s]);return bo.useEffect(()=>{m();},[e,o]),jsxRuntime.jsx(bn,{layouts:v,currentLayoutId:S,onLoad:r=>{x(r.id),i(r);},onSave:async r=>{try{let b=v.find(T=>T.name===r.name),c=b?b.id:Date.now().toString(),C={id:c,...r,createdAt:new Date().toISOString(),layoutData:t,isDefault:r.isDefault??!1,isPublic:r.isPublic??!1};if(!(await fetch(`${l}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k(C))})).ok)throw new Error("Failed to save layout");u&&u("Layout saved successfully"),await m(),x(c),i(C);}catch(b){console.error("Error saving layout",b),n&&n("Failed to save layout");}},onDelete:async r=>{try{if(!(await fetch(`${l}/api/layouts/${encodeURIComponent(r)}`,{method:"DELETE"})).ok)throw new Error("Failed to delete layout");S===r&&x(""),u&&u("Layout deleted successfully"),await m();}catch(b){console.error("Error deleting layout",b),n&&n("Failed to delete layout");}},onSetDefault:async r=>{try{let b=v.find(C=>C.id===r);if(!b)return;if(!(await fetch(`${l}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k({...b,isDefault:!0}))})).ok)throw new Error("Failed to set default layout");u&&u("Default layout set"),await m();}catch(b){console.error("Error setting default",b),n&&n("Failed to set default layout");}}})};function Sn(e,o,t){return o[t]<e[t]?-1:o[t]>e[t]?1:0}function ei(e,o){return e==="desc"?(t,i)=>Sn(t,i,o):(t,i)=>-Sn(t,i,o)}function ti(e,o){let t=e.map((i,s)=>[i,s]);return t.sort((i,s)=>{let a=o(i[0],s[0]);return a!==0?a:i[1]-s[1]}),t.map(i=>i[0])}var Tn=e=>{let o=bo.useCallback(h=>{let L=String(h?.label??h?.id??"").length*9+64,ee=typeof h?.minWidth=="number"?h.minWidth:0;return Math.max(100,ee,L)},[]),[t,i]=bo.useState(""),[s,a]=bo.useState(e.order||"asc"),[l,n]=bo.useState(e.orderBy||""),[u,v]=bo.useState(e.page||0),[w,S]=bo.useState(e.rowsPerPage||20),[x,P]=bo.useState(e.selected||[]),[k,m]=bo.useState(e.columns?e.columns.map(h=>h.id):[]),[g,y]=bo.useState(e.showSummary||false),[d,I]=bo.useState([]),[r,b]=bo.useState(new Set),[c,C]=bo.useState(()=>{let h={};return (e.columns||[]).forEach(E=>{h[E.id]=o(E);}),h}),[M,T]=bo.useState(null),[p,D]=bo.useState(null),[f,W]=bo.useState(null),[A,V]=bo.useState(null),[B,H]=bo.useState(false);bo.useEffect(()=>{e.order!==void 0&&a(e.order),e.orderBy!==void 0&&n(e.orderBy);},[e.order,e.orderBy]),bo.useEffect(()=>{e.selected!==void 0&&P(e.selected);},[e.selected]),bo.useEffect(()=>{e.page!==void 0&&v(e.page);},[e.page]),bo.useEffect(()=>{C(h=>{let E={...h};return (e.columns||[]).forEach(L=>{E[L.id]===void 0&&(E[L.id]=o(L));}),E});},[e.columns,o]);let z=bo.useMemo(()=>{let h=e.rows||[];return t&&(h=h.filter(E=>Object.keys(E).some(L=>String(E[L]).toLowerCase().includes(t.toLowerCase())))),h},[e.rows,t]),ke=bo.useMemo(()=>e.onSortChange||!l?z:ti(z,ei(s,l)),[z,s,l,e.onSortChange]),Me=bo.useCallback(h=>{if(d.length===0)return h.map(Y=>({type:"row",data:Y,id:Y[e.rowKey||"id"]}));let E=[...h].sort((Y,J)=>{for(let U of d){if(Y[U]<J[U])return -1;if(Y[U]>J[U])return 1}return 0}),L=(Y,J=0)=>{if(J>=d.length)return Y;let U=d[J],$={},le=[];return Y.forEach(se=>{let Ee=se[U],pe=`${U}:${Ee}`;$[pe]||($[pe]={key:pe,field:U,value:Ee,children:[],count:0,level:J},le.push($[pe])),$[pe].children.push(se),$[pe].count++;}),le.forEach(se=>{se.children&&(se.children=L(se.children,J+1));}),le},ee=L(E),O=(Y,J="")=>{let U=[];return Y.forEach($=>{if($.children){let le=J?`${J}>${$.key}`:$.key,se=r.has(le);U.push({type:"group",id:le,field:$.field,value:$.value,level:$.level,count:$.count,isExpanded:se,childIds:(function Ee(pe){let Be=[];return pe.children.forEach(Le=>{Le.children?Be=Be.concat(Ee(Le)):Be.push(Le[e.rowKey||"id"]);}),Be})($)}),se&&(U=U.concat(O($.children,le)));}else U.push({type:"row",data:$,id:$[e.rowKey||"id"],level:d.length});}),U};return O(ee)},[d,r,e.rowKey]),ie=bo.useMemo(()=>Me(ke),[ke,Me]),oe=bo.useMemo(()=>w>0?ie.slice(u*w,u*w+w):ie,[ie,u,w]),Oe=h=>{let E=new Set(r);E.has(h)?E.delete(h):E.add(h),b(E);},Et=h=>{Oe(h);},Ge=h=>{let E=new Set(r);Array.from(E).forEach(L=>{L.startsWith(h)&&E.delete(L);}),b(E);},Bt=h=>{h||b(new Set);},Lt=h=>{let E=l===h&&s==="asc",L=l===h&&s==="desc";if(e.onSortChange){E?e.onSortChange(h,"desc"):L?e.onSortChange("","asc"):e.onSortChange(h,"asc");return}E?(a("desc"),n(h)):L?(a("asc"),n("")):(a("asc"),n(h));},We=(h,E)=>{C(L=>({...L,[h]:E}));},nt=h=>{if(h.target.checked){let E=z.map(L=>L[e.rowKey||"id"]);P(E),e.onSelectionChange&&e.onSelectionChange(E);return}P([]),e.onSelectionChange&&e.onSelectionChange([]);},At=(h,E)=>{let L=E[e.rowKey||"id"],ee=x.indexOf(L),O=[];ee===-1?O=O.concat(x,L):ee===0?O=O.concat(x.slice(1)):ee===x.length-1?O=O.concat(x.slice(0,-1)):ee>0&&(O=O.concat(x.slice(0,ee),x.slice(ee+1))),P(O),e.onSelectionChange&&e.onSelectionChange(O);},at=h=>{v(h),e.onPageChange&&e.onPageChange(h);},rt=h=>{S(h),v(0),e.onRowsPerPageChange&&e.onRowsPerPageChange(h);},Ft=h=>{let E=k.indexOf(h),L=[...k];E===-1?L.push(h):L.splice(E,1),m(L);},Vt=h=>{let E=d.indexOf(h),L=[...d];E===-1?L.push(h):L.splice(E,1),I(L);},it=h=>{e.onLayoutSave&&e.onLayoutSave({visibleColumns:k,order:s,orderBy:l,grouping:d,columnWidths:c});},lt=h=>{h.layout&&(h.layout.visibleColumns&&m(h.layout.visibleColumns),h.layout.order&&a(h.layout.order),h.layout.orderBy&&n(h.layout.orderBy),h.layout.grouping&&I(h.layout.grouping),h.layout.columnWidths&&C(h.layout.columnWidths));};bo.useEffect(()=>{e.layout&&lt({layout:e.layout});},[e.layout]);let Nt=h=>{h.preventDefault(),V(A===null?{mouseX:h.clientX+2,mouseY:h.clientY-6}:null);},Ht=()=>{V(null);},zt=bo.useMemo(()=>{if(!g)return {};let h={};e.columns.forEach(L=>{if(L.numeric){let ee=z.reduce((O,Y)=>{let J=parseFloat(Y[L.id]);return O+(isNaN(J)?0:J)},0);h[L.id]=ee.toFixed(2);}else h[L.id]="";});let E=e.columns.find(L=>k.includes(L.id));return E&&!E.numeric&&(h[E.id]="Total"),h},[z,e.columns,g,k]),Ot=()=>{if(!e.columns||!z)return;let h=e.columns.map(Y=>Y.label).join(","),E=z.map(Y=>e.columns.map(J=>{let U=Y[J.id];return `"${(U==null?"":String(U)).replace(/"/g,'""')}"`}).join(",")).join(`
2
+ `),L=`data:text/csv;charset=utf-8,${h}
3
+ ${E}`,ee=encodeURI(L),O=document.createElement("a");O.setAttribute("href",ee),O.setAttribute("download",`${e.title||"export"}.csv`),document.body.appendChild(O),O.click(),document.body.removeChild(O);},st=()=>{H(true);},Gt=()=>{H(false);};return {isMobile:false,columns:e.columns,order:s,orderBy:l,filterText:t,setFilterText:i,visibleColumns:k,setVisibleColumns:m,showSummary:g,setShowSummary:y,summaryColumns:[],grouping:d,setGrouping:I,expandedGroups:r,setExpandedGroups:b,groupAnchorEl:p,setGroupAnchorEl:D,summaryAnchorEl:f,setSummaryAnchorEl:W,columnWidths:c,setColumnWidths:C,anchorEl:M,setAnchorEl:T,contextMenu:A,setContextMenu:V,sensors:void 0,sortedAndFilteredRows:ke,visibleRows:oe,summaryRow:zt,page:u,setPage:at,rowsPerPage:w,setRowsPerPage:rt,selected:x,setSelected:P,isAllExpanded:false,handleColumnResize:We,handleRequestSort:Lt,handleSelectAllClick:nt,handleClick:At,toggleSummaryColumn:()=>{},handleDragEnd:()=>{},handleExport:Ot,handleContextMenu:Nt,handleCloseContextMenu:Ht,toggleColumnVisibility:Ft,toggleGroupExpand:Oe,toggleGroupField:Vt,handleToggleAll:Bt,handleExpandGroupRecursively:Et,handleCollapseGroupRecursively:Ge,handleLayoutLoad:()=>{},handleVariantLoad:lt,handleLayoutSave:it,effectiveAppId:e.appId||"",currentLayoutData:{visibleColumns:k,order:s,orderBy:l,grouping:d,columnWidths:c},currentLayoutId:"",layoutIdToLoad:"",onPageChange:at,onRowsPerPageChange:rt,graphReportOpen:B,handleOpenGraphReport:st,handleCloseGraphReport:Gt}};var Ec=e=>jsxRuntime.jsx(ai__default.default,{...e}),Bc=e=>jsxRuntime.jsx(Do__default.default,{...e}),Lc=e=>jsxRuntime.jsx(wn__default.default,{...e}),Ac=e=>jsxRuntime.jsx(pa__default.default,{...e}),Fc=e=>jsxRuntime.jsx(ma__default.default,{...e}),kt=e=>{let{title:o="Data Table",selectionMode:t,selected:i=[],onSelectionChange:s,actions:a,extraTools:l,fitContainer:n=false,fullWidth:u=false,maxHeight:v,loading:w=false,page:S=0,rowsPerPage:x=20,rowsPerPageOptions:P=[20,50,100,-1],count:k=0,onPageChange:m,onRowsPerPageChange:g,onLayoutSave:y,filterConfig:d,rowKey:I,tableKey:r="default",graphReport:b}=e,{isMobile:c,columns:C,order:M,orderBy:T,filterText:p,setFilterText:D,visibleColumns:f,showSummary:W,setShowSummary:A,summaryColumns:V,grouping:B,setGrouping:H,expandedGroups:z,groupAnchorEl:ke,setGroupAnchorEl:Me,summaryAnchorEl:ie,setSummaryAnchorEl:oe,columnWidths:Oe,anchorEl:Et,setAnchorEl:Ge,contextMenu:Bt,sensors:Lt,sortedAndFilteredRows:We,summaryRow:nt,visibleRows:At,isAllExpanded:at,handleColumnResize:rt,handleRequestSort:Ft,handleSelectAllClick:Vt,handleClick:it,toggleSummaryColumn:lt,handleDragEnd:Nt,handleExport:Ht,handleContextMenu:zt,handleCloseContextMenu:Ot,toggleColumnVisibility:st,toggleGroupExpand:Gt,toggleGroupField:h,handleToggleAll:E,handleExpandGroupRecursively:L,handleCollapseGroupRecursively:ee,handleLayoutLoad:O,handleVariantLoad:Y,handleLayoutSave:J,effectiveAppId:U,currentLayoutData:$,currentLayoutId:le,layoutIdToLoad:se,graphReportOpen:Ee,handleOpenGraphReport:pe,handleCloseGraphReport:Be}=Tn(e),Le=b?.enabled??false,{model:Wt}=Xo({rows:We,config:{...b,title:b?.title||`${o} Graphic Report`}}),Bn=Wt.table.columns.map(ct=>({id:ct.id,label:ct.label,align:ct.align||"left",minWidth:120,numeric:ct.align==="right"})),Ln=U?jsxRuntime.jsx(Cn,{appId:U,tableKey:r,currentLayoutData:$,onLayoutLoad:O,targetLayoutId:se,activeLayoutId:le,serviceUrl:(d?.variantService,void 0)}):null,ho=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Oo,{groupAnchorEl:ke,setGroupAnchorEl:Me,grouping:B,setGrouping:H,columns:C,toggleGroupField:h}),jsxRuntime.jsx(Go,{anchorEl:Et,setAnchorEl:Ge,columns:C,visibleColumns:f,toggleColumnVisibility:st}),jsxRuntime.jsx(Wo,{anchorEl:ie,setAnchorEl:oe,showSummary:W,setShowSummary:A,columns:C,summaryColumns:V,toggleSummaryColumn:lt}),jsxRuntime.jsx($o,{contextMenu:Bt,handleCloseContextMenu:Ot,columns:C,visibleColumns:f,toggleColumnVisibility:st})]});return c?jsxRuntime.jsxs(mo__default.default,{sx:{display:"flex",flexDirection:"column",gap:2,height:"100%"},children:[d&&jsxRuntime.jsx(qe,{fields:d.fields,filters:d.filters,onFilterChange:d.onFilterChange,onSearch:d.onSearch,variants:d.variants||[],currentVariantId:d.currentVariantId,onVariantLoad:d.onVariantLoad,onVariantSave:d.onVariantSave,onVariantDelete:d.onVariantDelete,onVariantSetDefault:d.onVariantSetDefault,appId:d.appId,tableKey:r,currentLayout:[{tableKey:r,layoutData:$}],variantService:d.variantService}),jsxRuntime.jsx(Ho,{title:o,loading:w,showSummary:W,setShowSummary:A,setAnchorEl:Ge,setSummaryAnchorEl:oe,filterText:p,setFilterText:D,sortedAndFilteredRows:We,selected:i,columns:C,visibleColumns:f,summaryRow:nt,handleClick:it,selectionMode:t}),ho]}):jsxRuntime.jsxs(mo__default.default,{sx:{width:u?"100%":"auto",mb:n?0:2,...n?{flex:1,display:"flex",flexDirection:"column",minHeight:0,height:"100%"}:{}},children:[d&&jsxRuntime.jsx(mo__default.default,{sx:{mb:2},children:jsxRuntime.jsx(qe,{fields:d.fields,filters:d.filters,onFilterChange:d.onFilterChange,onSearch:d.onSearch,variants:d.variants||[],currentVariantId:d.currentVariantId,onVariantLoad:Y,onVariantSave:d.onVariantSave,onVariantDelete:d.onVariantDelete,onVariantSetDefault:d.onVariantSetDefault,loading:w,appId:d.appId,tableKey:r,currentLayout:[{tableKey:r,layoutData:$}],currentLayoutId:le,layoutRefs:[{tableKey:r,layoutId:le}],variantService:d.variantService})}),jsxRuntime.jsxs(oi__default.default,{sx:{width:u?"100%":"auto",mb:n?0:2,display:"flex",flexDirection:"column",overflow:"hidden",...v?{height:v}:n?{flex:1,minHeight:0}:{}},children:[jsxRuntime.jsx(Ro,{filterText:p,setFilterText:D,onRowsPerPageChange:g,rowsPerPage:x,rowsPerPageOptions:P,page:S,count:k,onPageChange:m,actions:a,extraTools:l,grouping:B,setGroupAnchorEl:Me,showSummary:W,setShowSummary:A,setAnchorEl:Ge,setSummaryAnchorEl:oe,handleExport:Ht,onLayoutSave:y||d?.variantService&&d?.appId?J:void 0,loading:w,layoutManager:Ln,onOpenGraphReport:Le?pe:void 0}),jsxRuntime.jsx(wn__default.default,{sx:{flex:1,maxHeight:v||"calc(100vh - 320px)",overflowY:"auto",overflowX:"auto",position:"relative",minHeight:0},children:jsxRuntime.jsx(core.DndContext,{sensors:Lt,collisionDetection:core.closestCenter,onDragEnd:Nt,modifiers:[modifiers.restrictToHorizontalAxis],children:jsxRuntime.jsxs(ni__default.default,{sx:{minWidth:u?750:"auto",width:u?"100%":"auto",tableLayout:Object.keys(Oe).length>0?"fixed":"auto",borderCollapse:"separate",borderSpacing:0},"aria-labelledby":"tableTitle",size:"small",stickyHeader:true,children:[jsxRuntime.jsx(Bo,{columns:C,visibleColumns:f,order:M,orderBy:T,onRequestSort:Ft,onContextMenu:zt,selectionMode:t,grouping:B,isAllExpanded:at,handleToggleAll:E,rowCount:We.length,numSelected:i.length,onSelectAllClick:Vt,columnWidths:Oe,onColumnResize:rt}),jsxRuntime.jsx(Ao,{visibleRows:At,columns:C,visibleColumns:f,selectionMode:t,selected:i,orderBy:T,loading:w,expandedGroups:z,toggleGroupExpand:Gt,handleExpandGroupRecursively:L,handleCollapseGroupRecursively:ee,handleClick:it,onSelectionChange:s,grouping:B,rowKeyProp:I,page:S,rowsPerPage:x}),W&&jsxRuntime.jsx(Vo,{showSummary:W,columns:C,visibleColumns:f,summaryRow:nt,selectionMode:t?.toString(),orderBy:T,zIndex:3})]})})})]}),ho,Le&&jsxRuntime.jsx(Yo,{open:Ee,onClose:Be,model:Wt,tableContent:jsxRuntime.jsx(kt,{title:"Data Body",columns:Bn,rows:Wt.table.rows,rowKey:"id",fullWidth:true,maxHeight:"420px",rowsPerPage:20,rowsPerPageOptions:[20,50,100],graphReport:{enabled:false}})})]})},Vc=kt;var $c=({title:e,hideHeader:o=true,filterConfig:t,tableProps:i,children:s,spacing:a=1})=>jsxRuntime.jsxs(ko,{title:e,hideHeader:o,children:[jsxRuntime.jsxs(material.Stack,{spacing:a,sx:{height:"100%",overflow:"hidden"},children:[t&&jsxRuntime.jsx(material.Box,{sx:{flexShrink:0},children:jsxRuntime.jsx(qe,{...t})}),jsxRuntime.jsx(material.Box,{sx:{flex:1,minHeight:0,overflow:"hidden"},children:jsxRuntime.jsx(kt,{...i,fitContainer:true,filterConfig:void 0})})]}),s]});var Kc=({metadata:e,fetchData:o})=>{let[t,i]=bo.useState(false),[s,a]=bo.useState([]),[l,n]=bo.useState({}),[u,v]=bo.useState(e.variants||[]),[w,S]=bo.useState(e.layout||null),[x,P]=bo.useState(0),[k,m]=bo.useState(0),[g,y]=bo.useState(10),[d,I]=bo.useState([]),[r,b]=bo.useState("asc"),[c,C]=bo.useState("");bo.useEffect(()=>{let B={};e.filters.forEach(H=>{H.defaultValue!==void 0&&(B[H.id]=H.defaultValue);}),n(B);},[e.filters]);let M=bo.useCallback(async(B,H,z,ke,Me)=>{i(true);try{let ie={...B,page:H+1,limit:z,sort:Me,order:ke},oe;o?oe=await o(ie):typeof e.api=="function"?oe=await e.api(ie):e.api&&typeof e.api=="object"?(console.log("Fetching from URL:",e.api.url,ie),oe={rows:[],total:0}):(console.warn("No API configured for report"),oe={rows:[],total:0}),oe&&(a(oe.rows||[]),P(oe.total||0));}catch(ie){console.error("Failed to fetch report data",ie);}finally{i(false);}},[e.api,o]);bo.useEffect(()=>{M(l,k,g,r,c);},[M,k,g,r,c]);let T=()=>{m(0),M(l,0,g,r,c);},p=(B,H)=>{b(H),C(B);},D=B=>{n(B);},f=B=>{if(B.filters){let H=B.filters.find(z=>z.scope==="default"||z.scope===e.id);H&&(n(H.filters),M(H.filters,0,g));}B.layout&&S(B.layout);},W=B=>{let H={...B,id:Date.now().toString(),createdAt:new Date().toISOString()};v(z=>[...z,H]);},A=B=>{S(B);};return {pageProps:{title:e.title,filterConfig:{appId:e.id,fields:e.filters,filters:l,onFilterChange:D,onSearch:T,onVariantLoad:f,onVariantSave:W,onVariantDelete:B=>v(H=>H.filter(z=>z.id!==B)),onVariantSetDefault:B=>{v(H=>H.map(z=>({...z,isDefault:z.id===B})));},variants:u},tableProps:{appId:e.id,columns:e.columns,rows:s,loading:t,rowKey:"id",count:x,page:k,rowsPerPage:g,rowsPerPageOptions:[10,25,50,100],onPageChange:m,onRowsPerPageChange:y,selectionMode:"multiple",selected:d,onSelectionChange:I,onLayoutSave:A,layout:w,title:e.title,showSummary:true,order:r,orderBy:c,onSortChange:p,graphReport:e.graphReport||{enabled:true,title:`${e.title} Graphic Report`}}},filters:l,rows:s,loading:t,refresh:T}};var Rn=64,Mi="#E9EDF2",Ri="linear-gradient(90deg, #F5F7FA 0%, #E9EDF2 50%, #F5F7FA 100%)",Dn=({appTitle:e,logo:o,mode:t="dark",onToggleMode:i,localeLabel:s="EN",searchPlaceholder:a="Ask me...",onSearch:l,user:n,leftSlot:u,rightSlot:v})=>{let S=material.useTheme().palette.mode==="dark",[x,P]=bo.useState(""),k=y=>{y.preventDefault(),l&&l(x.trim());},m=t==="system"?jsxRuntime.jsx(wi__default.default,{fontSize:"small"}):t==="dark"?jsxRuntime.jsx(Ii__default.default,{fontSize:"small"}):jsxRuntime.jsx(ki__default.default,{fontSize:"small"}),g=t==="system"?"Theme: System":t==="dark"?"Theme: Dark":"Theme: Light";return jsxRuntime.jsx(material.AppBar,{position:"sticky",elevation:0,sx:y=>({top:0,zIndex:y.zIndex.drawer+10,height:Rn,backgroundColor:y.palette.mode==="dark"?"#0D0D0D":Mi,backgroundImage:y.palette.mode==="dark"?["radial-gradient(circle at 18% 22%, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0) 45%)","radial-gradient(circle at 78% 32%, rgba(144,202,249,0.14) 0%, rgba(144,202,249,0) 42%)","linear-gradient(90deg, #0A0A0A 0%, #151515 50%, #0A0A0A 100%)","linear-gradient(rgba(255,255,255,0.04) 1px, transparent 1px)","linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px)"].join(","):["radial-gradient(circle at 22% 22%, rgba(255,255,255,0.7) 0%, rgba(255,255,255,0) 48%)","radial-gradient(circle at 76% 24%, rgba(203,213,225,0.45) 0%, rgba(203,213,225,0) 42%)",Ri,"linear-gradient(rgba(15,23,42,0.05) 1px, transparent 1px)","linear-gradient(90deg, rgba(15,23,42,0.04) 1px, transparent 1px)"].join(","),backgroundSize:"auto, auto, auto, 24px 24px, 24px 24px",borderBottom:"1px solid",borderColor:y.palette.mode==="dark"?"rgba(255,255,255,0.12)":"rgba(15,23,42,0.12)"}),children:jsxRuntime.jsxs(material.Toolbar,{sx:{minHeight:`${Rn}px !important`,px:2,gap:2},children:[jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:1.5,sx:{minWidth:220},children:[o||jsxRuntime.jsx(material.Box,{component:"img",src:"/orbcafe.png",alt:"ORBCAFE Logo",sx:{width:44,height:44,display:"block",objectFit:"contain",flexShrink:0}}),e&&jsxRuntime.jsx(material.Typography,{variant:"h6",sx:{fontWeight:700,color:S?"common.white":"#111827"},children:e}),u]}),jsxRuntime.jsx(material.Box,{sx:{flex:1,display:"flex",justifyContent:"center",minWidth:0},children:jsxRuntime.jsx(material.Box,{component:"form",onSubmit:k,sx:{width:"100%",maxWidth:540},children:jsxRuntime.jsx(material.TextField,{size:"small",fullWidth:true,value:x,onChange:y=>P(y.target.value),placeholder:a,InputProps:{startAdornment:jsxRuntime.jsx(material.InputAdornment,{position:"start",children:jsxRuntime.jsx(cn__default.default,{sx:{color:S?"rgba(255,255,255,0.7)":"rgba(15,23,42,0.55)",fontSize:18}})}),sx:{color:S?"common.white":"rgba(17,24,39,0.9)",bgcolor:S?"rgba(255,255,255,0.08)":"#ffffff",borderRadius:999,"& .MuiOutlinedInput-notchedOutline":{borderColor:S?"rgba(255,255,255,0.15)":"rgba(15,23,42,0.2)"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:S?"rgba(255,255,255,0.35)":"rgba(15,23,42,0.35)"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:S?"rgba(255,255,255,0.5)":"rgba(15,23,42,0.55)"}}},inputProps:{style:{color:S?"white":"#111827"}}})})}),jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:1.5,children:[jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:.5,children:[jsxRuntime.jsx(Ti__default.default,{sx:{color:S?"common.white":"#111827",fontSize:18}}),jsxRuntime.jsx(material.Typography,{variant:"caption",sx:{color:S?"common.white":"#111827",fontWeight:500},children:s})]}),jsxRuntime.jsx(material.IconButton,{size:"small",sx:{color:S?"common.white":"#111827"},onClick:i,title:g,children:m}),n&&jsxRuntime.jsxs(material.Stack,{direction:"row",alignItems:"center",spacing:1,children:[jsxRuntime.jsx(material.Box,{sx:{textAlign:"right"},children:jsxRuntime.jsx(material.Typography,{variant:"body2",sx:{color:S?"common.white":"#111827",fontWeight:600,lineHeight:1.2},children:n.name})}),jsxRuntime.jsx(material.Avatar,{src:n.avatarSrc,imgProps:{style:{objectFit:"cover"}},sx:{width:34,height:34,bgcolor:"grey.100",color:"grey.700",fontSize:"0.85rem"},children:n.avatarText||n.name.slice(0,1).toUpperCase()})]}),v]})]})})};var Pn=({menuData:e=[],initialNavigationCollapsed:o=false}={})=>{let{navigationIslandProps:t}=Io({initialCollapsed:o,content:e}),[i,s]=bo.useState(900);bo.useEffect(()=>{let l=()=>s(window.innerHeight);return l(),window.addEventListener("resize",l),()=>window.removeEventListener("resize",l)},[]);let a=bo.useMemo(()=>Math.max(280,i-100),[i]);return {navigationIslandProps:t,navigationMaxHeight:a}};var md=({appTitle:e,menuData:o=[],children:t,showNavigation:i=true,localeLabel:s,user:a,logo:l,onSearch:n,rightHeaderSlot:u,leftHeaderSlot:v,contentSx:w})=>{let[S,x]=bo.useState("system"),[P,k]=bo.useState("light"),[m,g]=bo.useState(false),y=S==="system"?m?P:"light":S;bo.useEffect(()=>{g(true);let b=window.matchMedia("(prefers-color-scheme: dark)"),c=()=>{k(b.matches?"dark":"light");};return c(),b.addEventListener("change",c),()=>b.removeEventListener("change",c)},[]);let d=bo.useMemo(()=>material.createTheme({palette:{mode:y}}),[y]),{navigationIslandProps:I,navigationMaxHeight:r}=Pn({menuData:o,initialNavigationCollapsed:false});return jsxRuntime.jsx(material.ThemeProvider,{theme:d,children:jsxRuntime.jsxs(material.Box,{sx:b=>({minHeight:"100vh",display:"flex",flexDirection:"column",background:b.palette.mode==="dark"?"linear-gradient(180deg, #0A0A0A 0%, #141414 55%, #1A1A1A 100%)":b.palette.background.default}),children:[jsxRuntime.jsx(Dn,{appTitle:e,logo:l,mode:S,onToggleMode:()=>x(b=>b==="system"?"dark":b==="dark"?"light":"system"),localeLabel:s,user:a,onSearch:n,leftSlot:v,rightSlot:u}),jsxRuntime.jsxs(material.Box,{sx:{flex:1,minHeight:0,display:"flex"},children:[i&&jsxRuntime.jsx(material.Box,{sx:{p:1.5,display:"flex",alignItems:"flex-start",flexShrink:0},children:jsxRuntime.jsx(To,{...I,maxHeight:r,colorMode:y})}),jsxRuntime.jsx(material.Box,{sx:{flex:1,minWidth:0,minHeight:0,overflow:"auto",p:1.5,...w},children:t})]})]})})};exports.Button=_t;exports.CAppHeader=Dn;exports.CAppPageLayout=md;exports.CLayoutManagement=bn;exports.CLayoutManager=Cn;exports.CPageLayout=ko;exports.CSmartFilter=qe;exports.CSmartTable=Vc;exports.CStandardPage=$c;exports.CTable=kt;exports.CTableBody=Ec;exports.CTableCell=Bc;exports.CTableContainer=Lc;exports.CTableHead=Ac;exports.CTableRow=Fc;exports.CVariantManagement=bt;exports.CVariantManager=nn;exports.NavigationIsland=To;exports.TreeMenu=Ut;exports.buttonVariants=Hn;exports.useNavigationIsland=Io;exports.usePageLayout=Pn;exports.useStandardReport=Kc;
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import*as co from'react';import co__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,InputAdornment,Popover,ListSubheader,Badge,Switch,Toolbar,TableBody,TableRow,TableCell,TableFooter,Chip}from'@mui/material';import io from'@mui/material/Box';import Wr from'@mui/material/Paper';import $r from'@mui/material/Table';import jr from'@mui/material/TableBody';import xo from'@mui/material/TableCell';import fn from'@mui/material/TableContainer';import Zn from'@mui/material/TableHead';import Qn from'@mui/material/TableRow';import {DndContext,closestCenter}from'@dnd-kit/core';import {restrictToHorizontalAxis}from'@dnd-kit/modifiers';import Zo from'@mui/icons-material/Search';import $n from'@mui/icons-material/ViewColumn';import ln from'@mui/icons-material/Save';import _n from'@mui/icons-material/Download';import Un from'@mui/icons-material/AccountTree';import Kn from'@mui/icons-material/Functions';import Yn from'@mui/icons-material/Insights';import ea from'@mui/material/Checkbox';import ta from'@mui/material/TableSortLabel';import ia from'@mui/icons-material/KeyboardArrowRight';import la from'@mui/icons-material/KeyboardArrowDown';import xa from'@mui/icons-material/Check';import Ca from'@mui/icons-material/ClearAll';import Ba from'@mui/icons-material/Close';import br from'@mui/icons-material/Settings';import xr from'@mui/icons-material/KeyboardArrowUp';import vr from'@mui/icons-material/ArrowRightAlt';import _a from'@mui/icons-material/Star';import {DateCalendar}from'@mui/x-date-pickers/DateCalendar';import {PickersDay}from'@mui/x-date-pickers/PickersDay';import ir from'@mui/icons-material/CalendarMonth';import lr from'@mui/icons-material/Clear';import sr from'@mui/icons-material/ArrowForward';import Me from'dayjs';import cr from'dayjs/plugin/isBetween';import Lr from'@mui/icons-material/Delete';import Vr from'@mui/icons-material/StarBorder';import Fr from'@mui/icons-material/ViewQuilt';function le(...e){return twMerge(clsx(e))}var Nt={primary:"#000000",primaryHover:"#333333"},lt={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"},We={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",full:"rounded-full"},so=()=>"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 wn=cva(so(),{variants:{variant:{default:`${lt.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:`${lt.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:lt.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-[${Nt.primary}] hover:bg-[${Nt.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:We.none,sm:We.sm,md:We.md,full:We.full}},defaultVariants:{variant:"default",size:"default",rounded:"md"}}),Gt=co.forwardRef(({className:e,variant:o,size:t,asChild:r=false,...c},n)=>jsx(r?Slot:"button",{className:le(wn({variant:o,size:t,className:e})),ref:n,...c}));Gt.displayName="Button";function zt({items:e,onItemClick:o,className:t="",level:r=0,expandedIds:c,onToggleExpand:n}){let i=usePathname(),[l,m]=useState(new Set),v=c!==void 0&&n!==void 0,w=v?c:l,D=x=>{if(v)n(x);else {let p=new Set(l);p.has(x)?p.delete(x):p.add(x),m(p);}},b=x=>{x.children&&x.children.length>0&&D(x.id),o&&o(x);};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(x=>{let p=w.has(x.id)||x.isExpanded,f=x.children&&x.children.length>0,k=x.appurl||x.href,T=k?i===k:false;return jsxs("div",{className:"tree-menu-item relative",children:[T&&jsx("div",{className:"absolute left-0 top-2 bottom-2 w-1 bg-blue-500 rounded-r-full z-10"}),jsxs(Gt,{variant:"ghost",className:le("w-full justify-start gap-2 h-auto py-2 relative overflow-hidden group",`ml-${r*4}`,T?"bg-blue-50/80 dark:bg-blue-900/20 text-blue-600 dark:text-blue-400 hover:bg-blue-100/80 dark:hover:bg-blue-900/30":"hover:bg-gray-100/50 dark:hover:bg-gray-800/50 text-gray-700 dark:text-gray-300"),onClick:()=>b(x),children:[f&&jsx("div",{className:le("flex-shrink-0 transition-transform duration-200",p&&"rotate-90",T?"text-blue-500":"text-gray-400 group-hover:text-gray-600 dark:text-gray-500 dark:group-hover:text-gray-300"),children:jsx(ChevronRight,{className:"h-4 w-4"})}),!f&&jsx("div",{className:"w-4 h-4 flex-shrink-0"}),x.icon&&jsx("div",{className:le("flex-shrink-0 transition-colors duration-200",T?"text-blue-500":"text-gray-400 group-hover:text-gray-600 dark:text-gray-500 dark:group-hover:text-gray-300"),children:x.icon}),jsxs("div",{className:"flex-1 text-left overflow-hidden z-10",children:[jsx("div",{className:le("text-sm truncate transition-colors duration-200",T?"font-semibold":"font-medium"),children:x.title||x.label}),x.description&&jsx("div",{className:le("text-xs truncate transition-colors duration-200",T?"text-blue-400/80 dark:text-blue-300/60":"text-gray-500 dark:text-gray-400"),title:x.description,children:x.description})]})]}),f&&jsx("div",{className:le("grid transition-[grid-template-rows] duration-300 ease-in-out",p?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:jsx("div",{className:"overflow-hidden",children:jsx(zt,{items:x.children,onItemClick:o,level:r+1,expandedIds:c,onToggleExpand:n})})})]},x.id)})})}var wi=({collapsed:e,onToggle:o,className:t="",maxHeight:r,menuData:c=[]})=>{let n=useRouter(),[i,l]=useState(""),[m,v]=useState(new Set);useEffect(()=>{e&&v(new Set);},[e]);let w=useCallback(p=>{let f=[],k=T=>{T.forEach(d=>{f.push(d.id),d.children&&k(d.children);});};return k(p),f},[]),D=useMemo(()=>{if(!i.trim())return c;let p=f=>f.reduce((k,T)=>{let d=T.title?.toLowerCase().includes(i.toLowerCase())||T.description?.toLowerCase().includes(i.toLowerCase()),L=T.children?p(T.children):[];return (d||L.length>0)&&k.push({...T,children:L.length>0?L:T.children}),k},[]);return p(c)},[i,c]),b=useMemo(()=>i.trim()?new Set(w(c)):m,[i,c,m,w]),x=useCallback(async p=>{if(console.log("\u{1F5B1}\uFE0F \u5BFC\u822A\u83DC\u5355\u9879\u70B9\u51FB:",p),p.id==="chat"||p.appurl==="/chat"){console.log("\u{1F4AC} \u68C0\u6D4B\u5230chat\u83DC\u5355\u70B9\u51FB\uFF0C\u8DF3\u8F6C\u5230\u65B0\u7684\u804A\u5929\u89C6\u56FE");try{n.push("/chat?new=true");}catch(k){console.error("\u274C \u65E0\u6CD5\u8DF3\u8F6C\u5230\u65B0\u804A\u5929\u89C6\u56FE:",k),n.push("/chat");}return}let f=p.appurl||p.href;f&&(f.startsWith("http://")||f.startsWith("https://")?window.open(f,"_blank"):n.push(f));},[n]);return jsxs("div",{className:`flex flex-col bg-white/10 dark:bg-[#101928] backdrop-blur-xl border border-white/20 dark:border-white/10 shadow-[0_4px_8px_0_rgba(31,38,135,0.1)] ${e?"w-14 rounded-full":"w-[234px] rounded-2xl"} relative ${t}`,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 text-gray-500 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors duration-200",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:i,onChange:p=>l(p.target.value),className:"w-full pl-10 pr-4 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white placeholder-gray-500 dark:placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"}),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 text-gray-400 dark:text-gray-500"})})]})}),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:D.length===0?jsx("div",{className:"flex items-center justify-center py-8 text-gray-500 text-sm",children:e?"\u{1F4C2}":i?"\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(zt,{items:D,onItemClick:x,className:"space-y-1",expandedIds:b,onToggleExpand:p=>{let f=new Set(m);D.some(T=>T.id===p)?f.has(p)?f.delete(p):(D.forEach(T=>{T.id!==p&&f.has(T.id)&&f.delete(T.id);}),f.add(p)):f.has(p)?f.delete(p):f.add(p),v(f);}})}),e&&jsx("div",{className:"space-y-2",children:c.map(p=>jsx("div",{className:"space-y-1",children:jsx("button",{onClick:()=>{o();let f=new Set([p.id]);v(f);},className:"w-full flex items-center justify-center p-2 rounded-lg text-gray-600 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-gray-800 cursor-pointer transition-colors duration-200",title:`\u5C55\u5F00\u67E5\u770B ${p.title}`,children:p.icon||jsx("div",{className:"w-6 h-6 bg-blue-100 dark:bg-blue-900/20 rounded text-xs flex items-center justify-center font-medium text-blue-600 dark:text-blue-400",children:p.title?.charAt(0)||"?"})})},p.id))})]})}),!e&&jsx("button",{onClick:o,className:"absolute -bottom-1 -right-1 w-6 h-6 bg-transparent hover:bg-white/20 dark:hover:bg-gray-800/50 rounded-full flex items-center justify-center transition-all duration-300 ease-in-out z-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:"dark:border-yellow-400",style:{width:"32px",height:"32px",borderRadius:"16px",border:"3px solid #21BCFF",backgroundColor:"transparent",position:"absolute",top:"-16px",left:"-16px"}})})})]})};var Mi=(e={})=>{let{initialCollapsed:o=false,content:t=[]}=e,[r,c]=useState(o),[n,i]=useState(t),l=useCallback(()=>{c(v=>!v);},[]),m=useMemo(()=>({collapsed:r,onToggle:l,menuData:n}),[r,l,n]);return {collapsed:r,setCollapsed:c,toggleCollapsed:l,menuData:n,setMenuData:i,navigationIslandProps:m}};var yo=({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 bo=e=>{let o="0.75rem";return jsxs(Toolbar,{sx:{pl:{sm:2},pr:{xs:1,sm:1},alignItems:"center"},children:[jsx(Typography,{sx:{flex:"1 1 100%",fontWeight:"bold"},variant:"h6",id:"tableTitle",component:"div",children:e.title||"Table"}),jsxs(Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsx(TextField,{size:"small",placeholder:"Search...",value:e.filterText,onChange:t=>e.setFilterText(t.target.value),InputProps:{sx:{fontSize:o,"& .MuiInputBase-input":{fontSize:o},"& .MuiInputBase-input::placeholder":{fontSize:o,opacity:1}},startAdornment:jsx(InputAdornment,{position:"start",children:jsx(Zo,{fontSize:"small"})})},sx:{width:300}}),jsx(Tooltip,{title:"Group By",children:jsx(IconButton,{onClick:t=>e.setGroupAnchorEl(t.currentTarget),children:jsx(Badge,{badgeContent:e.grouping?.length,color:"primary",children:jsx(Un,{})})})}),jsx(Tooltip,{title:"Summary",children:jsx(IconButton,{onClick:t=>e.setSummaryAnchorEl(t.currentTarget),color:e.showSummary?"primary":"default",children:jsx(Kn,{})})}),jsx(Tooltip,{title:"Columns",children:jsx(IconButton,{onClick:t=>e.setAnchorEl(t.currentTarget),children:jsx($n,{})})}),jsx(Tooltip,{title:"Export",children:jsx(IconButton,{onClick:e.handleExport,children:jsx(_n,{})})}),e.onOpenGraphReport&&jsx(Tooltip,{title:"Graphic Report",children:jsx(IconButton,{onClick:e.onOpenGraphReport,children:jsx(Yn,{})})}),e.onLayoutSave&&!e.layoutManager&&jsx(Tooltip,{title:"Save Layout",children:jsx(IconButton,{onClick:t=>e.onLayoutSave(t),children:jsx(ln,{})})}),e.layoutManager]})]})};var So=e=>{let{onSelectAllClick:o,order:t,orderBy:r,numSelected:c=0,rowCount:n=0,onRequestSort:i,columns:l,visibleColumns:m,selectionMode:v,onColumnResize:w,columnWidths:D}=e,[b,x]=useState(null),p=useRef(null),f=a=>S=>{b||i(a);},k=(a,S,s)=>{a.preventDefault(),a.stopPropagation(),x(S),p.current={startX:a.clientX,startWidth:s,colId:S},document.addEventListener("mousemove",T),document.addEventListener("mouseup",d),document.body.style.cursor="col-resize";},T=a=>{if(!p.current)return;let{startX:S,startWidth:s,colId:h}=p.current,I=a.clientX-S,C=Math.max(50,s+I);w&&w(h,C);},d=()=>{x(null),p.current=null,document.removeEventListener("mousemove",T),document.removeEventListener("mouseup",d),document.body.style.cursor="";};return useEffect(()=>()=>{document.removeEventListener("mousemove",T),document.removeEventListener("mouseup",d);},[]),jsx(Zn,{children:jsxs(Qn,{children:[(v==="multiple"||v==="single")&&jsx(xo,{padding:"checkbox",sx:a=>({width:48,backgroundColor:a.palette.mode==="dark"?"#000000":"#f5f5f5",color:a.palette.mode==="dark"?"#ffffff":a.palette.text.primary}),children:jsx(ea,{color:"primary",indeterminate:c>0&&c<n,checked:n>0&&c===n,onChange:o,disabled:v==="single"})}),l.filter(a=>m.includes(a.id)).map(a=>{let S=D?.[a.id]||a.minWidth||100;return jsxs(xo,{align:"left",padding:a.disablePadding?"none":"normal",sortDirection:r===a.id?t:false,style:{width:S,minWidth:S,maxWidth:S},sx:s=>({position:"relative",backgroundColor:s.palette.mode==="dark"?"#000000":"#f5f5f5",color:s.palette.mode==="dark"?"#ffffff":s.palette.text.primary,fontWeight:"bold",userSelect:"none"}),children:[jsx(ta,{active:r===a.id,direction:r===a.id?t:"asc",onClick:f(a.id),sx:s=>({"&.MuiTableSortLabel-root":{width:"100%"},"& .MuiTableSortLabel-icon":{color:s.palette.mode==="dark"?"#ffffff":s.palette.text.primary,opacity:r===a.id?1:0,transition:"opacity 0.2s"},"&:hover .MuiTableSortLabel-icon":{opacity:.5},"&.Mui-active .MuiTableSortLabel-icon":{opacity:1,color:s.palette.mode==="dark"?"#ffffff":s.palette.text.primary},fontWeight:"bold",color:s.palette.mode==="dark"?"#ffffff":s.palette.text.primary}),children:jsx(io,{component:"span",sx:{overflow:"visible",textOverflow:"clip",whiteSpace:"normal",lineHeight:1.2,wordBreak:"break-word",pr:1},children:a.label})}),jsx(io,{onMouseDown:s=>k(s,a.id,typeof S=="number"?S:100),onClick:s=>s.stopPropagation(),sx:{position:"absolute",right:0,top:0,bottom:0,width:5,cursor:"col-resize","&:hover":{backgroundColor:"primary.main",opacity:.5},zIndex:1}})]},a.id)})]})})};var wo=e=>{let{visibleRows:o,visibleColumns:t,selected:r=[],handleClick:c,columns:n,toggleGroupExpand:i,expandedGroups:l=new Set,selectionMode:m}=e,v=b=>r.indexOf(b)!==-1,w=m==="multiple"||m==="single",D=t.length+(w?1:0);return jsxs(TableBody,{children:[o.map((b,x)=>{if(b.type==="group"){let p=l.has(b.id),f=b.childIds||[],k=f.filter(a=>v(a)).length,T=f.length>0&&k===f.length,d=k>0&&k<f.length,L=a=>{if(a.stopPropagation(),!!e.onSelectionChange)if(T){let S=r.filter(s=>!f.includes(s));e.onSelectionChange(S);}else {let S=Array.from(new Set([...r,...f]));e.onSelectionChange(S);}};return jsx(TableRow,{sx:{backgroundColor:"#f5f5f5"},children:jsx(TableCell,{colSpan:D,sx:{py:1,pl:b.level*4+2},children:jsxs(Box,{sx:{display:"flex",alignItems:"center"},children:[jsx(IconButton,{size:"small",onClick:()=>i&&i(b.id),sx:{mr:1},children:p?jsx(la,{}):jsx(ia,{})}),w&&jsx(Checkbox,{size:"small",checked:T,indeterminate:d,onChange:L,onClick:a=>a.stopPropagation(),sx:{mr:1,p:.5}}),jsxs(Typography,{variant:"body2",fontWeight:"bold",children:[b.field,": ",b.value," (",b.count,")"]})]})})},b.id)}else {let p=b.data||b,f=b.id||p.id||x,k=v(f),T=`enhanced-table-checkbox-${x}`,L=(b.level!==void 0?b.level:0)*4;return jsxs(TableRow,{hover:true,onClick:a=>c&&c(a,p),role:"checkbox","aria-checked":k,tabIndex:-1,selected:k,sx:{cursor:"pointer"},children:[w&&jsx(TableCell,{padding:"checkbox",sx:{pl:L>0?L+1:void 0},children:jsx(Checkbox,{color:"primary",checked:k,inputProps:{"aria-labelledby":T}})}),n.filter(a=>t.includes(a.id)).map((a,S)=>{let h=!w&&S===0&&L>0?{pl:L+2}:{};return jsx(TableCell,{align:"left",sx:h,children:a.render?a.render(p[a.id],p):(function(){let C=p[a.id];if(a.numeric){if(typeof C=="number")return C.toLocaleString();if(typeof C=="string"&&C.trim()!==""&&!isNaN(Number(C)))return Number(C).toLocaleString()}return C})()},a.id)})]},f)}}),o.length===0&&jsx(TableRow,{children:jsx(TableCell,{colSpan:D,align:"center",children:"No data"})})]})};var Io=e=>{let{visibleColumns:o,summaryRow:t,selectionMode:r}=e;if(!e.showSummary)return null;let c=r==="multiple"||r==="single";return jsx(TableFooter,{sx:{position:"sticky",bottom:0,zIndex:e.zIndex,bgcolor:"background.paper"},children:jsxs(TableRow,{children:[c&&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 l=t[n];return l==null||l===""?"":typeof l=="number"?l.toLocaleString():typeof l=="string"&&l.trim()!==""&&!isNaN(Number(l))?Number(l).toLocaleString():l})()},n))]})})};var Mo=e=>jsx(Box,{sx:{p:2},children:jsx(Typography,{children:"Mobile View Not Implemented"})});var Po=({groupAnchorEl:e,setGroupAnchorEl:o,grouping:t,setGrouping:r,columns:c,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(Ca,{}),children:"Clear All"})]}),jsx(Divider,{}),c.map(i=>{let l=t.includes(i.id),m=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:l,size:"small"}),jsx(ListItemText,{primary:i.label}),l&&jsx(Badge,{badgeContent:m,color:"primary",sx:{mr:2}})]})},i.id)})]}),Eo=({anchorEl:e,setAnchorEl:o,columns:t,visibleColumns:r,toggleColumnVisibility:c})=>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:()=>c(n.id),children:[jsx(Checkbox,{checked:r.includes(n.id),size:"small"}),jsx(ListItemText,{primary:n.label})]},n.id))]}),Bo=({anchorEl:e,setAnchorEl:o,showSummary:t,setShowSummary:r,columns:c,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:l=>r(l.target.checked),size:"small"}),label:"Show Summary Row"})}),jsx(Divider,{}),c.filter(l=>l.numeric).map(l=>jsxs(MenuItem,{onClick:()=>i(l.id),disabled:!t,children:[jsx(Checkbox,{checked:n.includes(l.id),size:"small"}),jsx(ListItemText,{primary:l.label})]},l.id)),c.filter(l=>l.numeric).length===0&&jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"No numeric columns"})})]}),Lo=({contextMenu:e,handleCloseContextMenu:o,columns:t,visibleColumns:r,toggleColumnVisibility:c})=>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:()=>c(n.id),children:[jsx(ListItemIcon,{children:r.includes(n.id)&&jsx(xa,{fontSize:"small"})}),jsx(ListItemText,{children:n.label})]},n.id))]});var $e=(e,o=2)=>e.toLocaleString(void 0,{maximumFractionDigits:o}),Vo=({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 pt=["#1E88E5","#1ABC9C","#FBC02D","#EF5350","#7E57C2","#78909C"],ka=({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))})},Ia=({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))})},Ra=({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((c,n)=>{let i=o;return o+=c.percent,`${pt[n%pt.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((c,n)=>jsxs(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsx(Box,{sx:{width:10,height:10,borderRadius:"50%",bgcolor:pt[n%pt.length]}}),jsx(Typography,{variant:"caption",sx:{flex:1},children:c.name}),jsxs(Typography,{variant:"caption",sx:{fontWeight:700},children:[c.percent.toFixed(0),"%"]})]},c.name))})]})},Yt=({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]}),Fo=({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(Yt,{title:"Billable by Dimension",subtitle:"Top values by billable hours",children:jsx(ka,{data:e})}),jsx(Yt,{title:"Efficiency by Person",subtitle:"Lowest efficiency first",children:jsx(Ia,{data:o})}),jsx(Yt,{title:"Status Distribution",subtitle:"Record ratio by status",children:jsx(Ra,{data:t})})]});var Go=({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(Ba,{})})]})}),jsxs(Box,{sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,overflow:"auto",minHeight:0},children:[jsx(Vo,{kpis:t.kpis}),jsx(Fo,{billableByPrimary:t.charts.billableByPrimary,efficiencyBySecondary:t.charts.efficiencyBySecondary,statusDistribution:t.charts.statusDistribution}),r]})]})});var ve={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"]},La=5,Oo=e=>e.toLowerCase().replace(/[\s_-]/g,""),Se=(e,o,t,r)=>{if(o)return o;if(e.length===0)return r;let c=Object.keys(e[0]),n=new Map(c.map(i=>[Oo(i),i]));for(let i of t){let l=n.get(Oo(i));if(l)return l}return c[0]||r},ye=e=>{if(typeof e=="number")return Number.isFinite(e)?e:0;if(typeof e=="string"){let o=Number(e.replace(/,/g,"").trim());return Number.isFinite(o)?o:0}return 0},he=(e,o)=>e==null||e===""?o:String(e),Aa=(e,o,t,r)=>{let c=new Map;return e.forEach(n=>{let i=he(n[o],"Unassigned");c.set(i,(c.get(i)||0)+ye(n[t]));}),Array.from(c.entries()).map(([n,i])=>({name:n,value:i})).sort((n,i)=>i.value-n.value).slice(0,r)},Va=(e,o,t,r,c)=>{let n=new Map;return e.forEach(i=>{let l=he(i[o],"Unassigned"),m=n.get(l)||{report:0,billable:0};m.report+=ye(i[t]),m.billable+=ye(i[r]),n.set(l,m);}),Array.from(n.entries()).map(([i,l])=>({name:i,value:l.report>0?l.billable/l.report*100:0})).sort((i,l)=>i.value-l.value).slice(0,c)},Fa=(e,o)=>{let t=e.length;if(t===0)return [];let r=new Map;return e.forEach(c=>{let n=he(c[o],"Unassigned");r.set(n,(r.get(n)||0)+1);}),Array.from(r.entries()).map(([c,n])=>({name:c,value:n,percent:n/t*100}))},zo=({rows:e,config:o})=>{let t=useMemo(()=>{let m=o?.fieldMapping;return {primaryDimension:Se(e,m?.primaryDimension,ve.primaryDimension,"Category"),secondaryDimension:Se(e,m?.secondaryDimension,ve.secondaryDimension,"Owner"),status:Se(e,m?.status,ve.status,"Status"),date:Se(e,m?.date,ve.date,"Date"),description:Se(e,m?.description,ve.description,"Description"),reportHours:Se(e,m?.reportHours,ve.reportHours,"ReportHours"),billableHours:Se(e,m?.billableHours,ve.billableHours,"BillableHours"),amount:Se(e,m?.amount,ve.amount,"Amount")}},[e,o?.fieldMapping]),r=useMemo(()=>e.map((m,v)=>{let w=ye(m[t.reportHours]),D=ye(m[t.billableHours]),b=ye(m[t.amount]),x=w>0?D/w*100:0;return {id:`graph-row-${v}`,Date:he(m[t.date],""),Primary:he(m[t.primaryDimension],"Unassigned"),Secondary:he(m[t.secondaryDimension],"Unassigned"),Description:he(m[t.description],""),ReportHours:w,BillableHours:D,Amount:b,Efficiency:x,Status:he(m[t.status],"Unassigned")}}),[e,t]),c=useMemo(()=>{let m=r.length,v=r.reduce((f,k)=>f+ye(k.ReportHours),0),w=r.reduce((f,k)=>f+ye(k.BillableHours),0),D=r.reduce((f,k)=>f+ye(k.Amount),0),b=v>0?w/v*100:0,x=o?.statusFlagValues||["flag","flagged","warning","risk"],p=r.filter(f=>x.includes(he(f.Status,"").toLowerCase())).length;return {totalRecords:m,totalReportHours:v,totalBillableHours:w,efficiency:b,totalAmount:D,flaggedCount:p}},[r,o?.statusFlagValues]),n=o?.topN||La,i=useMemo(()=>({billableByPrimary:Aa(r,"Primary","BillableHours",n),efficiencyBySecondary:Va(r,"Secondary","ReportHours","BillableHours",n),statusDistribution:Fa(r,"Status")}),[r,n]),l=useMemo(()=>({title:o?.title||"Graphic Report",kpis:c,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,c,r]);return {fieldMapping:t,model:l}};var gt=({variants:e,currentVariantId:o,onLoad:t,onSave:r,onDelete:c,onSetDefault:n})=>{let i="0.75rem",[l,m]=useState(false),[v,w]=useState(""),[D,b]=useState(false),[x,p]=useState(false),f=e.find(d=>d.id===o);return jsxs(Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsx(Typography,{variant:"body2",sx:{fontWeight:"bold",minWidth:"fit-content",fontSize: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:d=>d.name+(d.isDefault?" (Default)":""),value:f||null,onChange:(d,L)=>{L&&t(L);},renderInput:d=>jsx(TextField,{...d,variant:"outlined",size:"small",InputProps:{...d.InputProps,sx:{fontSize:i}},placeholder:"Select Variant"}),renderOption:(d,L)=>jsx("li",{...d,children:jsxs(Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsx(Typography,{sx:{flex:1,fontSize:i},children:L.name}),L.isDefault&&jsx(_a,{fontSize:"small",color:"action"})]})})}),jsx(Tooltip,{title:"Save View",children:jsx(IconButton,{onClick:()=>{w(f?.name||"New Variant"),b(f?.isDefault||false),p(f?.isPublic||false),m(true);},size:"small",color:"primary",children:jsx(ln,{})})}),jsxs(Dialog,{open:l,onClose:()=>m(false),children:[jsx(DialogTitle,{children:"Save View"}),jsxs(DialogContent,{children:[jsx(TextField,{autoFocus:true,margin:"dense",label:"View Name",fullWidth:true,variant:"outlined",value:v,onChange:d=>w(d.target.value)}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:D,onChange:d=>b(d.target.checked)}),label:"Set as Default"}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:x,onChange:d=>p(d.target.checked)}),label:"Public (All Users)"})]}),jsxs(DialogActions,{children:[jsx(Button,{onClick:()=>m(false),children:"Cancel"}),jsx(Button,{onClick:()=>{r({name:v,isDefault:D,isPublic:x,description:""}),m(false);},variant:"contained",children:"Save"})]})]})]})};var Ya="http://127.0.0.1:8515",Ko=({appId:e,tableKey:o="default",currentFilters:t,currentLayoutId:r,layoutRefs:c,onLoad:n,serviceUrl:i=Ya,onError:l,onSuccess:m,currentVariantId:v,onVariantChange:w})=>{let[D,b]=useState([]),[x,p]=useState(""),f=v!==void 0?v:x,k=s=>{v===void 0&&p(s),w&&w(s);},T=useCallback(async()=>{if(!e)return [];try{let s=await fetch(`${i}/api/variants?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!s.ok)throw new Error("Failed to fetch variants");let h=await s.json();b(h);let I=h.find(C=>C.isDefault);return I&&!f&&(k(I.id),n(I)),h}catch(s){return console.error("Error fetching variants",s),l&&l("Failed to load variants"),[]}},[e,o,i,l,f,n]);return useEffect(()=>{T();},[e,o]),jsx(gt,{variants:D,currentVariantId:f,onLoad:s=>{k(s.id),n(s);},onSave:async s=>{try{let h=D.find(A=>A.name===s.name),I=h?h.id:Date.now().toString(),C=[];if(h&&(Array.isArray(h.filters)?C=[...h.filters]:h.filters&&(C=[{scope:"default",filters:h.filters}])),s.scope==="Search"||s.scope==="Both"){let A=(Array.isArray(t),t);if(A)if(Array.isArray(A)&&A.length>0&&A[0].scope)A.forEach(F=>{let E=C.findIndex(G=>G.scope===F.scope);E>=0?C[E]=F:C.push(F);});else {let F={scope:o,filters:A},E=C.findIndex(G=>G.scope===o);E>=0?C[E]=F:C.push(F);}}let u=h?.layout||{},M=[];if(h&&Array.isArray(h.layoutRefs)&&(M=[...h.layoutRefs]),s.scope==="Layout"||s.scope==="Both")if(c&&c.length>0)c.forEach(A=>{let F=M.findIndex(E=>E.tableKey===A.tableKey);F>=0?M[F]=A:M.push(A);});else {let A={tableKey:o,layoutId:r||null},F=M.findIndex(E=>E.tableKey===o);F>=0?M[F]=A:M.push(A);}let g={appId:e,tableKey:o,...s,id:I,createdAt:new Date().toISOString(),filters:C,layout:u,layoutRefs:M};if(!(await fetch(`${i}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)})).ok)throw new Error("Failed to save variant");m&&m("Variant saved successfully"),await T(),k(I),n(g);}catch(h){console.error("Error saving variant",h),l&&l("Failed to save variant");}},onDelete:async s=>{try{if(!(await fetch(`${i}/api/variants/${s}`,{method:"DELETE"})).ok)throw new Error("Failed to delete variant");f===s&&k(""),T(),m&&m("Variant deleted successfully");}catch(h){console.error("Error deleting variant",h),l&&l("Failed to delete variant");}},onSetDefault:async s=>{try{let h=D.find(u=>u.id===s);if(!h)return;let I={appId:e,tableKey:o,...h,isDefault:!0};if(!(await fetch(`${i}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(I)})).ok)throw new Error("Failed to set default variant");await T(),m&&m("Default variant updated");}catch(h){console.error("Error setting default variant",h),l&&l("Failed to update default variant");}}})};Me.extend(cr);var dr=[null,null],eo="0.75rem",ur=styled(PickersDay,{shouldForwardProp:e=>e!=="isInRange"&&e!=="isStart"&&e!=="isEnd"&&e!=="isHovered"})(({theme:e,isInRange:o,isStart:t,isEnd:r,isHovered:c})=>({...o&&{borderRadius:0,backgroundColor:e.palette.primary.light,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.main}},...c&&!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%"}})),Xo=({label:e="Date Range",value:o=dr,onChange:t})=>{let[r,c]=useState(null),[n,i]=useState(o),[l,m]=useState("start"),[v,w]=useState(null),[D,b]=useState(o[0]||Me()),x=co__default.useRef(o);useEffect(()=>{let[I,C]=o,[u,M]=x.current,g=F=>F&&typeof F.isSame=="function",W=!(I===null&&u===null||g(I)&&g(u)&&I.isSame(u,"day")),A=!(C===null&&M===null||g(C)&&g(M)&&C.isSame(M,"day"));(W||A)&&(i(o),o[0]&&g(o[0])&&b(o[0])),x.current=o;},[o]);let p=I=>{c(I.currentTarget);},f=()=>{c(null),m("start"),w(null);},k=!!r,T=I=>{if(!I)return;let C=[...n];if(l==="start")C=[I,null],m("end");else {let u=C[0];u&&I.isBefore(u)?(C=[I,null],m("end")):(C=[u,I],m("start"));}i(C);},d=I=>{let C=Me(),u=[null,null];switch(I){case "today":u=[C,C];break;case "week":u=[C.startOf("week"),C.endOf("week")];break;case "month":u=[C.startOf("month"),C.endOf("month")];break}i(u),m("start"),b(C);},L=()=>{i([null,null]),m("start"),b(Me());},a=()=>{t&&t(n),f();},S=()=>{i(o),m("start"),f();},s=useCallback(I=>{let{day:C,...u}=I,[M,g]=n,W=M?C.isSame(M,"day"):false,A=g?C.isSame(g,"day"):false,F=M&&g?C.isBetween(M,g,"day","()"):false,E=false;return l==="end"&&M&&!g&&v&&C.isAfter(M,"day")&&C.isBefore(v.add(1,"day"),"day")&&(E=true),jsx(ur,{...u,day:C,disableMargin:true,isStart:W,isEnd:A,isInRange:F||E,onMouseEnter:()=>w(C)})},[n,l,v]),h=I=>I?I.format("YYYY-MM-DD"):"";return jsxs(Box,{children:[jsx(TextField,{label:e,value:n[0]?`${h(n[0])} - ${h(n[1])}`:"",onClick:p,fullWidth:true,size:"small",InputLabelProps:{sx:{fontSize:eo}},InputProps:{readOnly:true,sx:{fontSize:eo,"& .MuiOutlinedInput-input":{fontSize:eo},paddingRight:"4px"},endAdornment:jsxs(InputAdornment,{position:"end",sx:{ml:0},children:[(n[0]||n[1])&&jsx(IconButton,{size:"small",onClick:I=>{I.stopPropagation(),L();},edge:"end",sx:{mr:.5,padding:"2px"},children:jsx(lr,{sx:{fontSize:"1rem"}})}),jsx(IconButton,{size:"small",edge:"end",onClick:p,sx:{padding:"2px"},children:jsx(ir,{sx:{fontSize:"1rem"},color:"action"})})]})}}),jsxs(Popover,{open:k,anchorEl:r,onClose:f,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:l==="start"?"primary.main":"divider",borderRadius:1,bgcolor:l==="start"?"action.hover":"transparent",flex:1,cursor:"pointer"},onClick:()=>m("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(sr,{color:"action",fontSize:"small"}),jsxs(Box,{sx:{p:1,border:1,borderColor:l==="end"?"primary.main":"divider",borderRadius:1,bgcolor:l==="end"?"action.hover":"transparent",flex:1,cursor:"pointer"},onClick:()=>{n[0]&&m("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:()=>d("today"),clickable:true,size:"small",variant:"outlined"}),jsx(Chip,{label:"This Week",onClick:()=>d("week"),clickable:true,size:"small",variant:"outlined"}),jsx(Chip,{label:"This Month",onClick:()=>d("month"),clickable:true,size:"small",variant:"outlined"})]})}),jsx(DateCalendar,{value:null,referenceDate:D,onMonthChange:b,onYearChange:b,onChange:T,slots:{day:s},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:S,color:"inherit",children:"Cancel"}),jsx(Button,{size:"small",variant:"contained",onClick:a,children:"Done"})]})]})]})};var xt={equals:"=",contains:"\u2287",notContains:"\u2285",wildcard:"*","=":"=","!=":"!=",">":">","<":"<",">=":"\u2265","<=":"\u2264",between:"\u2194"},Sr={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"},Tr=["equals","contains","notContains","wildcard"],Qo=["=","!=",">","<",">=","<=","between"],Z="0.75rem",wr=({field:e,value:o,onChange:t})=>{let[r,c]=useState(null),[n,i]=useState(null),[l,m]=useState(""),[v,w]=useState(""),[D,b]=useState(false),[x,p]=useState(""),[f,k]=useState("");useEffect(()=>{let u=setTimeout(()=>{k(x);},1e3);return ()=>clearTimeout(u)},[x]);let T=o?.operator||(e.type==="number"?"=":"equals"),d=o?.value,L=u=>Sr[u]||u,a=u=>{c(u.currentTarget);},S=u=>{t({...o,operator:u,value:d}),c(null);},s={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"}}}}}},h=e.type||"text";if(h==="date"){let M=(g=>{if(!g)return [null,null];if(Array.isArray(g)&&g.length===2){let W=g[0]?Me.isDayjs(g[0])?g[0]:Me(g[0]):null,A=g[1]?Me.isDayjs(g[1])?g[1]:Me(g[1]):null;return [W,A]}return Me.isDayjs(g)||typeof g=="string"?[Me.isDayjs(g)?g:Me(g),null]:[null,null]})(d);return jsx(Xo,{label:e.label,value:M,onChange:g=>t({value:g,operator:"between"})})}if(h==="number"&&T==="between"){let u=()=>{t({value:[l,v],operator:"between"}),i(null);},M=Array.isArray(d)?`${d[0]||""} - ${d[1]||""}`:"";return jsxs(Fragment,{children:[jsx(TextField,{...s,label:e.label,value:M,placeholder:"Min - Max",InputProps:{...s.InputProps,startAdornment:jsx(InputAdornment,{position:"start",children:jsx(Tooltip,{title:L("between"),children:jsx(IconButton,{size:"small",onClick:a,sx:{width:24,height:24,fontSize:Z},children:xt.between})})}),readOnly:true},onClick:g=>i(g.currentTarget)}),jsx(Menu,{anchorEl:r,open:!!r,onClose:()=>c(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,minHeight:"auto",py:.5}}},children:Qo.map(g=>jsxs(MenuItem,{selected:g===T,onClick:()=>S(g),children:[jsx(Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:xt[g]}),jsx(ListItemText,{primary:L(g),primaryTypographyProps:{fontSize:Z}})]},g))}),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:l,onChange:g=>m(g.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}}}),jsx(vr,{color:"action"}),jsx(TextField,{size:"small",label:"Max",type:"number",value:v,onChange:g=>w(g.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}}}),jsx(Button,{variant:"contained",size:"small",onClick:u,children:"OK"})]})})]})}if(h==="select")return jsxs(TextField,{...s,select:true,label:e.label,value:d||"",onChange:u=>t({...o,value:u.target.value,operator:"equals"}),children:[jsx(MenuItem,{value:"",children:jsx("em",{children:"None"})}),e.options?.map(u=>jsx(MenuItem,{value:u.value,children:u.label},u.value))]});if(h==="multi-select"){let u=Array.isArray(d)?d:[],M=e.options?.filter(g=>g.label.toLowerCase().includes(f.toLowerCase()))||[];return jsxs(TextField,{...s,select:true,label:e.label,value:u,onChange:g=>t({...o,value:g.target.value,operator:"anyOf"}),SelectProps:{...s.SelectProps,multiple:true,onClose:()=>{p(""),k("");},renderValue:g=>{if(!Array.isArray(g)||g.length===0)return jsx("em",{children:"None"});let W=F=>e.options?.find(E=>E.value===F)?.label||F,A=g.map(W);return A.length>2?`${A.slice(0,2).join(", ")} +${A.length-2}`:A.join(", ")}},children:[jsx(ListSubheader,{children:jsx(TextField,{size:"small",autoFocus:true,placeholder:"Search...",fullWidth:true,InputProps:{startAdornment:jsx(InputAdornment,{position:"start",children:jsx(Zo,{fontSize:"small"})}),sx:{fontSize:Z}},value:x,onChange:g=>p(g.target.value),onKeyDown:g=>{g.key!=="Escape"&&g.stopPropagation();},onClick:g=>g.stopPropagation()})}),M.length>0?M.map(g=>jsxs(MenuItem,{value:g.value,children:[jsx(Checkbox,{checked:u.indexOf(g.value)>-1,size:"small"}),jsx(ListItemText,{primary:g.label,primaryTypographyProps:{fontSize:Z}})]},g.value)):jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"No options found",primaryTypographyProps:{fontSize:Z}})})]})}let I=h==="number"?Qo:Tr,C=D||d!==void 0&&d!==""&&d!==null||!!r;return jsxs(Fragment,{children:[jsx(TextField,{...s,label:e.label,sx:{minWidth:"120px"},value:d||"",type:h==="number"?"number":"text",onChange:u=>t({...o,value:u.target.value,operator:T}),onFocus:()=>b(true),onBlur:()=>b(false),InputProps:{...s.InputProps,startAdornment:C?jsx(InputAdornment,{position:"start",children:jsx(Tooltip,{title:L(T),children:jsx(IconButton,{size:"small",onClick:a,onMouseDown:u=>u.preventDefault(),sx:{width:24,height:24,fontSize:Z,fontWeight:"bold",color:"primary.main",bgcolor:"action.hover"},children:xt[T]})})}):null,endAdornment:e.hasSearchIcon?jsx(InputAdornment,{position:"end",children:jsx(Zo,{color:"action"})}):void 0}}),jsx(Menu,{anchorEl:r,open:!!r,onClose:()=>c(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,minHeight:"auto",py:.5}}},children:I.map(u=>jsxs(MenuItem,{selected:u===T,onClick:()=>S(u),children:[jsx(Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:xt[u]}),jsx(ListItemText,{primary:L(u),primaryTypographyProps:{fontSize:Z}})]},u))})]})},Ye=({fields:e,filters:o,onFilterChange:t,variants:r=[],currentVariantId:c,onVariantLoad:n,onVariantSave:i,onVariantDelete:l,onVariantSetDefault:m,onSearch:v,loading:w=false,appId:D,tableKey:b,currentLayout:x,currentLayoutId:p,layoutRefs:f,variantService:k})=>{let[T,d]=useState(true),[L,a]=useState(null),[S,s]=useState(e.filter(u=>!u.hidden).map(u=>u.id)),h=(u,M)=>{t({...o,[u]:M});},I=u=>{S.includes(u)?s(S.filter(M=>M!==u)):s([...S,u]);};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:[D?jsx(Ko,{appId:D,tableKey:b,currentFilters:{values:o,visibleFields:S},currentLayout:x,currentLayoutId:p,layoutRefs:f,onLoad:u=>{if(!u.filters)return;let M=null;if(Array.isArray(u.filters)){let g=b||"default",W=u.filters.find(A=>A.scope===g);M=W?W.filters:null;}else M=u.filters;M&&(M.values||M.visibleFields?(M.visibleFields&&Array.isArray(M.visibleFields)&&s(M.visibleFields),M.values&&t(M.values)):t(M)),n&&n(u);},variantService:k,currentVariantId:c}):jsx(gt,{variants:r,currentVariantId:c,onLoad:n,onSave:u=>{i&&i({...u,filters:{values:o,visibleFields:S}});},onDelete:l,onSetDefault:m}),jsxs(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsx(Tooltip,{title:"Add Filters",children:jsx(Button,{onClick:u=>a(u.currentTarget),size:"small",color:"primary",startIcon:jsx(br,{fontSize:"small"}),sx:{textTransform:"none",fontSize:Z},children:"Adapt Filters"})}),jsx(Button,{variant:"contained",size:"small",onClick:v,disabled:w,sx:{minWidth:"40px",fontWeight:"bold"},children:w?"...":"Go"}),jsxs(Menu,{anchorEl:L,open:!!L,onClose:()=>a(null),slotProps:{paper:{style:{maxHeight:400,width:"25ch"}}},children:[jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"Visible Filters"})}),jsx(Divider,{}),e.map(u=>jsxs(MenuItem,{onClick:()=>I(u.id),children:[jsx(Checkbox,{checked:S.includes(u.id),size:"small"}),jsx(ListItemText,{primary:u.label})]},u.id))]})]})]}),jsx(Collapse,{in:T,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(u=>S.includes(u.id)).map(u=>jsx(Grid,{size:1,children:jsx(wr,{field:u,value:o[u.id]||{value:"",operator:u.type==="number"?"=":"equals"},onChange:M=>h(u.id,M)})},u.id))})})}),jsx(Box,{sx:{position:"absolute",bottom:0,left:"50%",transform:"translate(-50%, 50%)",zIndex:10},children:jsx(IconButton,{size:"small",onClick:()=>d(!T),sx:{bgcolor:"background.paper",boxShadow:2,border:"1px solid",borderColor:"divider",width:20,height:20,minHeight:0,p:0,"&:hover":{bgcolor:"background.paper"}},children:T?jsx(xr,{sx:{fontSize:16},color:"action"}):jsx(la,{sx:{fontSize:16},color:"action"})})})]})};var sn=({layouts:e,currentLayoutId:o,onLoad:t,onSave:r,onDelete:c,onSetDefault:n})=>{let[i,l]=useState(null),[m,v]=useState(false),[w,D]=useState(""),[b,x]=useState(""),[p,f]=useState({isDefault:false,isPublic:false}),k=e.find(s=>s.id===o),T=s=>{l(s.currentTarget);},d=()=>{l(null);},L=s=>{t(s),d();},a=()=>{D(""),x(""),f({isDefault:false,isPublic:false}),v(true),d();},S=()=>{w.trim()&&(r({name:w,description:b,...p}),v(false));};return jsxs(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsx(Tooltip,{title:"Save Layout",children:jsx(IconButton,{onClick:a,color:"primary",size:"small",children:jsx(ln,{})})}),jsx(Tooltip,{title:"Layout Options",children:jsx(IconButton,{onClick:T,color:k?"primary":"default",children:jsx(Fr,{})})}),jsxs(Menu,{anchorEl:i,open:!!i,onClose:d,PaperProps:{sx:{width:320,maxHeight:400}},children:[jsx(MenuItem,{disabled:true,children:jsx(Typography,{variant:"caption",children:"Select Layout"})}),jsxs(MenuItem,{onClick:a,children:[jsx(ListItemIcon,{children:jsx(ln,{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((s,h)=>jsx(MenuItem,{onClick:()=>L(s),selected:s.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:s.id===o?"bold":"normal",noWrap:true,children:s.name})}),s.description&&jsx(Typography,{variant:"caption",color:"text.secondary",noWrap:true,children:s.description})]}),jsxs(Box,{sx:{display:"flex",alignItems:"center"},onClick:I=>I.stopPropagation(),children:[jsx(Tooltip,{title:s.isDefault?"Remove Default":"Set as Default",children:jsx(IconButton,{size:"small",onClick:I=>{I.stopPropagation(),n(s.id);},children:s.isDefault?jsx(_a,{fontSize:"small",color:"warning"}):jsx(Vr,{fontSize:"small"})})}),jsx(Tooltip,{title:"Delete",children:jsx(IconButton,{size:"small",color:"error",onClick:I=>{I.stopPropagation(),c(s.id);},children:jsx(Lr,{fontSize:"small"})})})]})]})},s.id||h))]}),jsxs(Dialog,{open:m,onClose:()=>v(false),maxWidth:"xs",fullWidth:true,children:[jsx(DialogTitle,{children:"Save Layout"}),jsx(DialogContent,{children:jsxs(Box,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[jsx(TextField,{label:"Layout Name",value:w,onChange:s=>D(s.target.value),fullWidth:true,autoFocus:true,size:"small",helperText:"e.g., 'Compact View'"}),e.some(s=>s.name===w)&&jsx(Typography,{variant:"caption",color:"warning.main",sx:{ml:1},children:"Warning: Existing layout will be overwritten"}),jsx(TextField,{label:"Description",value:b,onChange:s=>x(s.target.value),fullWidth:true,size:"small"}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:p.isDefault,onChange:s=>f({...p,isDefault:s.target.checked})}),label:"Use as Default Layout"}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:p.isPublic,onChange:s=>f({...p,isPublic:s.target.checked})}),label:"Public (Visible to all users)"})]})}),jsxs(DialogActions,{children:[jsx(Button,{onClick:()=>v(false),children:"Cancel"}),jsx(Button,{onClick:S,variant:"contained",disabled:!w,children:"Save"})]})]})]})};var Gr="http://127.0.0.1:8515",dn=({appId:e,tableKey:o="default",currentLayoutData:t,onLayoutLoad:r,targetLayoutId:c,activeLayoutId:n,serviceUrl:i=Gr,onError:l,onSuccess:m})=>{let[v,w]=useState([]),[D,b]=useState(""),x=a=>({id:a.layoutId,name:a.name,description:a.description??"",isDefault:!!a.isDefault,isPublic:!!a.isPublic,createdAt:a.createdAt??new Date().toISOString(),layoutData:a.layout??{}}),p=a=>({appId:e,tableKey:o,layoutId:a.id,name:a.name,description:a.description??"",isDefault:!!a.isDefault,isPublic:!!a.isPublic,createdAt:a.createdAt,layout:a.layoutData});useEffect(()=>{n!==void 0&&b(n);},[n]),useEffect(()=>{if(c&&v.length>0){let a=v.find(S=>S.id===c);a&&(b(a.id),r(a));}},[c,v,r]);let f=useCallback(async()=>{if(e)try{let a=await fetch(`${i}/api/layouts?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!a.ok)throw new Error("Failed to fetch layouts");let s=(await a.json()).map(x);w(s);let h=s.find(I=>I.isDefault);h&&!D&&!c&&(b(h.id),r(h));}catch(a){console.error("Error fetching layouts",a),l&&l("Failed to load layouts");}},[e,o,i,l,D,r,c]);return useEffect(()=>{f();},[e,o]),jsx(sn,{layouts:v,currentLayoutId:D,onLoad:a=>{b(a.id),r(a);},onSave:async a=>{try{let S=v.find(C=>C.name===a.name),s=S?S.id:Date.now().toString(),h={id:s,...a,createdAt:new Date().toISOString(),layoutData:t,isDefault:a.isDefault??!1,isPublic:a.isPublic??!1};if(!(await fetch(`${i}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(p(h))})).ok)throw new Error("Failed to save layout");m&&m("Layout saved successfully"),await f(),b(s),r(h);}catch(S){console.error("Error saving layout",S),l&&l("Failed to save layout");}},onDelete:async a=>{try{if(!(await fetch(`${i}/api/layouts/${encodeURIComponent(a)}`,{method:"DELETE"})).ok)throw new Error("Failed to delete layout");D===a&&b(""),m&&m("Layout deleted successfully"),await f();}catch(S){console.error("Error deleting layout",S),l&&l("Failed to delete layout");}},onSetDefault:async a=>{try{let S=v.find(h=>h.id===a);if(!S)return;if(!(await fetch(`${i}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(p({...S,isDefault:!0}))})).ok)throw new Error("Failed to set default layout");m&&m("Default layout set"),await f();}catch(S){console.error("Error setting default",S),l&&l("Failed to set default layout");}}})};function pn(e,o,t){return o[t]<e[t]?-1:o[t]>e[t]?1:0}function zr(e,o){return e==="desc"?(t,r)=>pn(t,r,o):(t,r)=>-pn(t,r,o)}function Hr(e,o){let t=e.map((r,c)=>[r,c]);return t.sort((r,c)=>{let n=o(r[0],c[0]);return n!==0?n:r[1]-c[1]}),t.map(r=>r[0])}var mn=e=>{let o=useCallback(y=>{let B=String(y?.label??y?.id??"").length*9+64,Q=typeof y?.minWidth=="number"?y.minWidth:0;return Math.max(100,Q,B)},[]),[t,r]=useState(""),[c,n]=useState(e.order||"asc"),[i,l]=useState(e.orderBy||""),[m,v]=useState(e.page||0),[w,D]=useState(e.rowsPerPage||20),[b,x]=useState(e.selected||[]),[p,f]=useState(e.columns?e.columns.map(y=>y.id):[]),[k,T]=useState(e.showSummary||false),[d,L]=useState([]),[a,S]=useState(new Set),[s,h]=useState(()=>{let y={};return (e.columns||[]).forEach(P=>{y[P.id]=o(P);}),y}),[I,C]=useState(null),[u,M]=useState(null),[g,W]=useState(null),[A,F]=useState(null),[E,G]=useState(false);useEffect(()=>{e.order!==void 0&&n(e.order),e.orderBy!==void 0&&l(e.orderBy);},[e.order,e.orderBy]),useEffect(()=>{e.selected!==void 0&&x(e.selected);},[e.selected]),useEffect(()=>{e.page!==void 0&&v(e.page);},[e.page]),useEffect(()=>{h(y=>{let P={...y};return (e.columns||[]).forEach(B=>{P[B.id]===void 0&&(P[B.id]=o(B));}),P});},[e.columns,o]);let O=useMemo(()=>{let y=e.rows||[];return t&&(y=y.filter(P=>Object.keys(P).some(B=>String(P[B]).toLowerCase().includes(t.toLowerCase())))),y},[e.rows,t]),ke=useMemo(()=>e.onSortChange||!i?O:Hr(O,zr(c,i)),[O,c,i,e.onSortChange]),Ie=useCallback(y=>{if(d.length===0)return y.map(Y=>({type:"row",data:Y,id:Y[e.rowKey||"id"]}));let P=[...y].sort((Y,J)=>{for(let U of d){if(Y[U]<J[U])return -1;if(Y[U]>J[U])return 1}return 0}),B=(Y,J=0)=>{if(J>=d.length)return Y;let U=d[J],$={},re=[];return Y.forEach(ie=>{let Pe=ie[U],ue=`${U}:${Pe}`;$[ue]||($[ue]={key:ue,field:U,value:Pe,children:[],count:0,level:J},re.push($[ue])),$[ue].children.push(ie),$[ue].count++;}),re.forEach(ie=>{ie.children&&(ie.children=B(ie.children,J+1));}),re},Q=B(P),z=(Y,J="")=>{let U=[];return Y.forEach($=>{if($.children){let re=J?`${J}>${$.key}`:$.key,ie=a.has(re);U.push({type:"group",id:re,field:$.field,value:$.value,level:$.level,count:$.count,isExpanded:ie,childIds:(function Pe(ue){let Ee=[];return ue.children.forEach(Be=>{Be.children?Ee=Ee.concat(Pe(Be)):Ee.push(Be[e.rowKey||"id"]);}),Ee})($)}),ie&&(U=U.concat(z($.children,re)));}else U.push({type:"row",data:$,id:$[e.rowKey||"id"],level:d.length});}),U};return z(Q)},[d,a,e.rowKey]),ae=useMemo(()=>Ie(ke),[ke,Ie]),te=useMemo(()=>w>0?ae.slice(m*w,m*w+w):ae,[ae,m,w]),Oe=y=>{let P=new Set(a);P.has(y)?P.delete(y):P.add(y),S(P);},kt=y=>{Oe(y);},ze=y=>{let P=new Set(a);Array.from(P).forEach(B=>{B.startsWith(y)&&P.delete(B);}),S(P);},It=y=>{y||S(new Set);},Rt=y=>{let P=i===y&&c==="asc",B=i===y&&c==="desc";if(e.onSortChange){P?e.onSortChange(y,"desc"):B?e.onSortChange("","asc"):e.onSortChange(y,"asc");return}P?(n("desc"),l(y)):B?(n("asc"),l("")):(n("asc"),l(y));},He=(y,P)=>{h(B=>({...B,[y]:P}));},et=y=>{if(y.target.checked){let P=O.map(B=>B[e.rowKey||"id"]);x(P),e.onSelectionChange&&e.onSelectionChange(P);return}x([]),e.onSelectionChange&&e.onSelectionChange([]);},Mt=(y,P)=>{let B=P[e.rowKey||"id"],Q=b.indexOf(B),z=[];Q===-1?z=z.concat(b,B):Q===0?z=z.concat(b.slice(1)):Q===b.length-1?z=z.concat(b.slice(0,-1)):Q>0&&(z=z.concat(b.slice(0,Q),b.slice(Q+1))),x(z),e.onSelectionChange&&e.onSelectionChange(z);},tt=y=>{v(y),e.onPageChange&&e.onPageChange(y);},ot=y=>{D(y),v(0),e.onRowsPerPageChange&&e.onRowsPerPageChange(y);},Dt=y=>{let P=p.indexOf(y),B=[...p];P===-1?B.push(y):B.splice(P,1),f(B);},Pt=y=>{let P=d.indexOf(y),B=[...d];P===-1?B.push(y):B.splice(P,1),L(B);},nt=y=>{e.onLayoutSave&&e.onLayoutSave({visibleColumns:p,order:c,orderBy:i,grouping:d,columnWidths:s});},at=y=>{y.layout&&(y.layout.visibleColumns&&f(y.layout.visibleColumns),y.layout.order&&n(y.layout.order),y.layout.orderBy&&l(y.layout.orderBy),y.layout.grouping&&L(y.layout.grouping),y.layout.columnWidths&&h(y.layout.columnWidths));};useEffect(()=>{e.layout&&at({layout:e.layout});},[e.layout]);let Et=y=>{y.preventDefault(),F(A===null?{mouseX:y.clientX+2,mouseY:y.clientY-6}:null);},Bt=()=>{F(null);},Lt=useMemo(()=>{if(!k)return {};let y={};e.columns.forEach(B=>{if(B.numeric){let Q=O.reduce((z,Y)=>{let J=parseFloat(Y[B.id]);return z+(isNaN(J)?0:J)},0);y[B.id]=Q.toFixed(2);}else y[B.id]="";});let P=e.columns.find(B=>p.includes(B.id));return P&&!P.numeric&&(y[P.id]="Total"),y},[O,e.columns,k,p]),At=()=>{if(!e.columns||!O)return;let y=e.columns.map(Y=>Y.label).join(","),P=O.map(Y=>e.columns.map(J=>{let U=Y[J.id];return `"${(U==null?"":String(U)).replace(/"/g,'""')}"`}).join(",")).join(`
2
- `),B=`data:text/csv;charset=utf-8,${y}
3
- ${P}`,Q=encodeURI(B),z=document.createElement("a");z.setAttribute("href",Q),z.setAttribute("download",`${e.title||"export"}.csv`),document.body.appendChild(z),z.click(),document.body.removeChild(z);},rt=()=>{G(true);},Vt=()=>{G(false);};return {isMobile:false,columns:e.columns,order:c,orderBy:i,filterText:t,setFilterText:r,visibleColumns:p,setVisibleColumns:f,showSummary:k,setShowSummary:T,summaryColumns:[],grouping:d,setGrouping:L,expandedGroups:a,setExpandedGroups:S,groupAnchorEl:u,setGroupAnchorEl:M,summaryAnchorEl:g,setSummaryAnchorEl:W,columnWidths:s,setColumnWidths:h,anchorEl:I,setAnchorEl:C,contextMenu:A,setContextMenu:F,sensors:void 0,sortedAndFilteredRows:ke,visibleRows:te,summaryRow:Lt,page:m,setPage:tt,rowsPerPage:w,setRowsPerPage:ot,selected:b,setSelected:x,isAllExpanded:false,handleColumnResize:He,handleRequestSort:Rt,handleSelectAllClick:et,handleClick:Mt,toggleSummaryColumn:()=>{},handleDragEnd:()=>{},handleExport:At,handleContextMenu:Et,handleCloseContextMenu:Bt,toggleColumnVisibility:Dt,toggleGroupExpand:Oe,toggleGroupField:Pt,handleToggleAll:It,handleExpandGroupRecursively:kt,handleCollapseGroupRecursively:ze,handleLayoutLoad:()=>{},handleVariantLoad:at,handleLayoutSave:nt,effectiveAppId:e.appId||"",currentLayoutData:{visibleColumns:p,order:c,orderBy:i,grouping:d,columnWidths:s},currentLayoutId:"",layoutIdToLoad:"",onPageChange:tt,onRowsPerPageChange:ot,graphReportOpen:E,handleOpenGraphReport:rt,handleCloseGraphReport:Vt}};var Js=e=>jsx(jr,{...e}),Zs=e=>jsx(xo,{...e}),Qs=e=>jsx(fn,{...e}),ec=e=>jsx(Zn,{...e}),tc=e=>jsx(Qn,{...e}),Tt=e=>{let{title:o="Data Table",selectionMode:t,selected:r=[],onSelectionChange:c,actions:n,extraTools:i,fitContainer:l=false,fullWidth:m=false,maxHeight:v,loading:w=false,page:D=0,rowsPerPage:b=20,rowsPerPageOptions:x=[20,50,100,-1],count:p=0,onPageChange:f,onRowsPerPageChange:k,onLayoutSave:T,filterConfig:d,rowKey:L,tableKey:a="default",graphReport:S}=e,{isMobile:s,columns:h,order:I,orderBy:C,filterText:u,setFilterText:M,visibleColumns:g,showSummary:W,setShowSummary:A,summaryColumns:F,grouping:E,setGrouping:G,expandedGroups:O,groupAnchorEl:ke,setGroupAnchorEl:Ie,summaryAnchorEl:ae,setSummaryAnchorEl:te,columnWidths:Oe,anchorEl:kt,setAnchorEl:ze,contextMenu:It,sensors:Rt,sortedAndFilteredRows:He,summaryRow:et,visibleRows:Mt,isAllExpanded:tt,handleColumnResize:ot,handleRequestSort:Dt,handleSelectAllClick:Pt,handleClick:nt,toggleSummaryColumn:at,handleDragEnd:Et,handleExport:Bt,handleContextMenu:Lt,handleCloseContextMenu:At,toggleColumnVisibility:rt,toggleGroupExpand:Vt,toggleGroupField:y,handleToggleAll:P,handleExpandGroupRecursively:B,handleCollapseGroupRecursively:Q,handleLayoutLoad:z,handleVariantLoad:Y,handleLayoutSave:J,effectiveAppId:U,currentLayoutData:$,currentLayoutId:re,layoutIdToLoad:ie,graphReportOpen:Pe,handleOpenGraphReport:ue,handleCloseGraphReport:Ee}=mn(e),Be=S?.enabled??false,{model:Ft}=zo({rows:He,config:{...S,title:S?.title||`${o} Graphic Report`}}),bn=Ft.table.columns.map(it=>({id:it.id,label:it.label,align:it.align||"left",minWidth:120,numeric:it.align==="right"})),xn=U?jsx(dn,{appId:U,tableKey:a,currentLayoutData:$,onLayoutLoad:z,targetLayoutId:ie,activeLayoutId:re,serviceUrl:(d?.variantService,void 0)}):null,lo=jsxs(Fragment,{children:[jsx(Po,{groupAnchorEl:ke,setGroupAnchorEl:Ie,grouping:E,setGrouping:G,columns:h,toggleGroupField:y}),jsx(Eo,{anchorEl:kt,setAnchorEl:ze,columns:h,visibleColumns:g,toggleColumnVisibility:rt}),jsx(Bo,{anchorEl:ae,setAnchorEl:te,showSummary:W,setShowSummary:A,columns:h,summaryColumns:F,toggleSummaryColumn:at}),jsx(Lo,{contextMenu:It,handleCloseContextMenu:At,columns:h,visibleColumns:g,toggleColumnVisibility:rt})]});return s?jsxs(io,{sx:{display:"flex",flexDirection:"column",gap:2,height:"100%"},children:[d&&jsx(Ye,{fields:d.fields,filters:d.filters,onFilterChange:d.onFilterChange,onSearch:d.onSearch,variants:d.variants||[],currentVariantId:d.currentVariantId,onVariantLoad:d.onVariantLoad,onVariantSave:d.onVariantSave,onVariantDelete:d.onVariantDelete,onVariantSetDefault:d.onVariantSetDefault,appId:d.appId,tableKey:a,currentLayout:[{tableKey:a,layoutData:$}],variantService:d.variantService}),jsx(Mo,{title:o,loading:w,showSummary:W,setShowSummary:A,setAnchorEl:ze,setSummaryAnchorEl:te,filterText:u,setFilterText:M,sortedAndFilteredRows:He,selected:r,columns:h,visibleColumns:g,summaryRow:et,handleClick:nt,selectionMode:t}),lo]}):jsxs(io,{sx:{width:m?"100%":"auto",mb:l?0:2,...l?{flex:1,display:"flex",flexDirection:"column",minHeight:0,height:"100%"}:{}},children:[d&&jsx(io,{sx:{mb:2},children:jsx(Ye,{fields:d.fields,filters:d.filters,onFilterChange:d.onFilterChange,onSearch:d.onSearch,variants:d.variants||[],currentVariantId:d.currentVariantId,onVariantLoad:Y,onVariantSave:d.onVariantSave,onVariantDelete:d.onVariantDelete,onVariantSetDefault:d.onVariantSetDefault,loading:w,appId:d.appId,tableKey:a,currentLayout:[{tableKey:a,layoutData:$}],currentLayoutId:re,layoutRefs:[{tableKey:a,layoutId:re}],variantService:d.variantService})}),jsxs(Wr,{sx:{width:m?"100%":"auto",mb:l?0:2,display:"flex",flexDirection:"column",overflow:"hidden",...v?{height:v}:l?{flex:1,minHeight:0}:{}},children:[jsx(bo,{filterText:u,setFilterText:M,onRowsPerPageChange:k,rowsPerPage:b,rowsPerPageOptions:x,page:D,count:p,onPageChange:f,actions:n,extraTools:i,grouping:E,setGroupAnchorEl:Ie,showSummary:W,setShowSummary:A,setAnchorEl:ze,setSummaryAnchorEl:te,handleExport:Bt,onLayoutSave:T||d?.variantService&&d?.appId?J:void 0,loading:w,layoutManager:xn,onOpenGraphReport:Be?ue:void 0}),jsx(fn,{sx:{flex:1,maxHeight:v||"calc(100vh - 320px)",overflowY:"auto",overflowX:"auto",position:"relative",minHeight:0},children:jsx(DndContext,{sensors:Rt,collisionDetection:closestCenter,onDragEnd:Et,modifiers:[restrictToHorizontalAxis],children:jsxs($r,{sx:{minWidth:m?750:"auto",width:m?"100%":"auto",tableLayout:Object.keys(Oe).length>0?"fixed":"auto",borderCollapse:"separate",borderSpacing:0},"aria-labelledby":"tableTitle",size:"small",stickyHeader:true,children:[jsx(So,{columns:h,visibleColumns:g,order:I,orderBy:C,onRequestSort:Dt,onContextMenu:Lt,selectionMode:t,grouping:E,isAllExpanded:tt,handleToggleAll:P,rowCount:He.length,numSelected:r.length,onSelectAllClick:Pt,columnWidths:Oe,onColumnResize:ot}),jsx(wo,{visibleRows:Mt,columns:h,visibleColumns:g,selectionMode:t,selected:r,orderBy:C,loading:w,expandedGroups:O,toggleGroupExpand:Vt,handleExpandGroupRecursively:B,handleCollapseGroupRecursively:Q,handleClick:nt,onSelectionChange:c,grouping:E,rowKeyProp:L,page:D,rowsPerPage:b}),W&&jsx(Io,{showSummary:W,columns:h,visibleColumns:g,summaryRow:et,selectionMode:t?.toString(),orderBy:C,zIndex:3})]})})})]}),lo,Be&&jsx(Go,{open:Pe,onClose:Ee,model:Ft,tableContent:jsx(Tt,{title:"Data Body",columns:bn,rows:Ft.table.rows,rowKey:"id",fullWidth:true,maxHeight:"420px",rowsPerPage:20,rowsPerPageOptions:[20,50,100],graphReport:{enabled:false}})})]})},oc=Tt;var cc=({title:e,hideHeader:o=true,filterConfig:t,tableProps:r,children:c,spacing:n=1})=>jsxs(yo,{title:e,hideHeader:o,children:[jsxs(Stack,{spacing:n,sx:{height:"100%",overflow:"hidden"},children:[t&&jsx(Box,{sx:{flexShrink:0},children:jsx(Ye,{...t})}),jsx(Box,{sx:{flex:1,minHeight:0,overflow:"hidden"},children:jsx(Tt,{...r,fitContainer:true,filterConfig:void 0})})]}),c]});var mc=({metadata:e,fetchData:o})=>{let[t,r]=useState(false),[c,n]=useState([]),[i,l]=useState({}),[m,v]=useState(e.variants||[]),[w,D]=useState(e.layout||null),[b,x]=useState(0),[p,f]=useState(0),[k,T]=useState(10),[d,L]=useState([]),[a,S]=useState("asc"),[s,h]=useState("");useEffect(()=>{let E={};e.filters.forEach(G=>{G.defaultValue!==void 0&&(E[G.id]=G.defaultValue);}),l(E);},[e.filters]);let I=useCallback(async(E,G,O,ke,Ie)=>{r(true);try{let ae={...E,page:G+1,limit:O,sort:Ie,order:ke},te;o?te=await o(ae):typeof e.api=="function"?te=await e.api(ae):e.api&&typeof e.api=="object"?(console.log("Fetching from URL:",e.api.url,ae),te={rows:[],total:0}):(console.warn("No API configured for report"),te={rows:[],total:0}),te&&(n(te.rows||[]),x(te.total||0));}catch(ae){console.error("Failed to fetch report data",ae);}finally{r(false);}},[e.api,o]);useEffect(()=>{I(i,p,k,a,s);},[I,p,k,a,s]);let C=()=>{f(0),I(i,0,k,a,s);},u=(E,G)=>{S(G),h(E);},M=E=>{l(E);},g=E=>{if(E.filters){let G=E.filters.find(O=>O.scope==="default"||O.scope===e.id);G&&(l(G.filters),I(G.filters,0,k));}E.layout&&D(E.layout);},W=E=>{let G={...E,id:Date.now().toString(),createdAt:new Date().toISOString()};v(O=>[...O,G]);},A=E=>{D(E);};return {pageProps:{title:e.title,filterConfig:{appId:e.id,fields:e.filters,filters:i,onFilterChange:M,onSearch:C,onVariantLoad:g,onVariantSave:W,onVariantDelete:E=>v(G=>G.filter(O=>O.id!==E)),onVariantSetDefault:E=>{v(G=>G.map(O=>({...O,isDefault:O.id===E})));},variants:m},tableProps:{appId:e.id,columns:e.columns,rows:c,loading:t,rowKey:"id",count:b,page:p,rowsPerPage:k,rowsPerPageOptions:[10,25,50,100],onPageChange:f,onRowsPerPageChange:T,selectionMode:"multiple",selected:d,onSelectionChange:L,onLayoutSave:A,layout:w,title:e.title,showSummary:true,order:a,orderBy:s,onSortChange:u,graphReport:e.graphReport||{enabled:true,title:`${e.title} Graphic Report`}}},filters:i,rows:c,loading:t,refresh:C}};export{Gt as Button,sn as CLayoutManagement,dn as CLayoutManager,yo as CPageLayout,Ye as CSmartFilter,oc as CSmartTable,cc as CStandardPage,Tt as CTable,Js as CTableBody,Zs as CTableCell,Qs as CTableContainer,ec as CTableHead,tc as CTableRow,gt as CVariantManagement,Ko as CVariantManager,wi as NavigationIsland,zt as TreeMenu,wn as buttonVariants,Mi as useNavigationIsland,mc as useStandardReport};
1
+ import*as bo from'react';import bo__default,{useState,useEffect,useCallback,useMemo,useRef}from'react';import {usePathname,useRouter}from'next/navigation';import {ChevronRight,Search}from'lucide-react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {Slot}from'@radix-ui/react-slot';import {cva}from'class-variance-authority';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {styled,Box,Typography,Autocomplete,TextField,Tooltip,IconButton,Dialog,DialogTitle,DialogContent,FormControlLabel,Checkbox,DialogActions,Button,Paper,Menu,MenuItem,ListItemText,Divider,Collapse,Grid,ListItemIcon,Stack,useTheme,AppBar,Toolbar,InputAdornment,Avatar,createTheme,ThemeProvider,Popover,ListSubheader,Badge,Switch,TableBody,TableRow,TableCell,TableFooter,Chip}from'@mui/material';import mo from'@mui/material/Box';import oi from'@mui/material/Paper';import ni from'@mui/material/Table';import ai from'@mui/material/TableBody';import Do from'@mui/material/TableCell';import wn from'@mui/material/TableContainer';import pa from'@mui/material/TableHead';import ma from'@mui/material/TableRow';import {DndContext,closestCenter}from'@dnd-kit/core';import {restrictToHorizontalAxis}from'@dnd-kit/modifiers';import cn from'@mui/icons-material/Search';import na from'@mui/icons-material/ViewColumn';import yn from'@mui/icons-material/Save';import ra from'@mui/icons-material/Download';import ia from'@mui/icons-material/AccountTree';import la from'@mui/icons-material/Functions';import sa from'@mui/icons-material/Insights';import ga from'@mui/material/Checkbox';import fa from'@mui/material/TableSortLabel';import Ca from'@mui/icons-material/KeyboardArrowRight';import va from'@mui/icons-material/KeyboardArrowDown';import La from'@mui/icons-material/Check';import Aa from'@mui/icons-material/ClearAll';import Ua from'@mui/icons-material/Close';import Br from'@mui/icons-material/Settings';import Lr from'@mui/icons-material/KeyboardArrowUp';import Fr from'@mui/icons-material/ArrowRightAlt';import rr from'@mui/icons-material/Star';import {DateCalendar}from'@mui/x-date-pickers/DateCalendar';import {PickersDay}from'@mui/x-date-pickers/PickersDay';import Cr from'@mui/icons-material/CalendarMonth';import vr from'@mui/icons-material/Clear';import Sr from'@mui/icons-material/ArrowForward';import De from'dayjs';import Tr from'dayjs/plugin/isBetween';import Kr from'@mui/icons-material/Delete';import qr from'@mui/icons-material/StarBorder';import Xr from'@mui/icons-material/ViewQuilt';import Ti from'@mui/icons-material/Language';import wi from'@mui/icons-material/DesktopWindows';import Ii from'@mui/icons-material/DarkMode';import ki from'@mui/icons-material/LightMode';function re(...e){return twMerge(clsx(e))}var $t={primary:"#000000",primaryHover:"#333333"},dt={primary:"bg-primary text-primary-foreground hover:bg-primary/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",ghost:"hover:bg-accent hover:text-accent-foreground"},$e={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",full:"rounded-full"},yo=()=>"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50";var Hn=cva(yo(),{variants:{variant:{default:`${dt.primary} shadow-sm`,destructive:"bg-red-500 text-white hover:bg-red-600 active:bg-red-700 dark:bg-red-600 dark:hover:bg-red-500 dark:active:bg-red-700 shadow-sm",outline:`${dt.outline} shadow-sm`,secondary:"bg-gray-200 text-gray-700 hover:bg-gray-300 active:bg-gray-400 dark:bg-gray-700 dark:text-gray-200 dark:hover:bg-gray-600 dark:active:bg-gray-500 shadow-sm",ghost:dt.ghost,link:"text-blue-600 dark:text-blue-400 underline-offset-4 hover:underline hover:text-blue-700 dark:hover:text-blue-300 active:text-blue-800 dark:active:text-blue-200","chat-tool":"bg-[var(--orbai-surface-2)] border border-[var(--orbai-border-soft)] text-[var(--orbai-text-2)] hover:bg-[var(--orbai-surface-3)] hover:border-[var(--orbai-border-strong)] hover:text-[var(--orbai-text-1)] active:scale-95 transition-all duration-200","chat-send":`bg-[${$t.primary}] hover:bg-[${$t.primaryHover}] text-white border border-[var(--orbai-border-strong)] shadow-[var(--orbai-shadow-soft-sm)] hover:shadow-[var(--orbai-shadow-soft-md)] active:scale-95 transition-all duration-200`,"chat-stop":"bg-red-500 hover:bg-red-600 border border-[var(--orbai-border-strong)] shadow-[var(--orbai-shadow-soft-sm)] hover:shadow-[var(--orbai-shadow-soft-md)] active:scale-95 text-white transition-all duration-200","chat-disabled":"cursor-not-allowed opacity-50 bg-[var(--orbai-surface-2)] border border-[var(--orbai-border-soft)] text-[var(--orbai-muted)]"},size:{default:"h-10 px-4 py-2",sm:"h-9 px-3",lg:"h-11 px-8",icon:"h-10 w-10","chat-sm":"h-8 w-8 rounded-full","chat-md":"h-10 w-10 rounded-full","chat-lg":"h-12 w-12 rounded-full"},rounded:{none:$e.none,sm:$e.sm,md:$e.md,full:$e.full}},defaultVariants:{variant:"default",size:"default",rounded:"md"}}),_t=bo.forwardRef(({className:e,variant:o,size:t,asChild:i=false,...s},a)=>jsx(i?Slot:"button",{className:re(Hn({variant:o,size:t,className:e})),ref:a,...s}));_t.displayName="Button";function Ut({items:e,onItemClick:o,className:t="",level:i=0,expandedIds:s,onToggleExpand:a,colorMode:l="light"}){let n=l==="dark",u=usePathname(),[v,w]=useState(new Set),S=s!==void 0&&a!==void 0,x=S?s:v,P=m=>{if(S)a(m);else {let g=new Set(v);g.has(m)?g.delete(m):g.add(m),w(g);}},k=m=>{m.children&&m.children.length>0&&P(m.id),o&&o(m);};return !e||!Array.isArray(e)?jsx("div",{className:re("tree-menu",t),children:jsx("div",{className:"text-sm text-gray-500 p-2",children:"No items to display"})}):jsx("div",{className:re("tree-menu",t),children:e.map(m=>{let g=x.has(m.id)||m.isExpanded,y=m.children&&m.children.length>0,d=m.appurl||m.href,I=d?u===d:false;return jsxs("div",{className:"tree-menu-item relative",children:[I&&jsx("div",{className:re("absolute left-0 top-2 bottom-2 w-[3px] rounded-r-full z-10",n?"bg-[#90caf9]":"bg-[#1976d2]")}),jsxs(_t,{variant:"ghost",className:re("w-full justify-start gap-2 h-auto py-2 relative overflow-hidden group",`ml-${i*4}`,I?n?"bg-transparent text-[#90caf9] hover:bg-gray-800/35":"bg-transparent text-[#1976d2] hover:bg-gray-100/60":n?"hover:bg-gray-800/50 text-gray-300":"hover:bg-gray-100/50 text-gray-700"),onClick:()=>k(m),children:[y&&jsx("div",{className:re("flex-shrink-0 transition-transform duration-200",g&&"rotate-90",I?n?"text-[#90caf9]":"text-[#1976d2]":n?"text-gray-500 group-hover:text-gray-300":"text-gray-400 group-hover:text-gray-600"),children:jsx(ChevronRight,{className:"h-4 w-4"})}),!y&&jsx("div",{className:"w-4 h-4 flex-shrink-0"}),m.icon&&jsx("div",{className:re("flex-shrink-0 transition-colors duration-200",I?n?"text-[#90caf9]":"text-[#1976d2]":n?"text-gray-500 group-hover:text-gray-300":"text-gray-400 group-hover:text-gray-600"),children:m.icon}),jsxs("div",{className:"flex-1 text-left overflow-hidden z-10",children:[jsx("div",{className:re("text-sm truncate transition-colors duration-200",I?"font-semibold":"font-medium"),children:m.title||m.label}),m.description&&jsx("div",{className:re("text-xs truncate transition-colors duration-200",I?n?"text-[#90caf9]/70":"text-[#1976d2]/75":n?"text-gray-400":"text-gray-500"),title:m.description,children:m.description})]})]}),y&&jsx("div",{className:re("grid transition-[grid-template-rows] duration-300 ease-in-out",g?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:jsx("div",{className:"overflow-hidden",children:jsx(Ut,{items:m.children,onItemClick:o,level:i+1,expandedIds:s,onToggleExpand:a,colorMode:l})})})]},m.id)})})}var To=({collapsed:e,onToggle:o,className:t="",maxHeight:i,menuData:s=[],colorMode:a="light"})=>{let l=a==="dark",n=useRouter(),[u,v]=useState(""),[w,S]=useState(new Set);useEffect(()=>{e&&S(new Set);},[e]);let x=useCallback(g=>{let y=[],d=I=>{I.forEach(r=>{y.push(r.id),r.children&&d(r.children);});};return d(g),y},[]),P=useMemo(()=>{if(!u.trim())return s;let g=y=>y.reduce((d,I)=>{let r=I.title?.toLowerCase().includes(u.toLowerCase())||I.description?.toLowerCase().includes(u.toLowerCase()),b=I.children?g(I.children):[];return (r||b.length>0)&&d.push({...I,children:b.length>0?b:I.children}),d},[]);return g(s)},[u,s]),k=useMemo(()=>u.trim()?new Set(x(s)):w,[u,s,w,x]),m=useCallback(async g=>{if(console.log("\u{1F5B1}\uFE0F \u5BFC\u822A\u83DC\u5355\u9879\u70B9\u51FB:",g),g.id==="chat"||g.appurl==="/chat"){console.log("\u{1F4AC} \u68C0\u6D4B\u5230chat\u83DC\u5355\u70B9\u51FB\uFF0C\u8DF3\u8F6C\u5230\u65B0\u7684\u804A\u5929\u89C6\u56FE");try{n.push("/chat?new=true");}catch(d){console.error("\u274C \u65E0\u6CD5\u8DF3\u8F6C\u5230\u65B0\u804A\u5929\u89C6\u56FE:",d),n.push("/chat");}return}let y=g.appurl||g.href;y&&(y.startsWith("http://")||y.startsWith("https://")?window.open(y,"_blank"):n.push(y));},[n]);return jsxs("div",{className:`flex flex-col backdrop-blur-xl border shadow-[0_4px_8px_0_rgba(31,38,135,0.1)] ${e?"w-14 rounded-full":"w-[234px] rounded-2xl"} relative ${t} ${l?"bg-[#111111] border-white/10":"bg-white/70 border-white/30"}`,style:{backdropFilter:"blur(16px) saturate(180%)",WebkitBackdropFilter:"blur(16px) saturate(180%)",transition:"width 400ms cubic-bezier(0.4, 0.0, 0.2, 1), border-radius 0ms cubic-bezier(0.4, 0.0, 0.2, 1), box-shadow 400ms ease-out",maxHeight:i?`${i}px`:void 0},children:[jsx("div",{className:`pt-4 pb-2 transition-all duration-500 ease-in-out ${e?"px-1":"px-2"}`,children:e?jsx("div",{className:"flex justify-center",children:jsx("button",{onClick:o,className:`w-10 h-10 flex items-center justify-center rounded-lg transition-colors duration-200 ${l?"text-gray-300 hover:bg-gray-800":"text-gray-500 hover:bg-gray-50"}`,title:"\u5C55\u5F00\u5BFC\u822A",children:jsx(Search,{className:"h-5 w-5"})})}):jsxs("div",{className:`relative transition-opacity duration-300 ${e?"opacity-0":"opacity-100 delay-200"}`,children:[jsx("input",{type:"text",placeholder:"\u641C\u7D22\u83DC\u5355...",value:u,onChange:g=>v(g.target.value),className:`w-full pl-10 pr-4 py-2 text-sm border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent ${l?"border-gray-700 bg-[#1A1A1A] text-white placeholder-gray-400":"border-gray-300 bg-white text-gray-900 placeholder-gray-500"}`}),jsx("div",{className:"absolute left-3 top-1/2 transform -translate-y-1/2 pointer-events-none",children:jsx(Search,{className:`h-4 w-4 ${l?"text-gray-500":"text-gray-400"}`})})]})}),jsx("nav",{className:`flex-1 pb-4 transition-all duration-500 ease-in-out overflow-y-auto min-h-0 ${e?"px-1":"px-2"}`,children:P.length===0?jsx("div",{className:"flex items-center justify-center py-8 text-gray-500 text-sm",children:e?"\u{1F4C2}":u?"\u672A\u627E\u5230\u5339\u914D\u7684\u83DC\u5355\u9879":"\u6682\u65E0\u53EF\u8BBF\u95EE\u7684\u5E94\u7528"}):jsxs(Fragment,{children:[!e&&jsx("div",{className:`transition-opacity duration-300 ${e?"opacity-0":"opacity-100 delay-200"}`,children:jsx(Ut,{items:P,onItemClick:m,className:"space-y-1",expandedIds:k,colorMode:a,onToggleExpand:g=>{let y=new Set(w);P.some(I=>I.id===g)?y.has(g)?y.delete(g):(P.forEach(I=>{I.id!==g&&y.has(I.id)&&y.delete(I.id);}),y.add(g)):y.has(g)?y.delete(g):y.add(g),S(y);}})}),e&&jsx("div",{className:"space-y-2",children:s.map(g=>jsx("div",{className:"space-y-1",children:jsx("button",{onClick:()=>{o();let y=new Set([g.id]);S(y);},className:`w-full flex items-center justify-center p-2 rounded-lg cursor-pointer transition-colors duration-200 ${l?"text-gray-400 hover:bg-gray-800":"text-gray-600 hover:bg-gray-50"}`,title:`\u5C55\u5F00\u67E5\u770B ${g.title}`,children:g.icon||jsx("div",{className:`w-6 h-6 rounded text-xs flex items-center justify-center font-medium ${l?"bg-[#90caf9] text-[#0b0b0b]":"bg-[#1976d2] text-white"}`,children:g.title?.charAt(0)||"?"})})},g.id))})]})}),!e&&jsx("button",{onClick:o,className:`absolute -bottom-1 -right-1 w-6 h-6 bg-transparent rounded-full flex items-center justify-center transition-all duration-300 ease-in-out z-20 ${l?"hover:bg-gray-800/50":"hover:bg-white/20"}`,title:"\u6298\u53E0\u5BFC\u822A",children:jsx("div",{className:"absolute",style:{bottom:"0px",right:"0px",width:"16px",height:"16px",overflow:"hidden"},children:jsx("div",{className:l?"border-yellow-400":"",style:{width:"32px",height:"32px",borderRadius:"16px",border:"3px solid #21BCFF",backgroundColor:"transparent",position:"absolute",top:"-16px",left:"-16px"}})})})]})};var Io=(e={})=>{let{initialCollapsed:o=false,content:t=[]}=e,[i,s]=useState(o),[a,l]=useState(t),n=useCallback(()=>{s(v=>!v);},[]),u=useMemo(()=>({collapsed:i,onToggle:n,menuData:a}),[i,n,a]);return {collapsed:i,setCollapsed:s,toggleCollapsed:n,menuData:a,setMenuData:l,navigationIslandProps:u}};var ko=({title:e,hideHeader:o,children:t})=>jsxs(Box,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[!o&&jsx(Box,{sx:{mb:2},children:jsx(Typography,{variant:"h4",children:e})}),jsx(Box,{sx:{flex:1,overflow:"hidden"},children:t})]});var Ro=e=>{let o="0.75rem";return jsxs(Toolbar,{sx:{pl:{sm:2},pr:{xs:1,sm:1},alignItems:"center"},children:[jsx(Typography,{sx:{flex:"1 1 100%",fontWeight:"bold"},variant:"h6",id:"tableTitle",component:"div",children:e.title||"Table"}),jsxs(Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsx(TextField,{size:"small",placeholder:"Search...",value:e.filterText,onChange:t=>e.setFilterText(t.target.value),InputProps:{sx:{fontSize:o,"& .MuiInputBase-input":{fontSize:o},"& .MuiInputBase-input::placeholder":{fontSize:o,opacity:1}},startAdornment:jsx(InputAdornment,{position:"start",children:jsx(cn,{fontSize:"small"})})},sx:{width:300}}),jsx(Tooltip,{title:"Group By",children:jsx(IconButton,{onClick:t=>e.setGroupAnchorEl(t.currentTarget),children:jsx(Badge,{badgeContent:e.grouping?.length,color:"primary",children:jsx(ia,{})})})}),jsx(Tooltip,{title:"Summary",children:jsx(IconButton,{onClick:t=>e.setSummaryAnchorEl(t.currentTarget),color:e.showSummary?"primary":"default",children:jsx(la,{})})}),jsx(Tooltip,{title:"Columns",children:jsx(IconButton,{onClick:t=>e.setAnchorEl(t.currentTarget),children:jsx(na,{})})}),jsx(Tooltip,{title:"Export",children:jsx(IconButton,{onClick:e.handleExport,children:jsx(ra,{})})}),e.onOpenGraphReport&&jsx(Tooltip,{title:"Graphic Report",children:jsx(IconButton,{onClick:e.onOpenGraphReport,children:jsx(sa,{})})}),e.onLayoutSave&&!e.layoutManager&&jsx(Tooltip,{title:"Save Layout",children:jsx(IconButton,{onClick:t=>e.onLayoutSave(t),children:jsx(yn,{})})}),e.layoutManager]})]})};var Bo=e=>{let{onSelectAllClick:o,order:t,orderBy:i,numSelected:s=0,rowCount:a=0,onRequestSort:l,columns:n,visibleColumns:u,selectionMode:v,onColumnResize:w,columnWidths:S}=e,[x,P]=useState(null),k=useRef(null),m=r=>b=>{x||l(r);},g=(r,b,c)=>{r.preventDefault(),r.stopPropagation(),P(b),k.current={startX:r.clientX,startWidth:c,colId:b},document.addEventListener("mousemove",y),document.addEventListener("mouseup",d),document.body.style.cursor="col-resize";},y=r=>{if(!k.current)return;let{startX:b,startWidth:c,colId:C}=k.current,M=r.clientX-b,T=Math.max(50,c+M);w&&w(C,T);},d=()=>{P(null),k.current=null,document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",d),document.body.style.cursor="";};return useEffect(()=>()=>{document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",d);},[]),jsx(pa,{children:jsxs(ma,{children:[(v==="multiple"||v==="single")&&jsx(Do,{padding:"checkbox",sx:r=>({width:48,backgroundColor:r.palette.mode==="dark"?"#000000":"#f5f5f5",color:r.palette.mode==="dark"?"#ffffff":r.palette.text.primary}),children:jsx(ga,{color:"primary",indeterminate:s>0&&s<a,checked:a>0&&s===a,onChange:o,disabled:v==="single"})}),n.filter(r=>u.includes(r.id)).map(r=>{let b=S?.[r.id]||r.minWidth||100;return jsxs(Do,{align:"left",padding:r.disablePadding?"none":"normal",sortDirection:i===r.id?t:false,style:{width:b,minWidth:b,maxWidth:b},sx:c=>({position:"relative",backgroundColor:c.palette.mode==="dark"?"#000000":"#f5f5f5",color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary,fontWeight:"bold",userSelect:"none"}),children:[jsx(fa,{active:i===r.id,direction:i===r.id?t:"asc",onClick:m(r.id),sx:c=>({"&.MuiTableSortLabel-root":{width:"100%"},"& .MuiTableSortLabel-icon":{color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary,opacity:i===r.id?1:0,transition:"opacity 0.2s"},"&:hover .MuiTableSortLabel-icon":{opacity:.5},"&.Mui-active .MuiTableSortLabel-icon":{opacity:1,color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary},fontWeight:"bold",color:c.palette.mode==="dark"?"#ffffff":c.palette.text.primary}),children:jsx(mo,{component:"span",sx:{overflow:"visible",textOverflow:"clip",whiteSpace:"normal",lineHeight:1.2,wordBreak:"break-word",pr:1},children:r.label})}),jsx(mo,{onMouseDown:c=>g(c,r.id,typeof b=="number"?b:100),onClick:c=>c.stopPropagation(),sx:{position:"absolute",right:0,top:0,bottom:0,width:5,cursor:"col-resize","&:hover":{backgroundColor:"primary.main",opacity:.5},zIndex:1}})]},r.id)})]})})};var Ao=e=>{let{visibleRows:o,visibleColumns:t,selected:i=[],handleClick:s,columns:a,toggleGroupExpand:l,expandedGroups:n=new Set,selectionMode:u}=e,v=x=>i.indexOf(x)!==-1,w=u==="multiple"||u==="single",S=t.length+(w?1:0);return jsxs(TableBody,{children:[o.map((x,P)=>{if(x.type==="group"){let k=n.has(x.id),m=x.childIds||[],g=m.filter(r=>v(r)).length,y=m.length>0&&g===m.length,d=g>0&&g<m.length,I=r=>{if(r.stopPropagation(),!!e.onSelectionChange)if(y){let b=i.filter(c=>!m.includes(c));e.onSelectionChange(b);}else {let b=Array.from(new Set([...i,...m]));e.onSelectionChange(b);}};return jsx(TableRow,{sx:{backgroundColor:"#f5f5f5"},children:jsx(TableCell,{colSpan:S,sx:{py:1,pl:x.level*4+2},children:jsxs(Box,{sx:{display:"flex",alignItems:"center"},children:[jsx(IconButton,{size:"small",onClick:()=>l&&l(x.id),sx:{mr:1},children:k?jsx(va,{}):jsx(Ca,{})}),w&&jsx(Checkbox,{size:"small",checked:y,indeterminate:d,onChange:I,onClick:r=>r.stopPropagation(),sx:{mr:1,p:.5}}),jsxs(Typography,{variant:"body2",fontWeight:"bold",children:[x.field,": ",x.value," (",x.count,")"]})]})})},x.id)}else {let k=x.data||x,m=x.id||k.id||P,g=v(m),y=`enhanced-table-checkbox-${P}`,I=(x.level!==void 0?x.level:0)*4;return jsxs(TableRow,{hover:true,onClick:r=>s&&s(r,k),role:"checkbox","aria-checked":g,tabIndex:-1,selected:g,sx:{cursor:"pointer"},children:[w&&jsx(TableCell,{padding:"checkbox",sx:{pl:I>0?I+1:void 0},children:jsx(Checkbox,{color:"primary",checked:g,inputProps:{"aria-labelledby":y}})}),a.filter(r=>t.includes(r.id)).map((r,b)=>{let C=!w&&b===0&&I>0?{pl:I+2}:{};return jsx(TableCell,{align:"left",sx:C,children:r.render?r.render(k[r.id],k):(function(){let T=k[r.id];if(r.numeric){if(typeof T=="number")return T.toLocaleString();if(typeof T=="string"&&T.trim()!==""&&!isNaN(Number(T)))return Number(T).toLocaleString()}return T})()},r.id)})]},m)}}),o.length===0&&jsx(TableRow,{children:jsx(TableCell,{colSpan:S,align:"center",children:"No data"})})]})};var Vo=e=>{let{visibleColumns:o,summaryRow:t,selectionMode:i}=e;if(!e.showSummary)return null;let s=i==="multiple"||i==="single";return jsx(TableFooter,{sx:{position:"sticky",bottom:0,zIndex:e.zIndex,bgcolor:"background.paper"},children:jsxs(TableRow,{children:[s&&jsx(TableCell,{padding:"checkbox",sx:{bgcolor:"background.paper"}}),o.map(a=>jsx(TableCell,{sx:{fontWeight:"bold",fontSize:"0.875rem",bgcolor:"background.paper",color:"text.primary"},children:(function(){let n=t[a];return n==null||n===""?"":typeof n=="number"?n.toLocaleString():typeof n=="string"&&n.trim()!==""&&!isNaN(Number(n))?Number(n).toLocaleString():n})()},a))]})})};var Ho=e=>jsx(Box,{sx:{p:2},children:jsx(Typography,{children:"Mobile View Not Implemented"})});var Oo=({groupAnchorEl:e,setGroupAnchorEl:o,grouping:t,setGrouping:i,columns:s,toggleGroupField:a})=>jsxs(Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsxs(Box,{sx:{p:1,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[jsx(Typography,{variant:"subtitle2",sx:{px:1},children:"Group By"}),t.length>0&&jsx(Button,{size:"small",color:"error",onClick:()=>i([]),startIcon:jsx(Aa,{}),children:"Clear All"})]}),jsx(Divider,{}),s.map(l=>{let n=t.includes(l.id),u=t.indexOf(l.id)+1;return jsx(MenuItem,{onClick:()=>a(l.id),children:jsxs(Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsx(Checkbox,{checked:n,size:"small"}),jsx(ListItemText,{primary:l.label}),n&&jsx(Badge,{badgeContent:u,color:"primary",sx:{mr:2}})]})},l.id)})]}),Go=({anchorEl:e,setAnchorEl:o,columns:t,visibleColumns:i,toggleColumnVisibility:s})=>jsxs(Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"Visible Columns"})}),jsx(Divider,{}),t.map(a=>jsxs(MenuItem,{onClick:()=>s(a.id),children:[jsx(Checkbox,{checked:i.includes(a.id),size:"small"}),jsx(ListItemText,{primary:a.label})]},a.id))]}),Wo=({anchorEl:e,setAnchorEl:o,showSummary:t,setShowSummary:i,columns:s,summaryColumns:a,toggleSummaryColumn:l})=>jsxs(Menu,{anchorEl:e,open:!!e,onClose:()=>o(null),children:[jsx(MenuItem,{children:jsx(FormControlLabel,{control:jsx(Switch,{checked:t,onChange:n=>i(n.target.checked),size:"small"}),label:"Show Summary Row"})}),jsx(Divider,{}),s.filter(n=>n.numeric).map(n=>jsxs(MenuItem,{onClick:()=>l(n.id),disabled:!t,children:[jsx(Checkbox,{checked:a.includes(n.id),size:"small"}),jsx(ListItemText,{primary:n.label})]},n.id)),s.filter(n=>n.numeric).length===0&&jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"No numeric columns"})})]}),$o=({contextMenu:e,handleCloseContextMenu:o,columns:t,visibleColumns:i,toggleColumnVisibility:s})=>jsxs(Menu,{open:e!==null,onClose:o,anchorReference:"anchorPosition",anchorPosition:e!==null?{top:e.mouseY,left:e.mouseX}:void 0,children:[jsx(MenuItem,{onClick:o,children:"Copy"}),jsx(Divider,{}),jsx(MenuItem,{disabled:true,children:"Visible Columns"}),t.map(a=>jsxs(MenuItem,{onClick:()=>s(a.id),children:[jsx(ListItemIcon,{children:i.includes(a.id)&&jsx(La,{fontSize:"small"})}),jsx(ListItemText,{children:a.label})]},a.id))]});var _e=(e,o=2)=>e.toLocaleString(void 0,{maximumFractionDigits:o}),jo=({kpis:e})=>{let o=[{label:"Total Records",value:_e(e.totalRecords,0),color:"text.primary"},{label:"Total Report",value:_e(e.totalReportHours),color:"text.primary"},{label:"Total Billable",value:_e(e.totalBillableHours),color:"success.main"},{label:"Efficiency",value:`${e.efficiency.toFixed(2)}%`,color:"warning.main"},{label:"Amount",value:_e(e.totalAmount),color:"info.main"},{label:"Flagged",value:_e(e.flaggedCount,0),color:"error.main"}];return jsx(Box,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",sm:"repeat(2, minmax(0, 1fr))",lg:"repeat(6, minmax(0, 1fr))"},gap:1.5},children:o.map(t=>jsxs(Paper,{variant:"outlined",sx:{p:1.5,borderRadius:2,minHeight:96,display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[jsx(Typography,{variant:"caption",color:"text.secondary",children:t.label}),jsx(Typography,{variant:"h4",fontWeight:800,sx:{color:t.color},children:t.value})]},t.label))})};var ft=["#1E88E5","#1ABC9C","#FBC02D","#EF5350","#7E57C2","#78909C"],za=({data:e})=>{let o=Math.max(...e.map(t=>t.value),1);return jsx(Stack,{spacing:1,children:e.map(t=>jsxs(Box,{sx:{display:"grid",gridTemplateColumns:"140px 1fr 64px",gap:1},children:[jsx(Typography,{variant:"caption",color:"text.secondary",noWrap:true,title:t.name,children:t.name}),jsx(Box,{sx:{alignSelf:"center",bgcolor:"action.hover",height:10,borderRadius:999,overflow:"hidden"},children:jsx(Box,{sx:{width:`${t.value/o*100}%`,height:"100%",bgcolor:"primary.main"}})}),jsx(Typography,{variant:"caption",sx:{textAlign:"right",fontWeight:600},children:t.value.toFixed(1)})]},t.name))})},Oa=({data:e})=>{let o=Math.max(...e.map(t=>t.value),1);return jsx(Box,{sx:{display:"flex",gap:1,alignItems:"flex-end",minHeight:210},children:e.map(t=>jsxs(Box,{sx:{flex:1,minWidth:0},children:[jsx(Box,{sx:{height:`${Math.max(t.value/o*180,6)}px`,bgcolor:"primary.main",borderRadius:"8px 8px 0 0"}}),jsx(Typography,{variant:"caption",noWrap:true,title:t.name,sx:{display:"block",mt:.5},children:t.name}),jsxs(Typography,{variant:"caption",color:"text.secondary",children:[t.value.toFixed(1),"%"]})]},t.name))})},Ga=({data:e})=>{if(e.length===0)return jsx(Typography,{variant:"body2",color:"text.secondary",children:"No data"});let o=0,i=`conic-gradient(${e.map((s,a)=>{let l=o;return o+=s.percent,`${ft[a%ft.length]} ${l}% ${o}%`}).join(", ")})`;return jsxs(Stack,{direction:{xs:"column",sm:"row"},spacing:2,alignItems:"center",children:[jsx(Box,{sx:{width:180,height:180,borderRadius:"50%",background:i,position:"relative"},children:jsx(Box,{sx:{position:"absolute",inset:30,bgcolor:"background.paper",borderRadius:"50%"}})}),jsx(Stack,{spacing:1,sx:{minWidth:180},children:e.map((s,a)=>jsxs(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsx(Box,{sx:{width:10,height:10,borderRadius:"50%",bgcolor:ft[a%ft.length]}}),jsx(Typography,{variant:"caption",sx:{flex:1},children:s.name}),jsxs(Typography,{variant:"caption",sx:{fontWeight:700},children:[s.percent.toFixed(0),"%"]})]},s.name))})]})},eo=({title:e,subtitle:o,children:t})=>jsxs(Paper,{variant:"outlined",sx:{p:2,borderRadius:2},children:[jsx(Typography,{variant:"subtitle1",fontWeight:700,children:e}),jsx(Typography,{variant:"body2",color:"text.secondary",sx:{mb:2},children:o}),t]}),Uo=({billableByPrimary:e,efficiencyBySecondary:o,statusDistribution:t})=>jsxs(Box,{sx:{display:"grid",gap:1.5,gridTemplateColumns:{xs:"1fr",lg:"1.2fr 1.2fr 1fr"}},children:[jsx(eo,{title:"Billable by Dimension",subtitle:"Top values by billable hours",children:jsx(za,{data:e})}),jsx(eo,{title:"Efficiency by Person",subtitle:"Lowest efficiency first",children:jsx(Oa,{data:o})}),jsx(eo,{title:"Status Distribution",subtitle:"Record ratio by status",children:jsx(Ga,{data:t})})]});var Yo=({open:e,onClose:o,model:t,tableContent:i})=>jsx(Dialog,{open:e,onClose:o,fullScreen:true,children:jsxs(Box,{sx:{height:"100%",display:"flex",flexDirection:"column",bgcolor:"background.default"},children:[jsx(Box,{sx:{p:2,borderBottom:1,borderColor:"divider"},children:jsxs(Stack,{direction:"row",alignItems:"center",justifyContent:"space-between",spacing:2,children:[jsxs(Stack,{direction:"row",spacing:1.5,alignItems:"center",children:[jsx(Typography,{variant:"h5",fontWeight:800,children:t.title}),jsx(Chip,{size:"small",label:`${t.kpis.totalRecords} records`})]}),jsx(IconButton,{onClick:o,children:jsx(Ua,{})})]})}),jsxs(Box,{sx:{p:2,display:"flex",flexDirection:"column",gap:1.5,overflow:"auto",minHeight:0},children:[jsx(jo,{kpis:t.kpis}),jsx(Uo,{billableByPrimary:t.charts.billableByPrimary,efficiencyBySecondary:t.charts.efficiencyBySecondary,statusDistribution:t.charts.statusDistribution}),i]})]})});var Se={primaryDimension:["Client","Customer","Category","Project"],secondaryDimension:["Person","Consultant","Owner","Name"],status:["Status","state"],date:["Date","WorkDate","CreatedAt"],description:["Description","Task","Title","Memo"],reportHours:["Report_Hour","Report Hours","Hours","ReportHours"],billableHours:["Billable_Hour","Billable Hours","BillableHours"],amount:["Amount","Billable_Amount","Total_Amount","Value"]},Ka=5,qo=e=>e.toLowerCase().replace(/[\s_-]/g,""),Te=(e,o,t,i)=>{if(o)return o;if(e.length===0)return i;let s=Object.keys(e[0]),a=new Map(s.map(l=>[qo(l),l]));for(let l of t){let n=a.get(qo(l));if(n)return n}return s[0]||i},ye=e=>{if(typeof e=="number")return Number.isFinite(e)?e:0;if(typeof e=="string"){let o=Number(e.replace(/,/g,"").trim());return Number.isFinite(o)?o:0}return 0},be=(e,o)=>e==null||e===""?o:String(e),Ya=(e,o,t,i)=>{let s=new Map;return e.forEach(a=>{let l=be(a[o],"Unassigned");s.set(l,(s.get(l)||0)+ye(a[t]));}),Array.from(s.entries()).map(([a,l])=>({name:a,value:l})).sort((a,l)=>l.value-a.value).slice(0,i)},qa=(e,o,t,i,s)=>{let a=new Map;return e.forEach(l=>{let n=be(l[o],"Unassigned"),u=a.get(n)||{report:0,billable:0};u.report+=ye(l[t]),u.billable+=ye(l[i]),a.set(n,u);}),Array.from(a.entries()).map(([l,n])=>({name:l,value:n.report>0?n.billable/n.report*100:0})).sort((l,n)=>l.value-n.value).slice(0,s)},Xa=(e,o)=>{let t=e.length;if(t===0)return [];let i=new Map;return e.forEach(s=>{let a=be(s[o],"Unassigned");i.set(a,(i.get(a)||0)+1);}),Array.from(i.entries()).map(([s,a])=>({name:s,value:a,percent:a/t*100}))},Xo=({rows:e,config:o})=>{let t=useMemo(()=>{let u=o?.fieldMapping;return {primaryDimension:Te(e,u?.primaryDimension,Se.primaryDimension,"Category"),secondaryDimension:Te(e,u?.secondaryDimension,Se.secondaryDimension,"Owner"),status:Te(e,u?.status,Se.status,"Status"),date:Te(e,u?.date,Se.date,"Date"),description:Te(e,u?.description,Se.description,"Description"),reportHours:Te(e,u?.reportHours,Se.reportHours,"ReportHours"),billableHours:Te(e,u?.billableHours,Se.billableHours,"BillableHours"),amount:Te(e,u?.amount,Se.amount,"Amount")}},[e,o?.fieldMapping]),i=useMemo(()=>e.map((u,v)=>{let w=ye(u[t.reportHours]),S=ye(u[t.billableHours]),x=ye(u[t.amount]),P=w>0?S/w*100:0;return {id:`graph-row-${v}`,Date:be(u[t.date],""),Primary:be(u[t.primaryDimension],"Unassigned"),Secondary:be(u[t.secondaryDimension],"Unassigned"),Description:be(u[t.description],""),ReportHours:w,BillableHours:S,Amount:x,Efficiency:P,Status:be(u[t.status],"Unassigned")}}),[e,t]),s=useMemo(()=>{let u=i.length,v=i.reduce((m,g)=>m+ye(g.ReportHours),0),w=i.reduce((m,g)=>m+ye(g.BillableHours),0),S=i.reduce((m,g)=>m+ye(g.Amount),0),x=v>0?w/v*100:0,P=o?.statusFlagValues||["flag","flagged","warning","risk"],k=i.filter(m=>P.includes(be(m.Status,"").toLowerCase())).length;return {totalRecords:u,totalReportHours:v,totalBillableHours:w,efficiency:x,totalAmount:S,flaggedCount:k}},[i,o?.statusFlagValues]),a=o?.topN||Ka,l=useMemo(()=>({billableByPrimary:Ya(i,"Primary","BillableHours",a),efficiencyBySecondary:qa(i,"Secondary","ReportHours","BillableHours",a),statusDistribution:Xa(i,"Status")}),[i,a]),n=useMemo(()=>({title:o?.title||"Graphic Report",kpis:s,charts:l,table:{columns:[{id:"Date",label:t.date},{id:"Primary",label:t.primaryDimension},{id:"Secondary",label:t.secondaryDimension},{id:"Description",label:t.description},{id:"ReportHours",label:"Report Hours",align:"right"},{id:"BillableHours",label:"Billable Hours",align:"right"},{id:"Amount",label:"Amount",align:"right"},{id:"Efficiency",label:"Efficiency",align:"right"},{id:"Status",label:t.status}],rows:i}}),[l,o?.title,t,s,i]);return {fieldMapping:t,model:n}};var bt=({variants:e,currentVariantId:o,onLoad:t,onSave:i,onDelete:s,onSetDefault:a})=>{let l="0.75rem",[n,u]=useState(false),[v,w]=useState(""),[S,x]=useState(false),[P,k]=useState(false),m=e.find(d=>d.id===o);return jsxs(Box,{sx:{display:"flex",gap:1,alignItems:"center"},children:[jsx(Typography,{variant:"body2",sx:{fontWeight:"bold",minWidth:"fit-content",fontSize:l},children:"Variant:"}),jsx(Autocomplete,{size:"small",sx:{width:200,"& .MuiInputBase-root":{fontSize:l},"& .MuiInputBase-input":{fontSize:l},"& .MuiAutocomplete-noOptions":{fontSize:l}},noOptionsText:jsx(Typography,{sx:{fontSize:l},children:"No options"}),options:e,getOptionLabel:d=>d.name+(d.isDefault?" (Default)":""),value:m||null,onChange:(d,I)=>{I&&t(I);},renderInput:d=>jsx(TextField,{...d,variant:"outlined",size:"small",InputProps:{...d.InputProps,sx:{fontSize:l}},placeholder:"Select Variant"}),renderOption:(d,I)=>jsx("li",{...d,children:jsxs(Box,{sx:{display:"flex",alignItems:"center",width:"100%"},children:[jsx(Typography,{sx:{flex:1,fontSize:l},children:I.name}),I.isDefault&&jsx(rr,{fontSize:"small",color:"action"})]})})}),jsx(Tooltip,{title:"Save View",children:jsx(IconButton,{onClick:()=>{w(m?.name||"New Variant"),x(m?.isDefault||false),k(m?.isPublic||false),u(true);},size:"small",color:"primary",children:jsx(yn,{})})}),jsxs(Dialog,{open:n,onClose:()=>u(false),children:[jsx(DialogTitle,{children:"Save View"}),jsxs(DialogContent,{children:[jsx(TextField,{autoFocus:true,margin:"dense",label:"View Name",fullWidth:true,variant:"outlined",value:v,onChange:d=>w(d.target.value)}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:S,onChange:d=>x(d.target.checked)}),label:"Set as Default"}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:P,onChange:d=>k(d.target.checked)}),label:"Public (All Users)"})]}),jsxs(DialogActions,{children:[jsx(Button,{onClick:()=>u(false),children:"Cancel"}),jsx(Button,{onClick:()=>{i({name:v,isDefault:S,isPublic:P,description:""}),u(false);},variant:"contained",children:"Save"})]})]})]})};var sr="http://127.0.0.1:8515",nn=({appId:e,tableKey:o="default",currentFilters:t,currentLayoutId:i,layoutRefs:s,onLoad:a,serviceUrl:l=sr,onError:n,onSuccess:u,currentVariantId:v,onVariantChange:w})=>{let[S,x]=useState([]),[P,k]=useState(""),m=v!==void 0?v:P,g=c=>{v===void 0&&k(c),w&&w(c);},y=useCallback(async()=>{if(!e)return [];try{let c=await fetch(`${l}/api/variants?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!c.ok)throw new Error("Failed to fetch variants");let C=await c.json();x(C);let M=C.find(T=>T.isDefault);return M&&!m&&(g(M.id),a(M)),C}catch(c){return console.error("Error fetching variants",c),n&&n("Failed to load variants"),[]}},[e,o,l,n,m,a]);return useEffect(()=>{y();},[e,o]),jsx(bt,{variants:S,currentVariantId:m,onLoad:c=>{g(c.id),a(c);},onSave:async c=>{try{let C=S.find(A=>A.name===c.name),M=C?C.id:Date.now().toString(),T=[];if(C&&(Array.isArray(C.filters)?T=[...C.filters]:C.filters&&(T=[{scope:"default",filters:C.filters}])),c.scope==="Search"||c.scope==="Both"){let A=(Array.isArray(t),t);if(A)if(Array.isArray(A)&&A.length>0&&A[0].scope)A.forEach(V=>{let B=T.findIndex(H=>H.scope===V.scope);B>=0?T[B]=V:T.push(V);});else {let V={scope:o,filters:A},B=T.findIndex(H=>H.scope===o);B>=0?T[B]=V:T.push(V);}}let p=C?.layout||{},D=[];if(C&&Array.isArray(C.layoutRefs)&&(D=[...C.layoutRefs]),c.scope==="Layout"||c.scope==="Both")if(s&&s.length>0)s.forEach(A=>{let V=D.findIndex(B=>B.tableKey===A.tableKey);V>=0?D[V]=A:D.push(A);});else {let A={tableKey:o,layoutId:i||null},V=D.findIndex(B=>B.tableKey===o);V>=0?D[V]=A:D.push(A);}let f={appId:e,tableKey:o,...c,id:M,createdAt:new Date().toISOString(),filters:T,layout:p,layoutRefs:D};if(!(await fetch(`${l}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(f)})).ok)throw new Error("Failed to save variant");u&&u("Variant saved successfully"),await y(),g(M),a(f);}catch(C){console.error("Error saving variant",C),n&&n("Failed to save variant");}},onDelete:async c=>{try{if(!(await fetch(`${l}/api/variants/${c}`,{method:"DELETE"})).ok)throw new Error("Failed to delete variant");m===c&&g(""),y(),u&&u("Variant deleted successfully");}catch(C){console.error("Error deleting variant",C),n&&n("Failed to delete variant");}},onSetDefault:async c=>{try{let C=S.find(p=>p.id===c);if(!C)return;let M={appId:e,tableKey:o,...C,isDefault:!0};if(!(await fetch(`${l}/api/variants`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(M)})).ok)throw new Error("Failed to set default variant");await y(),u&&u("Default variant updated");}catch(C){console.error("Error setting default variant",C),n&&n("Failed to update default variant");}}})};De.extend(Tr);var wr=[null,null],io="0.75rem",Ir=styled(PickersDay,{shouldForwardProp:e=>e!=="isInRange"&&e!=="isStart"&&e!=="isEnd"&&e!=="isHovered"})(({theme:e,isInRange:o,isStart:t,isEnd:i,isHovered:s})=>({...o&&{borderRadius:0,backgroundColor:e.palette.primary.light,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.main}},...s&&!o&&!t&&!i&&{borderRadius:0,backgroundColor:e.palette.action.hover,border:`1px dashed ${e.palette.primary.main}`},...t&&{borderRadius:"50% 0 0 50%",backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.dark}},...i&&{borderRadius:"0 50% 50% 0",backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.dark}},...t&&i&&{borderRadius:"50%"}})),ln=({label:e="Date Range",value:o=wr,onChange:t})=>{let[i,s]=useState(null),[a,l]=useState(o),[n,u]=useState("start"),[v,w]=useState(null),[S,x]=useState(o[0]||De()),P=bo__default.useRef(o);useEffect(()=>{let[M,T]=o,[p,D]=P.current,f=V=>V&&typeof V.isSame=="function",W=!(M===null&&p===null||f(M)&&f(p)&&M.isSame(p,"day")),A=!(T===null&&D===null||f(T)&&f(D)&&T.isSame(D,"day"));(W||A)&&(l(o),o[0]&&f(o[0])&&x(o[0])),P.current=o;},[o]);let k=M=>{s(M.currentTarget);},m=()=>{s(null),u("start"),w(null);},g=!!i,y=M=>{if(!M)return;let T=[...a];if(n==="start")T=[M,null],u("end");else {let p=T[0];p&&M.isBefore(p)?(T=[M,null],u("end")):(T=[p,M],u("start"));}l(T);},d=M=>{let T=De(),p=[null,null];switch(M){case "today":p=[T,T];break;case "week":p=[T.startOf("week"),T.endOf("week")];break;case "month":p=[T.startOf("month"),T.endOf("month")];break}l(p),u("start"),x(T);},I=()=>{l([null,null]),u("start"),x(De());},r=()=>{t&&t(a),m();},b=()=>{l(o),u("start"),m();},c=useCallback(M=>{let{day:T,...p}=M,[D,f]=a,W=D?T.isSame(D,"day"):false,A=f?T.isSame(f,"day"):false,V=D&&f?T.isBetween(D,f,"day","()"):false,B=false;return n==="end"&&D&&!f&&v&&T.isAfter(D,"day")&&T.isBefore(v.add(1,"day"),"day")&&(B=true),jsx(Ir,{...p,day:T,disableMargin:true,isStart:W,isEnd:A,isInRange:V||B,onMouseEnter:()=>w(T)})},[a,n,v]),C=M=>M?M.format("YYYY-MM-DD"):"";return jsxs(Box,{children:[jsx(TextField,{label:e,value:a[0]?`${C(a[0])} - ${C(a[1])}`:"",onClick:k,fullWidth:true,size:"small",InputLabelProps:{sx:{fontSize:io}},InputProps:{readOnly:true,sx:{fontSize:io,"& .MuiOutlinedInput-input":{fontSize:io},paddingRight:"4px"},endAdornment:jsxs(InputAdornment,{position:"end",sx:{ml:0},children:[(a[0]||a[1])&&jsx(IconButton,{size:"small",onClick:M=>{M.stopPropagation(),I();},edge:"end",sx:{mr:.5,padding:"2px"},children:jsx(vr,{sx:{fontSize:"1rem"}})}),jsx(IconButton,{size:"small",edge:"end",onClick:k,sx:{padding:"2px"},children:jsx(Cr,{sx:{fontSize:"1rem"},color:"action"})})]})}}),jsxs(Popover,{open:g,anchorEl:i,onClose:m,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},slotProps:{paper:{sx:{display:"flex",flexDirection:"column",p:0,minWidth:320}}},children:[jsx(Box,{sx:{p:2,bgcolor:"background.default",borderBottom:1,borderColor:"divider"},children:jsxs(Stack,{direction:"row",alignItems:"center",spacing:2,justifyContent:"space-between",children:[jsxs(Box,{sx:{p:1,border:1,borderColor:n==="start"?"primary.main":"divider",borderRadius:1,bgcolor:n==="start"?"action.hover":"transparent",flex:1,cursor:"pointer"},onClick:()=>u("start"),children:[jsx(Typography,{variant:"caption",color:"text.secondary",display:"block",children:"Start Date"}),jsx(Typography,{variant:"body2",fontWeight:500,children:a[0]?a[0].format("MMM DD, YYYY"):"Select..."})]}),jsx(Sr,{color:"action",fontSize:"small"}),jsxs(Box,{sx:{p:1,border:1,borderColor:n==="end"?"primary.main":"divider",borderRadius:1,bgcolor:n==="end"?"action.hover":"transparent",flex:1,cursor:"pointer"},onClick:()=>{a[0]&&u("end");},children:[jsx(Typography,{variant:"caption",color:"text.secondary",display:"block",children:"End Date"}),jsx(Typography,{variant:"body2",fontWeight:500,children:a[1]?a[1].format("MMM DD, YYYY"):"Select..."})]})]})}),jsx(Box,{sx:{p:2,pb:0},children:jsxs(Stack,{direction:"row",spacing:1,justifyContent:"center",children:[jsx(Chip,{label:"Today",onClick:()=>d("today"),clickable:true,size:"small",variant:"outlined"}),jsx(Chip,{label:"This Week",onClick:()=>d("week"),clickable:true,size:"small",variant:"outlined"}),jsx(Chip,{label:"This Month",onClick:()=>d("month"),clickable:true,size:"small",variant:"outlined"})]})}),jsx(DateCalendar,{value:null,referenceDate:S,onMonthChange:x,onYearChange:x,onChange:y,slots:{day:c},views:["day"],showDaysOutsideCurrentMonth:true,sx:{m:0}}),jsx(Divider,{}),jsxs(Stack,{direction:"row",justifyContent:"flex-end",spacing:1,sx:{p:2},children:[jsx(Button,{size:"small",onClick:b,color:"inherit",children:"Cancel"}),jsx(Button,{size:"small",variant:"contained",onClick:r,children:"Done"})]})]})]})};var St={equals:"=",contains:"\u2287",notContains:"\u2285",wildcard:"*","=":"=","!=":"!=",">":">","<":"<",">=":"\u2265","<=":"\u2264",between:"\u2194"},Vr={equals:"Equals",contains:"Contains",notContains:"Does Not Contain",wildcard:"Wildcard Search","=":"Equals","!=":"Not Equals",">":"Greater Than","<":"Less Than",">=":"Greater Than or Equal","<=":"Less Than or Equal",between:"Between"},Nr=["equals","contains","notContains","wildcard"],dn=["=","!=",">","<",">=","<=","between"],Z="0.75rem",Hr=({field:e,value:o,onChange:t})=>{let[i,s]=useState(null),[a,l]=useState(null),[n,u]=useState(""),[v,w]=useState(""),[S,x]=useState(false),[P,k]=useState(""),[m,g]=useState("");useEffect(()=>{let p=setTimeout(()=>{g(P);},1e3);return ()=>clearTimeout(p)},[P]);let y=o?.operator||(e.type==="number"?"=":"equals"),d=o?.value,I=p=>Vr[p]||p,r=p=>{s(p.currentTarget);},b=p=>{t({...o,operator:p,value:d}),s(null);},c={size:"small",fullWidth:true,variant:"outlined",InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}},SelectProps:{MenuProps:{PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,paddingTop:"4px",paddingBottom:"4px",minHeight:"auto"}}}}}},C=e.type||"text";if(C==="date"){let D=(f=>{if(!f)return [null,null];if(Array.isArray(f)&&f.length===2){let W=f[0]?De.isDayjs(f[0])?f[0]:De(f[0]):null,A=f[1]?De.isDayjs(f[1])?f[1]:De(f[1]):null;return [W,A]}return De.isDayjs(f)||typeof f=="string"?[De.isDayjs(f)?f:De(f),null]:[null,null]})(d);return jsx(ln,{label:e.label,value:D,onChange:f=>t({value:f,operator:"between"})})}if(C==="number"&&y==="between"){let p=()=>{t({value:[n,v],operator:"between"}),l(null);},D=Array.isArray(d)?`${d[0]||""} - ${d[1]||""}`:"";return jsxs(Fragment,{children:[jsx(TextField,{...c,label:e.label,value:D,placeholder:"Min - Max",InputProps:{...c.InputProps,startAdornment:jsx(InputAdornment,{position:"start",children:jsx(Tooltip,{title:I("between"),children:jsx(IconButton,{size:"small",onClick:r,sx:{width:24,height:24,fontSize:Z},children:St.between})})}),readOnly:true},onClick:f=>l(f.currentTarget)}),jsx(Menu,{anchorEl:i,open:!!i,onClose:()=>s(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,minHeight:"auto",py:.5}}},children:dn.map(f=>jsxs(MenuItem,{selected:f===y,onClick:()=>b(f),children:[jsx(Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:St[f]}),jsx(ListItemText,{primary:I(f),primaryTypographyProps:{fontSize:Z}})]},f))}),jsx(Popover,{open:!!a,anchorEl:a,onClose:()=>l(null),anchorOrigin:{vertical:"bottom",horizontal:"left"},children:jsxs(Box,{sx:{p:2,display:"flex",gap:1,alignItems:"center"},children:[jsx(TextField,{size:"small",label:"Min",type:"number",value:n,onChange:f=>u(f.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}}}),jsx(Fr,{color:"action"}),jsx(TextField,{size:"small",label:"Max",type:"number",value:v,onChange:f=>w(f.target.value),sx:{width:100},InputLabelProps:{sx:{fontSize:Z}},InputProps:{sx:{fontSize:Z}}}),jsx(Button,{variant:"contained",size:"small",onClick:p,children:"OK"})]})})]})}if(C==="select")return jsxs(TextField,{...c,select:true,label:e.label,value:d||"",onChange:p=>t({...o,value:p.target.value,operator:"equals"}),children:[jsx(MenuItem,{value:"",children:jsx("em",{children:"None"})}),e.options?.map(p=>jsx(MenuItem,{value:p.value,children:p.label},p.value))]});if(C==="multi-select"){let p=Array.isArray(d)?d:[],D=e.options?.filter(f=>f.label.toLowerCase().includes(m.toLowerCase()))||[];return jsxs(TextField,{...c,select:true,label:e.label,value:p,onChange:f=>t({...o,value:f.target.value,operator:"anyOf"}),SelectProps:{...c.SelectProps,multiple:true,onClose:()=>{k(""),g("");},renderValue:f=>{if(!Array.isArray(f)||f.length===0)return jsx("em",{children:"None"});let W=V=>e.options?.find(B=>B.value===V)?.label||V,A=f.map(W);return A.length>2?`${A.slice(0,2).join(", ")} +${A.length-2}`:A.join(", ")}},children:[jsx(ListSubheader,{children:jsx(TextField,{size:"small",autoFocus:true,placeholder:"Search...",fullWidth:true,InputProps:{startAdornment:jsx(InputAdornment,{position:"start",children:jsx(cn,{fontSize:"small"})}),sx:{fontSize:Z}},value:P,onChange:f=>k(f.target.value),onKeyDown:f=>{f.key!=="Escape"&&f.stopPropagation();},onClick:f=>f.stopPropagation()})}),D.length>0?D.map(f=>jsxs(MenuItem,{value:f.value,children:[jsx(Checkbox,{checked:p.indexOf(f.value)>-1,size:"small"}),jsx(ListItemText,{primary:f.label,primaryTypographyProps:{fontSize:Z}})]},f.value)):jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"No options found",primaryTypographyProps:{fontSize:Z}})})]})}let M=C==="number"?dn:Nr,T=S||d!==void 0&&d!==""&&d!==null||!!i;return jsxs(Fragment,{children:[jsx(TextField,{...c,label:e.label,sx:{minWidth:"120px"},value:d||"",type:C==="number"?"number":"text",onChange:p=>t({...o,value:p.target.value,operator:y}),onFocus:()=>x(true),onBlur:()=>x(false),InputProps:{...c.InputProps,startAdornment:T?jsx(InputAdornment,{position:"start",children:jsx(Tooltip,{title:I(y),children:jsx(IconButton,{size:"small",onClick:r,onMouseDown:p=>p.preventDefault(),sx:{width:24,height:24,fontSize:Z,fontWeight:"bold",color:"primary.main",bgcolor:"action.hover"},children:St[y]})})}):null,endAdornment:e.hasSearchIcon?jsx(InputAdornment,{position:"end",children:jsx(cn,{color:"action"})}):void 0}}),jsx(Menu,{anchorEl:i,open:!!i,onClose:()=>s(null),PaperProps:{sx:{"& .MuiMenuItem-root":{fontSize:Z,minHeight:"auto",py:.5}}},children:M.map(p=>jsxs(MenuItem,{selected:p===y,onClick:()=>b(p),children:[jsx(Box,{sx:{width:24,display:"inline-block",fontWeight:"bold"},children:St[p]}),jsx(ListItemText,{primary:I(p),primaryTypographyProps:{fontSize:Z}})]},p))})]})},qe=({fields:e,filters:o,onFilterChange:t,variants:i=[],currentVariantId:s,onVariantLoad:a,onVariantSave:l,onVariantDelete:n,onVariantSetDefault:u,onSearch:v,loading:w=false,appId:S,tableKey:x,currentLayout:P,currentLayoutId:k,layoutRefs:m,variantService:g})=>{let[y,d]=useState(true),[I,r]=useState(null),[b,c]=useState(e.filter(p=>!p.hidden).map(p=>p.id)),C=(p,D)=>{t({...o,[p]:D});},M=p=>{b.includes(p)?c(b.filter(D=>D!==p)):c([...b,p]);};return jsxs(Paper,{sx:{mb:0,display:"flex",flexDirection:"column",overflow:"visible",position:"relative"},children:[jsxs(Box,{sx:{p:2,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[S?jsx(nn,{appId:S,tableKey:x,currentFilters:{values:o,visibleFields:b},currentLayout:P,currentLayoutId:k,layoutRefs:m,onLoad:p=>{if(!p.filters)return;let D=null;if(Array.isArray(p.filters)){let f=x||"default",W=p.filters.find(A=>A.scope===f);D=W?W.filters:null;}else D=p.filters;D&&(D.values||D.visibleFields?(D.visibleFields&&Array.isArray(D.visibleFields)&&c(D.visibleFields),D.values&&t(D.values)):t(D)),a&&a(p);},variantService:g,currentVariantId:s}):jsx(bt,{variants:i,currentVariantId:s,onLoad:a,onSave:p=>{l&&l({...p,filters:{values:o,visibleFields:b}});},onDelete:n,onSetDefault:u}),jsxs(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsx(Tooltip,{title:"Add Filters",children:jsx(Button,{onClick:p=>r(p.currentTarget),size:"small",color:"primary",startIcon:jsx(Br,{fontSize:"small"}),sx:{textTransform:"none",fontSize:Z},children:"Adapt Filters"})}),jsx(Button,{variant:"contained",size:"small",onClick:v,disabled:w,sx:{minWidth:"40px",fontWeight:"bold"},children:w?"...":"Go"}),jsxs(Menu,{anchorEl:I,open:!!I,onClose:()=>r(null),slotProps:{paper:{style:{maxHeight:400,width:"25ch"}}},children:[jsx(MenuItem,{disabled:true,children:jsx(ListItemText,{primary:"Visible Filters"})}),jsx(Divider,{}),e.map(p=>jsxs(MenuItem,{onClick:()=>M(p.id),children:[jsx(Checkbox,{checked:b.includes(p.id),size:"small"}),jsx(ListItemText,{primary:p.label})]},p.id))]})]})]}),jsx(Collapse,{in:y,children:jsx(Box,{sx:{px:2,pb:2},children:jsx(Grid,{container:true,spacing:2,columns:{xs:2,sm:3,md:4,lg:6},children:e.filter(p=>b.includes(p.id)).map(p=>jsx(Grid,{size:1,children:jsx(Hr,{field:p,value:o[p.id]||{value:"",operator:p.type==="number"?"=":"equals"},onChange:D=>C(p.id,D)})},p.id))})})}),jsx(Box,{sx:{position:"absolute",bottom:0,left:"50%",transform:"translate(-50%, 50%)",zIndex:10},children:jsx(IconButton,{size:"small",onClick:()=>d(!y),sx:{bgcolor:"background.paper",boxShadow:2,border:"1px solid",borderColor:"divider",width:20,height:20,minHeight:0,p:0,"&:hover":{bgcolor:"background.paper"}},children:y?jsx(Lr,{sx:{fontSize:16},color:"action"}):jsx(va,{sx:{fontSize:16},color:"action"})})})]})};var bn=({layouts:e,currentLayoutId:o,onLoad:t,onSave:i,onDelete:s,onSetDefault:a})=>{let[l,n]=useState(null),[u,v]=useState(false),[w,S]=useState(""),[x,P]=useState(""),[k,m]=useState({isDefault:false,isPublic:false}),g=e.find(c=>c.id===o),y=c=>{n(c.currentTarget);},d=()=>{n(null);},I=c=>{t(c),d();},r=()=>{S(""),P(""),m({isDefault:false,isPublic:false}),v(true),d();},b=()=>{w.trim()&&(i({name:w,description:x,...k}),v(false));};return jsxs(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[jsx(Tooltip,{title:"Save Layout",children:jsx(IconButton,{onClick:r,color:"primary",size:"small",children:jsx(yn,{})})}),jsx(Tooltip,{title:"Layout Options",children:jsx(IconButton,{onClick:y,color:g?"primary":"default",children:jsx(Xr,{})})}),jsxs(Menu,{anchorEl:l,open:!!l,onClose:d,PaperProps:{sx:{width:320,maxHeight:400}},children:[jsx(MenuItem,{disabled:true,children:jsx(Typography,{variant:"caption",children:"Select Layout"})}),jsxs(MenuItem,{onClick:r,children:[jsx(ListItemIcon,{children:jsx(yn,{fontSize:"small"})}),jsx(ListItemText,{children:"Save Current Layout..."})]}),jsx(Divider,{}),e.length===0&&jsx(MenuItem,{disabled:true,children:jsx(Typography,{variant:"body2",color:"text.secondary",children:"No saved layouts"})}),e.map((c,C)=>jsx(MenuItem,{onClick:()=>I(c),selected:c.id===o,children:jsxs(Box,{sx:{display:"flex",alignItems:"center",width:"100%",justifyContent:"space-between"},children:[jsxs(Box,{sx:{display:"flex",flexDirection:"column",overflow:"hidden",mr:1},children:[jsx(Box,{sx:{display:"flex",alignItems:"center",gap:1},children:jsx(Typography,{variant:"body2",fontWeight:c.id===o?"bold":"normal",noWrap:true,children:c.name})}),c.description&&jsx(Typography,{variant:"caption",color:"text.secondary",noWrap:true,children:c.description})]}),jsxs(Box,{sx:{display:"flex",alignItems:"center"},onClick:M=>M.stopPropagation(),children:[jsx(Tooltip,{title:c.isDefault?"Remove Default":"Set as Default",children:jsx(IconButton,{size:"small",onClick:M=>{M.stopPropagation(),a(c.id);},children:c.isDefault?jsx(rr,{fontSize:"small",color:"warning"}):jsx(qr,{fontSize:"small"})})}),jsx(Tooltip,{title:"Delete",children:jsx(IconButton,{size:"small",color:"error",onClick:M=>{M.stopPropagation(),s(c.id);},children:jsx(Kr,{fontSize:"small"})})})]})]})},c.id||C))]}),jsxs(Dialog,{open:u,onClose:()=>v(false),maxWidth:"xs",fullWidth:true,children:[jsx(DialogTitle,{children:"Save Layout"}),jsx(DialogContent,{children:jsxs(Box,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[jsx(TextField,{label:"Layout Name",value:w,onChange:c=>S(c.target.value),fullWidth:true,autoFocus:true,size:"small",helperText:"e.g., 'Compact View'"}),e.some(c=>c.name===w)&&jsx(Typography,{variant:"caption",color:"warning.main",sx:{ml:1},children:"Warning: Existing layout will be overwritten"}),jsx(TextField,{label:"Description",value:x,onChange:c=>P(c.target.value),fullWidth:true,size:"small"}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:k.isDefault,onChange:c=>m({...k,isDefault:c.target.checked})}),label:"Use as Default Layout"}),jsx(FormControlLabel,{control:jsx(Checkbox,{checked:k.isPublic,onChange:c=>m({...k,isPublic:c.target.checked})}),label:"Public (Visible to all users)"})]})}),jsxs(DialogActions,{children:[jsx(Button,{onClick:()=>v(false),children:"Cancel"}),jsx(Button,{onClick:b,variant:"contained",disabled:!w,children:"Save"})]})]})]})};var Zr="http://127.0.0.1:8515",Cn=({appId:e,tableKey:o="default",currentLayoutData:t,onLayoutLoad:i,targetLayoutId:s,activeLayoutId:a,serviceUrl:l=Zr,onError:n,onSuccess:u})=>{let[v,w]=useState([]),[S,x]=useState(""),P=r=>({id:r.layoutId,name:r.name,description:r.description??"",isDefault:!!r.isDefault,isPublic:!!r.isPublic,createdAt:r.createdAt??new Date().toISOString(),layoutData:r.layout??{}}),k=r=>({appId:e,tableKey:o,layoutId:r.id,name:r.name,description:r.description??"",isDefault:!!r.isDefault,isPublic:!!r.isPublic,createdAt:r.createdAt,layout:r.layoutData});useEffect(()=>{a!==void 0&&x(a);},[a]),useEffect(()=>{if(s&&v.length>0){let r=v.find(b=>b.id===s);r&&(x(r.id),i(r));}},[s,v,i]);let m=useCallback(async()=>{if(e)try{let r=await fetch(`${l}/api/layouts?appId=${encodeURIComponent(e)}&tableKey=${encodeURIComponent(o)}`);if(!r.ok)throw new Error("Failed to fetch layouts");let c=(await r.json()).map(P);w(c);let C=c.find(M=>M.isDefault);C&&!S&&!s&&(x(C.id),i(C));}catch(r){console.error("Error fetching layouts",r),n&&n("Failed to load layouts");}},[e,o,l,n,S,i,s]);return useEffect(()=>{m();},[e,o]),jsx(bn,{layouts:v,currentLayoutId:S,onLoad:r=>{x(r.id),i(r);},onSave:async r=>{try{let b=v.find(T=>T.name===r.name),c=b?b.id:Date.now().toString(),C={id:c,...r,createdAt:new Date().toISOString(),layoutData:t,isDefault:r.isDefault??!1,isPublic:r.isPublic??!1};if(!(await fetch(`${l}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k(C))})).ok)throw new Error("Failed to save layout");u&&u("Layout saved successfully"),await m(),x(c),i(C);}catch(b){console.error("Error saving layout",b),n&&n("Failed to save layout");}},onDelete:async r=>{try{if(!(await fetch(`${l}/api/layouts/${encodeURIComponent(r)}`,{method:"DELETE"})).ok)throw new Error("Failed to delete layout");S===r&&x(""),u&&u("Layout deleted successfully"),await m();}catch(b){console.error("Error deleting layout",b),n&&n("Failed to delete layout");}},onSetDefault:async r=>{try{let b=v.find(C=>C.id===r);if(!b)return;if(!(await fetch(`${l}/api/layouts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k({...b,isDefault:!0}))})).ok)throw new Error("Failed to set default layout");u&&u("Default layout set"),await m();}catch(b){console.error("Error setting default",b),n&&n("Failed to set default layout");}}})};function Sn(e,o,t){return o[t]<e[t]?-1:o[t]>e[t]?1:0}function ei(e,o){return e==="desc"?(t,i)=>Sn(t,i,o):(t,i)=>-Sn(t,i,o)}function ti(e,o){let t=e.map((i,s)=>[i,s]);return t.sort((i,s)=>{let a=o(i[0],s[0]);return a!==0?a:i[1]-s[1]}),t.map(i=>i[0])}var Tn=e=>{let o=useCallback(h=>{let L=String(h?.label??h?.id??"").length*9+64,ee=typeof h?.minWidth=="number"?h.minWidth:0;return Math.max(100,ee,L)},[]),[t,i]=useState(""),[s,a]=useState(e.order||"asc"),[l,n]=useState(e.orderBy||""),[u,v]=useState(e.page||0),[w,S]=useState(e.rowsPerPage||20),[x,P]=useState(e.selected||[]),[k,m]=useState(e.columns?e.columns.map(h=>h.id):[]),[g,y]=useState(e.showSummary||false),[d,I]=useState([]),[r,b]=useState(new Set),[c,C]=useState(()=>{let h={};return (e.columns||[]).forEach(E=>{h[E.id]=o(E);}),h}),[M,T]=useState(null),[p,D]=useState(null),[f,W]=useState(null),[A,V]=useState(null),[B,H]=useState(false);useEffect(()=>{e.order!==void 0&&a(e.order),e.orderBy!==void 0&&n(e.orderBy);},[e.order,e.orderBy]),useEffect(()=>{e.selected!==void 0&&P(e.selected);},[e.selected]),useEffect(()=>{e.page!==void 0&&v(e.page);},[e.page]),useEffect(()=>{C(h=>{let E={...h};return (e.columns||[]).forEach(L=>{E[L.id]===void 0&&(E[L.id]=o(L));}),E});},[e.columns,o]);let z=useMemo(()=>{let h=e.rows||[];return t&&(h=h.filter(E=>Object.keys(E).some(L=>String(E[L]).toLowerCase().includes(t.toLowerCase())))),h},[e.rows,t]),ke=useMemo(()=>e.onSortChange||!l?z:ti(z,ei(s,l)),[z,s,l,e.onSortChange]),Me=useCallback(h=>{if(d.length===0)return h.map(Y=>({type:"row",data:Y,id:Y[e.rowKey||"id"]}));let E=[...h].sort((Y,J)=>{for(let U of d){if(Y[U]<J[U])return -1;if(Y[U]>J[U])return 1}return 0}),L=(Y,J=0)=>{if(J>=d.length)return Y;let U=d[J],$={},le=[];return Y.forEach(se=>{let Ee=se[U],pe=`${U}:${Ee}`;$[pe]||($[pe]={key:pe,field:U,value:Ee,children:[],count:0,level:J},le.push($[pe])),$[pe].children.push(se),$[pe].count++;}),le.forEach(se=>{se.children&&(se.children=L(se.children,J+1));}),le},ee=L(E),O=(Y,J="")=>{let U=[];return Y.forEach($=>{if($.children){let le=J?`${J}>${$.key}`:$.key,se=r.has(le);U.push({type:"group",id:le,field:$.field,value:$.value,level:$.level,count:$.count,isExpanded:se,childIds:(function Ee(pe){let Be=[];return pe.children.forEach(Le=>{Le.children?Be=Be.concat(Ee(Le)):Be.push(Le[e.rowKey||"id"]);}),Be})($)}),se&&(U=U.concat(O($.children,le)));}else U.push({type:"row",data:$,id:$[e.rowKey||"id"],level:d.length});}),U};return O(ee)},[d,r,e.rowKey]),ie=useMemo(()=>Me(ke),[ke,Me]),oe=useMemo(()=>w>0?ie.slice(u*w,u*w+w):ie,[ie,u,w]),Oe=h=>{let E=new Set(r);E.has(h)?E.delete(h):E.add(h),b(E);},Et=h=>{Oe(h);},Ge=h=>{let E=new Set(r);Array.from(E).forEach(L=>{L.startsWith(h)&&E.delete(L);}),b(E);},Bt=h=>{h||b(new Set);},Lt=h=>{let E=l===h&&s==="asc",L=l===h&&s==="desc";if(e.onSortChange){E?e.onSortChange(h,"desc"):L?e.onSortChange("","asc"):e.onSortChange(h,"asc");return}E?(a("desc"),n(h)):L?(a("asc"),n("")):(a("asc"),n(h));},We=(h,E)=>{C(L=>({...L,[h]:E}));},nt=h=>{if(h.target.checked){let E=z.map(L=>L[e.rowKey||"id"]);P(E),e.onSelectionChange&&e.onSelectionChange(E);return}P([]),e.onSelectionChange&&e.onSelectionChange([]);},At=(h,E)=>{let L=E[e.rowKey||"id"],ee=x.indexOf(L),O=[];ee===-1?O=O.concat(x,L):ee===0?O=O.concat(x.slice(1)):ee===x.length-1?O=O.concat(x.slice(0,-1)):ee>0&&(O=O.concat(x.slice(0,ee),x.slice(ee+1))),P(O),e.onSelectionChange&&e.onSelectionChange(O);},at=h=>{v(h),e.onPageChange&&e.onPageChange(h);},rt=h=>{S(h),v(0),e.onRowsPerPageChange&&e.onRowsPerPageChange(h);},Ft=h=>{let E=k.indexOf(h),L=[...k];E===-1?L.push(h):L.splice(E,1),m(L);},Vt=h=>{let E=d.indexOf(h),L=[...d];E===-1?L.push(h):L.splice(E,1),I(L);},it=h=>{e.onLayoutSave&&e.onLayoutSave({visibleColumns:k,order:s,orderBy:l,grouping:d,columnWidths:c});},lt=h=>{h.layout&&(h.layout.visibleColumns&&m(h.layout.visibleColumns),h.layout.order&&a(h.layout.order),h.layout.orderBy&&n(h.layout.orderBy),h.layout.grouping&&I(h.layout.grouping),h.layout.columnWidths&&C(h.layout.columnWidths));};useEffect(()=>{e.layout&&lt({layout:e.layout});},[e.layout]);let Nt=h=>{h.preventDefault(),V(A===null?{mouseX:h.clientX+2,mouseY:h.clientY-6}:null);},Ht=()=>{V(null);},zt=useMemo(()=>{if(!g)return {};let h={};e.columns.forEach(L=>{if(L.numeric){let ee=z.reduce((O,Y)=>{let J=parseFloat(Y[L.id]);return O+(isNaN(J)?0:J)},0);h[L.id]=ee.toFixed(2);}else h[L.id]="";});let E=e.columns.find(L=>k.includes(L.id));return E&&!E.numeric&&(h[E.id]="Total"),h},[z,e.columns,g,k]),Ot=()=>{if(!e.columns||!z)return;let h=e.columns.map(Y=>Y.label).join(","),E=z.map(Y=>e.columns.map(J=>{let U=Y[J.id];return `"${(U==null?"":String(U)).replace(/"/g,'""')}"`}).join(",")).join(`
2
+ `),L=`data:text/csv;charset=utf-8,${h}
3
+ ${E}`,ee=encodeURI(L),O=document.createElement("a");O.setAttribute("href",ee),O.setAttribute("download",`${e.title||"export"}.csv`),document.body.appendChild(O),O.click(),document.body.removeChild(O);},st=()=>{H(true);},Gt=()=>{H(false);};return {isMobile:false,columns:e.columns,order:s,orderBy:l,filterText:t,setFilterText:i,visibleColumns:k,setVisibleColumns:m,showSummary:g,setShowSummary:y,summaryColumns:[],grouping:d,setGrouping:I,expandedGroups:r,setExpandedGroups:b,groupAnchorEl:p,setGroupAnchorEl:D,summaryAnchorEl:f,setSummaryAnchorEl:W,columnWidths:c,setColumnWidths:C,anchorEl:M,setAnchorEl:T,contextMenu:A,setContextMenu:V,sensors:void 0,sortedAndFilteredRows:ke,visibleRows:oe,summaryRow:zt,page:u,setPage:at,rowsPerPage:w,setRowsPerPage:rt,selected:x,setSelected:P,isAllExpanded:false,handleColumnResize:We,handleRequestSort:Lt,handleSelectAllClick:nt,handleClick:At,toggleSummaryColumn:()=>{},handleDragEnd:()=>{},handleExport:Ot,handleContextMenu:Nt,handleCloseContextMenu:Ht,toggleColumnVisibility:Ft,toggleGroupExpand:Oe,toggleGroupField:Vt,handleToggleAll:Bt,handleExpandGroupRecursively:Et,handleCollapseGroupRecursively:Ge,handleLayoutLoad:()=>{},handleVariantLoad:lt,handleLayoutSave:it,effectiveAppId:e.appId||"",currentLayoutData:{visibleColumns:k,order:s,orderBy:l,grouping:d,columnWidths:c},currentLayoutId:"",layoutIdToLoad:"",onPageChange:at,onRowsPerPageChange:rt,graphReportOpen:B,handleOpenGraphReport:st,handleCloseGraphReport:Gt}};var Ec=e=>jsx(ai,{...e}),Bc=e=>jsx(Do,{...e}),Lc=e=>jsx(wn,{...e}),Ac=e=>jsx(pa,{...e}),Fc=e=>jsx(ma,{...e}),kt=e=>{let{title:o="Data Table",selectionMode:t,selected:i=[],onSelectionChange:s,actions:a,extraTools:l,fitContainer:n=false,fullWidth:u=false,maxHeight:v,loading:w=false,page:S=0,rowsPerPage:x=20,rowsPerPageOptions:P=[20,50,100,-1],count:k=0,onPageChange:m,onRowsPerPageChange:g,onLayoutSave:y,filterConfig:d,rowKey:I,tableKey:r="default",graphReport:b}=e,{isMobile:c,columns:C,order:M,orderBy:T,filterText:p,setFilterText:D,visibleColumns:f,showSummary:W,setShowSummary:A,summaryColumns:V,grouping:B,setGrouping:H,expandedGroups:z,groupAnchorEl:ke,setGroupAnchorEl:Me,summaryAnchorEl:ie,setSummaryAnchorEl:oe,columnWidths:Oe,anchorEl:Et,setAnchorEl:Ge,contextMenu:Bt,sensors:Lt,sortedAndFilteredRows:We,summaryRow:nt,visibleRows:At,isAllExpanded:at,handleColumnResize:rt,handleRequestSort:Ft,handleSelectAllClick:Vt,handleClick:it,toggleSummaryColumn:lt,handleDragEnd:Nt,handleExport:Ht,handleContextMenu:zt,handleCloseContextMenu:Ot,toggleColumnVisibility:st,toggleGroupExpand:Gt,toggleGroupField:h,handleToggleAll:E,handleExpandGroupRecursively:L,handleCollapseGroupRecursively:ee,handleLayoutLoad:O,handleVariantLoad:Y,handleLayoutSave:J,effectiveAppId:U,currentLayoutData:$,currentLayoutId:le,layoutIdToLoad:se,graphReportOpen:Ee,handleOpenGraphReport:pe,handleCloseGraphReport:Be}=Tn(e),Le=b?.enabled??false,{model:Wt}=Xo({rows:We,config:{...b,title:b?.title||`${o} Graphic Report`}}),Bn=Wt.table.columns.map(ct=>({id:ct.id,label:ct.label,align:ct.align||"left",minWidth:120,numeric:ct.align==="right"})),Ln=U?jsx(Cn,{appId:U,tableKey:r,currentLayoutData:$,onLayoutLoad:O,targetLayoutId:se,activeLayoutId:le,serviceUrl:(d?.variantService,void 0)}):null,ho=jsxs(Fragment,{children:[jsx(Oo,{groupAnchorEl:ke,setGroupAnchorEl:Me,grouping:B,setGrouping:H,columns:C,toggleGroupField:h}),jsx(Go,{anchorEl:Et,setAnchorEl:Ge,columns:C,visibleColumns:f,toggleColumnVisibility:st}),jsx(Wo,{anchorEl:ie,setAnchorEl:oe,showSummary:W,setShowSummary:A,columns:C,summaryColumns:V,toggleSummaryColumn:lt}),jsx($o,{contextMenu:Bt,handleCloseContextMenu:Ot,columns:C,visibleColumns:f,toggleColumnVisibility:st})]});return c?jsxs(mo,{sx:{display:"flex",flexDirection:"column",gap:2,height:"100%"},children:[d&&jsx(qe,{fields:d.fields,filters:d.filters,onFilterChange:d.onFilterChange,onSearch:d.onSearch,variants:d.variants||[],currentVariantId:d.currentVariantId,onVariantLoad:d.onVariantLoad,onVariantSave:d.onVariantSave,onVariantDelete:d.onVariantDelete,onVariantSetDefault:d.onVariantSetDefault,appId:d.appId,tableKey:r,currentLayout:[{tableKey:r,layoutData:$}],variantService:d.variantService}),jsx(Ho,{title:o,loading:w,showSummary:W,setShowSummary:A,setAnchorEl:Ge,setSummaryAnchorEl:oe,filterText:p,setFilterText:D,sortedAndFilteredRows:We,selected:i,columns:C,visibleColumns:f,summaryRow:nt,handleClick:it,selectionMode:t}),ho]}):jsxs(mo,{sx:{width:u?"100%":"auto",mb:n?0:2,...n?{flex:1,display:"flex",flexDirection:"column",minHeight:0,height:"100%"}:{}},children:[d&&jsx(mo,{sx:{mb:2},children:jsx(qe,{fields:d.fields,filters:d.filters,onFilterChange:d.onFilterChange,onSearch:d.onSearch,variants:d.variants||[],currentVariantId:d.currentVariantId,onVariantLoad:Y,onVariantSave:d.onVariantSave,onVariantDelete:d.onVariantDelete,onVariantSetDefault:d.onVariantSetDefault,loading:w,appId:d.appId,tableKey:r,currentLayout:[{tableKey:r,layoutData:$}],currentLayoutId:le,layoutRefs:[{tableKey:r,layoutId:le}],variantService:d.variantService})}),jsxs(oi,{sx:{width:u?"100%":"auto",mb:n?0:2,display:"flex",flexDirection:"column",overflow:"hidden",...v?{height:v}:n?{flex:1,minHeight:0}:{}},children:[jsx(Ro,{filterText:p,setFilterText:D,onRowsPerPageChange:g,rowsPerPage:x,rowsPerPageOptions:P,page:S,count:k,onPageChange:m,actions:a,extraTools:l,grouping:B,setGroupAnchorEl:Me,showSummary:W,setShowSummary:A,setAnchorEl:Ge,setSummaryAnchorEl:oe,handleExport:Ht,onLayoutSave:y||d?.variantService&&d?.appId?J:void 0,loading:w,layoutManager:Ln,onOpenGraphReport:Le?pe:void 0}),jsx(wn,{sx:{flex:1,maxHeight:v||"calc(100vh - 320px)",overflowY:"auto",overflowX:"auto",position:"relative",minHeight:0},children:jsx(DndContext,{sensors:Lt,collisionDetection:closestCenter,onDragEnd:Nt,modifiers:[restrictToHorizontalAxis],children:jsxs(ni,{sx:{minWidth:u?750:"auto",width:u?"100%":"auto",tableLayout:Object.keys(Oe).length>0?"fixed":"auto",borderCollapse:"separate",borderSpacing:0},"aria-labelledby":"tableTitle",size:"small",stickyHeader:true,children:[jsx(Bo,{columns:C,visibleColumns:f,order:M,orderBy:T,onRequestSort:Ft,onContextMenu:zt,selectionMode:t,grouping:B,isAllExpanded:at,handleToggleAll:E,rowCount:We.length,numSelected:i.length,onSelectAllClick:Vt,columnWidths:Oe,onColumnResize:rt}),jsx(Ao,{visibleRows:At,columns:C,visibleColumns:f,selectionMode:t,selected:i,orderBy:T,loading:w,expandedGroups:z,toggleGroupExpand:Gt,handleExpandGroupRecursively:L,handleCollapseGroupRecursively:ee,handleClick:it,onSelectionChange:s,grouping:B,rowKeyProp:I,page:S,rowsPerPage:x}),W&&jsx(Vo,{showSummary:W,columns:C,visibleColumns:f,summaryRow:nt,selectionMode:t?.toString(),orderBy:T,zIndex:3})]})})})]}),ho,Le&&jsx(Yo,{open:Ee,onClose:Be,model:Wt,tableContent:jsx(kt,{title:"Data Body",columns:Bn,rows:Wt.table.rows,rowKey:"id",fullWidth:true,maxHeight:"420px",rowsPerPage:20,rowsPerPageOptions:[20,50,100],graphReport:{enabled:false}})})]})},Vc=kt;var $c=({title:e,hideHeader:o=true,filterConfig:t,tableProps:i,children:s,spacing:a=1})=>jsxs(ko,{title:e,hideHeader:o,children:[jsxs(Stack,{spacing:a,sx:{height:"100%",overflow:"hidden"},children:[t&&jsx(Box,{sx:{flexShrink:0},children:jsx(qe,{...t})}),jsx(Box,{sx:{flex:1,minHeight:0,overflow:"hidden"},children:jsx(kt,{...i,fitContainer:true,filterConfig:void 0})})]}),s]});var Kc=({metadata:e,fetchData:o})=>{let[t,i]=useState(false),[s,a]=useState([]),[l,n]=useState({}),[u,v]=useState(e.variants||[]),[w,S]=useState(e.layout||null),[x,P]=useState(0),[k,m]=useState(0),[g,y]=useState(10),[d,I]=useState([]),[r,b]=useState("asc"),[c,C]=useState("");useEffect(()=>{let B={};e.filters.forEach(H=>{H.defaultValue!==void 0&&(B[H.id]=H.defaultValue);}),n(B);},[e.filters]);let M=useCallback(async(B,H,z,ke,Me)=>{i(true);try{let ie={...B,page:H+1,limit:z,sort:Me,order:ke},oe;o?oe=await o(ie):typeof e.api=="function"?oe=await e.api(ie):e.api&&typeof e.api=="object"?(console.log("Fetching from URL:",e.api.url,ie),oe={rows:[],total:0}):(console.warn("No API configured for report"),oe={rows:[],total:0}),oe&&(a(oe.rows||[]),P(oe.total||0));}catch(ie){console.error("Failed to fetch report data",ie);}finally{i(false);}},[e.api,o]);useEffect(()=>{M(l,k,g,r,c);},[M,k,g,r,c]);let T=()=>{m(0),M(l,0,g,r,c);},p=(B,H)=>{b(H),C(B);},D=B=>{n(B);},f=B=>{if(B.filters){let H=B.filters.find(z=>z.scope==="default"||z.scope===e.id);H&&(n(H.filters),M(H.filters,0,g));}B.layout&&S(B.layout);},W=B=>{let H={...B,id:Date.now().toString(),createdAt:new Date().toISOString()};v(z=>[...z,H]);},A=B=>{S(B);};return {pageProps:{title:e.title,filterConfig:{appId:e.id,fields:e.filters,filters:l,onFilterChange:D,onSearch:T,onVariantLoad:f,onVariantSave:W,onVariantDelete:B=>v(H=>H.filter(z=>z.id!==B)),onVariantSetDefault:B=>{v(H=>H.map(z=>({...z,isDefault:z.id===B})));},variants:u},tableProps:{appId:e.id,columns:e.columns,rows:s,loading:t,rowKey:"id",count:x,page:k,rowsPerPage:g,rowsPerPageOptions:[10,25,50,100],onPageChange:m,onRowsPerPageChange:y,selectionMode:"multiple",selected:d,onSelectionChange:I,onLayoutSave:A,layout:w,title:e.title,showSummary:true,order:r,orderBy:c,onSortChange:p,graphReport:e.graphReport||{enabled:true,title:`${e.title} Graphic Report`}}},filters:l,rows:s,loading:t,refresh:T}};var Rn=64,Mi="#E9EDF2",Ri="linear-gradient(90deg, #F5F7FA 0%, #E9EDF2 50%, #F5F7FA 100%)",Dn=({appTitle:e,logo:o,mode:t="dark",onToggleMode:i,localeLabel:s="EN",searchPlaceholder:a="Ask me...",onSearch:l,user:n,leftSlot:u,rightSlot:v})=>{let S=useTheme().palette.mode==="dark",[x,P]=useState(""),k=y=>{y.preventDefault(),l&&l(x.trim());},m=t==="system"?jsx(wi,{fontSize:"small"}):t==="dark"?jsx(Ii,{fontSize:"small"}):jsx(ki,{fontSize:"small"}),g=t==="system"?"Theme: System":t==="dark"?"Theme: Dark":"Theme: Light";return jsx(AppBar,{position:"sticky",elevation:0,sx:y=>({top:0,zIndex:y.zIndex.drawer+10,height:Rn,backgroundColor:y.palette.mode==="dark"?"#0D0D0D":Mi,backgroundImage:y.palette.mode==="dark"?["radial-gradient(circle at 18% 22%, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0) 45%)","radial-gradient(circle at 78% 32%, rgba(144,202,249,0.14) 0%, rgba(144,202,249,0) 42%)","linear-gradient(90deg, #0A0A0A 0%, #151515 50%, #0A0A0A 100%)","linear-gradient(rgba(255,255,255,0.04) 1px, transparent 1px)","linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px)"].join(","):["radial-gradient(circle at 22% 22%, rgba(255,255,255,0.7) 0%, rgba(255,255,255,0) 48%)","radial-gradient(circle at 76% 24%, rgba(203,213,225,0.45) 0%, rgba(203,213,225,0) 42%)",Ri,"linear-gradient(rgba(15,23,42,0.05) 1px, transparent 1px)","linear-gradient(90deg, rgba(15,23,42,0.04) 1px, transparent 1px)"].join(","),backgroundSize:"auto, auto, auto, 24px 24px, 24px 24px",borderBottom:"1px solid",borderColor:y.palette.mode==="dark"?"rgba(255,255,255,0.12)":"rgba(15,23,42,0.12)"}),children:jsxs(Toolbar,{sx:{minHeight:`${Rn}px !important`,px:2,gap:2},children:[jsxs(Stack,{direction:"row",alignItems:"center",spacing:1.5,sx:{minWidth:220},children:[o||jsx(Box,{component:"img",src:"/orbcafe.png",alt:"ORBCAFE Logo",sx:{width:44,height:44,display:"block",objectFit:"contain",flexShrink:0}}),e&&jsx(Typography,{variant:"h6",sx:{fontWeight:700,color:S?"common.white":"#111827"},children:e}),u]}),jsx(Box,{sx:{flex:1,display:"flex",justifyContent:"center",minWidth:0},children:jsx(Box,{component:"form",onSubmit:k,sx:{width:"100%",maxWidth:540},children:jsx(TextField,{size:"small",fullWidth:true,value:x,onChange:y=>P(y.target.value),placeholder:a,InputProps:{startAdornment:jsx(InputAdornment,{position:"start",children:jsx(cn,{sx:{color:S?"rgba(255,255,255,0.7)":"rgba(15,23,42,0.55)",fontSize:18}})}),sx:{color:S?"common.white":"rgba(17,24,39,0.9)",bgcolor:S?"rgba(255,255,255,0.08)":"#ffffff",borderRadius:999,"& .MuiOutlinedInput-notchedOutline":{borderColor:S?"rgba(255,255,255,0.15)":"rgba(15,23,42,0.2)"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:S?"rgba(255,255,255,0.35)":"rgba(15,23,42,0.35)"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:S?"rgba(255,255,255,0.5)":"rgba(15,23,42,0.55)"}}},inputProps:{style:{color:S?"white":"#111827"}}})})}),jsxs(Stack,{direction:"row",alignItems:"center",spacing:1.5,children:[jsxs(Stack,{direction:"row",alignItems:"center",spacing:.5,children:[jsx(Ti,{sx:{color:S?"common.white":"#111827",fontSize:18}}),jsx(Typography,{variant:"caption",sx:{color:S?"common.white":"#111827",fontWeight:500},children:s})]}),jsx(IconButton,{size:"small",sx:{color:S?"common.white":"#111827"},onClick:i,title:g,children:m}),n&&jsxs(Stack,{direction:"row",alignItems:"center",spacing:1,children:[jsx(Box,{sx:{textAlign:"right"},children:jsx(Typography,{variant:"body2",sx:{color:S?"common.white":"#111827",fontWeight:600,lineHeight:1.2},children:n.name})}),jsx(Avatar,{src:n.avatarSrc,imgProps:{style:{objectFit:"cover"}},sx:{width:34,height:34,bgcolor:"grey.100",color:"grey.700",fontSize:"0.85rem"},children:n.avatarText||n.name.slice(0,1).toUpperCase()})]}),v]})]})})};var Pn=({menuData:e=[],initialNavigationCollapsed:o=false}={})=>{let{navigationIslandProps:t}=Io({initialCollapsed:o,content:e}),[i,s]=useState(900);useEffect(()=>{let l=()=>s(window.innerHeight);return l(),window.addEventListener("resize",l),()=>window.removeEventListener("resize",l)},[]);let a=useMemo(()=>Math.max(280,i-100),[i]);return {navigationIslandProps:t,navigationMaxHeight:a}};var md=({appTitle:e,menuData:o=[],children:t,showNavigation:i=true,localeLabel:s,user:a,logo:l,onSearch:n,rightHeaderSlot:u,leftHeaderSlot:v,contentSx:w})=>{let[S,x]=useState("system"),[P,k]=useState("light"),[m,g]=useState(false),y=S==="system"?m?P:"light":S;useEffect(()=>{g(true);let b=window.matchMedia("(prefers-color-scheme: dark)"),c=()=>{k(b.matches?"dark":"light");};return c(),b.addEventListener("change",c),()=>b.removeEventListener("change",c)},[]);let d=useMemo(()=>createTheme({palette:{mode:y}}),[y]),{navigationIslandProps:I,navigationMaxHeight:r}=Pn({menuData:o,initialNavigationCollapsed:false});return jsx(ThemeProvider,{theme:d,children:jsxs(Box,{sx:b=>({minHeight:"100vh",display:"flex",flexDirection:"column",background:b.palette.mode==="dark"?"linear-gradient(180deg, #0A0A0A 0%, #141414 55%, #1A1A1A 100%)":b.palette.background.default}),children:[jsx(Dn,{appTitle:e,logo:l,mode:S,onToggleMode:()=>x(b=>b==="system"?"dark":b==="dark"?"light":"system"),localeLabel:s,user:a,onSearch:n,leftSlot:v,rightSlot:u}),jsxs(Box,{sx:{flex:1,minHeight:0,display:"flex"},children:[i&&jsx(Box,{sx:{p:1.5,display:"flex",alignItems:"flex-start",flexShrink:0},children:jsx(To,{...I,maxHeight:r,colorMode:y})}),jsx(Box,{sx:{flex:1,minWidth:0,minHeight:0,overflow:"auto",p:1.5,...w},children:t})]})]})})};export{_t as Button,Dn as CAppHeader,md as CAppPageLayout,bn as CLayoutManagement,Cn as CLayoutManager,ko as CPageLayout,qe as CSmartFilter,Vc as CSmartTable,$c as CStandardPage,kt as CTable,Ec as CTableBody,Bc as CTableCell,Lc as CTableContainer,Ac as CTableHead,Fc as CTableRow,bt as CVariantManagement,nn as CVariantManager,To as NavigationIsland,Ut as TreeMenu,Hn as buttonVariants,Io as useNavigationIsland,Pn as usePageLayout,Kc as useStandardReport};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orbcafe-ui",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Awesome UI components with Glassmorphism",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -26,6 +26,11 @@
26
26
  "access": "public"
27
27
  },
28
28
  "peerDependencies": {
29
+ "@emotion/react": "^11.14.0",
30
+ "@emotion/styled": "^11.14.1",
31
+ "@mui/icons-material": "^7.3.8",
32
+ "@mui/material": "^7.3.8",
33
+ "@mui/x-date-pickers": "^8.27.2",
29
34
  "next": "^13.0.0 || ^14.0.0 || ^15.0.0",
30
35
  "react": "^18.0.0 || ^19.0.0",
31
36
  "react-dom": "^18.0.0 || ^19.0.0"
@@ -42,11 +47,6 @@
42
47
  "@dnd-kit/core": "^6.3.1",
43
48
  "@dnd-kit/modifiers": "^9.0.0",
44
49
  "@dnd-kit/sortable": "^10.0.0",
45
- "@emotion/react": "^11.14.0",
46
- "@emotion/styled": "^11.14.1",
47
- "@mui/icons-material": "^7.3.8",
48
- "@mui/material": "^7.3.8",
49
- "@mui/x-date-pickers": "^8.27.2",
50
50
  "@radix-ui/react-slot": "^1.0.0",
51
51
  "class-variance-authority": "^0.7.0",
52
52
  "clsx": "^2.0.0",