@qwickapps/server 1.5.1 → 1.5.2
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/CHANGELOG.md +21 -0
- package/dist/core/control-panel.d.ts.map +1 -1
- package/dist/core/control-panel.js +41 -0
- package/dist/core/control-panel.js.map +1 -1
- package/dist/core/guards.d.ts.map +1 -1
- package/dist/core/guards.js +77 -0
- package/dist/core/guards.js.map +1 -1
- package/dist/core/health-manager.d.ts +4 -0
- package/dist/core/health-manager.d.ts.map +1 -1
- package/dist/core/health-manager.js +6 -1
- package/dist/core/health-manager.js.map +1 -1
- package/dist/core/plugin-registry.d.ts +55 -5
- package/dist/core/plugin-registry.d.ts.map +1 -1
- package/dist/core/plugin-registry.js +57 -19
- package/dist/core/plugin-registry.js.map +1 -1
- package/dist/core/types.d.ts +2 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/plugins/auth/auth-plugin.d.ts.map +1 -1
- package/dist/plugins/auth/auth-plugin.js +16 -0
- package/dist/plugins/auth/auth-plugin.js.map +1 -1
- package/dist/plugins/auth/auth-plugin.test.js +133 -0
- package/dist/plugins/auth/auth-plugin.test.js.map +1 -1
- package/dist/plugins/auth/env-config.d.ts.map +1 -1
- package/dist/plugins/auth/env-config.js +4 -0
- package/dist/plugins/auth/env-config.js.map +1 -1
- package/dist/plugins/auth/types.d.ts +10 -0
- package/dist/plugins/auth/types.d.ts.map +1 -1
- package/dist/plugins/auth/types.js.map +1 -1
- package/dist/plugins/devices/__tests__/token-utils.test.js +4 -2
- package/dist/plugins/devices/__tests__/token-utils.test.js.map +1 -1
- package/dist/plugins/frontend-app-plugin.d.ts.map +1 -1
- package/dist/plugins/frontend-app-plugin.js +18 -4
- package/dist/plugins/frontend-app-plugin.js.map +1 -1
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +2 -0
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/qwickbrain/index.d.ts +25 -0
- package/dist/plugins/qwickbrain/index.d.ts.map +1 -0
- package/dist/plugins/qwickbrain/index.js +24 -0
- package/dist/plugins/qwickbrain/index.js.map +1 -0
- package/dist/plugins/qwickbrain/qwickbrain-plugin.d.ts +23 -0
- package/dist/plugins/qwickbrain/qwickbrain-plugin.d.ts.map +1 -0
- package/dist/plugins/qwickbrain/qwickbrain-plugin.js +528 -0
- package/dist/plugins/qwickbrain/qwickbrain-plugin.js.map +1 -0
- package/dist/plugins/qwickbrain/types.d.ts +131 -0
- package/dist/plugins/qwickbrain/types.d.ts.map +1 -0
- package/dist/plugins/qwickbrain/types.js +9 -0
- package/dist/plugins/qwickbrain/types.js.map +1 -0
- package/dist-ui/assets/{index-CynOqPkb.js → index-BfC7mG5L.js} +2 -2
- package/dist-ui/assets/{index-CynOqPkb.js.map → index-BfC7mG5L.js.map} +1 -1
- package/dist-ui/index.html +1 -1
- package/dist-ui-lib/api/controlPanelApi.d.ts +6 -0
- package/dist-ui-lib/index.js +277 -266
- package/dist-ui-lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/control-panel.ts +47 -0
- package/src/core/guards.ts +89 -0
- package/src/core/health-manager.ts +6 -1
- package/src/core/plugin-registry.ts +123 -25
- package/src/core/types.ts +2 -0
- package/src/index.ts +11 -0
- package/src/plugins/auth/auth-plugin.test.ts +167 -0
- package/src/plugins/auth/auth-plugin.ts +16 -0
- package/src/plugins/auth/env-config.ts +4 -0
- package/src/plugins/auth/types.ts +10 -0
- package/src/plugins/devices/__tests__/token-utils.test.ts +4 -2
- package/src/plugins/frontend-app-plugin.ts +19 -4
- package/src/plugins/index.ts +15 -0
- package/src/plugins/qwickbrain/index.ts +33 -0
- package/src/plugins/qwickbrain/qwickbrain-plugin.ts +642 -0
- package/src/plugins/qwickbrain/types.ts +146 -0
- package/ui/src/api/controlPanelApi.ts +49 -37
|
@@ -461,9 +461,9 @@ Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An err
|
|
|
461
461
|
|
|
462
462
|
**Bold text** and *italic text*.`}),W(),ae(),F("design:type",String)],mc.prototype,"children",void 0);_([z(),D({field_type:B.CHECKBOX,label:"Sanitize HTML",description:"Whether to sanitize HTML output for security"}),W(),Bt(),F("design:type",Boolean)],mc.prototype,"sanitize",void 0);_([z(),D({field_type:B.TEXT,label:"Placeholder",description:"Fallback content to display when Markdown is empty",placeholder:"No content available"}),W(),ae(),F("design:type",String)],mc.prototype,"placeholder",void 0);mc=_([Ft("Markdown","1.0.0")],mc);var bU=mc;const wU=[{selector:"pre",transform:(e,t)=>{var a;const r=e.querySelector("code");if(!r)return null;const o={tagName:"Code",version:"1.0.0",data:{language:((a=Array.from(r.classList).find(c=>c.startsWith("language-")))==null?void 0:a.replace("language-",""))||"text",showCopy:!0,showLineNumbers:!1,children:r.textContent||""}};return l.jsx(ne,{sx:{my:1.5},children:an.deserialize(o)},t)}},{selector:"code",transform:e=>(e.closest("pre"),null)}],SU=e=>({gfm:!0,breaks:!1,pedantic:!1,sanitize:!1,smartypants:!1,renderer:new St.Renderer,...e});function H0({children:e="",htmlTransformConfig:t,sanitize:r=!0,sanitizeOptions:n,placeholder:o,component:a="div",markedOptions:c,...u}){const{styleProps:d,htmlProps:f,restProps:h}=In(u);if(H0[Bn]=!0,!e||!e.trim())return o?l.jsx(ne,{component:a,...f,...d,...h,sx:{opacity:.6,fontStyle:"italic",...d.sx},children:o}):null;try{const v=SU(c),m=St(e,v),y=t||{rules:wU,sanitize:r,sanitizeOptions:n};return l.jsx(No,{transformConfig:y,sanitize:r,sanitizeOptions:n,component:a,...f,...d,...h,children:m})}catch(v){return console.error("Error processing Markdown content:",v),l.jsxs(ne,{component:a,...f,...d,...h,sx:{p:2,border:"1px solid orange",borderRadius:1,backgroundColor:"rgba(255, 165, 0, 0.1)",...d.sx},children:[l.jsx("strong",{children:"Markdown Processing Error:"})," ",v instanceof Error?v.message:"Unknown error",l.jsx(bo,{html:e,placeholder:"Failed to process Markdown"})]})}}class pd extends Js{getComponentSpecificProps(){return{children:this.props.children,sanitize:this.props.sanitize,placeholder:this.props.placeholder}}renderView(){const{...t}=this.props;return l.jsx(H0,{...t})}renderWithDataBinding(){return l.jsx(CU,{...this.props})}static registerPatternHandlers(t){t.hasPattern("div.markdown-content")||t.registerPattern("div.markdown-content",pd.transformMarkdownDiv),t.hasPattern("[data-markdown]")||t.registerPattern("[data-markdown]",pd.transformDataMarkdown)}static transformMarkdownDiv(t){const r=t.getAttribute("data-sanitize")!=="false",n=t.getAttribute("data-placeholder");return{tagName:"Markdown",props:{children:t.textContent||"",sanitize:r,placeholder:n||void 0}}}static transformDataMarkdown(t){const r=t.getAttribute("data-markdown")||t.textContent,n=t.getAttribute("data-sanitize")!=="false",o=t.getAttribute("data-placeholder");return{tagName:"Markdown",props:{children:r,sanitize:n,placeholder:o||void 0}}}}pd.tagName="Markdown";pd.version="1.0.0";function CU(e){const{dataSource:t,bindingOptions:r,...n}=e,{loading:o,error:a,...c}=Fi(t,n,bU.getSchema(),{...r});return o?l.jsx(ne,{sx:{p:2,textAlign:"center",opacity:.6},children:"Loading Markdown content..."}):a?(console.error("Error loading Markdown content:",a),l.jsxs(ne,{sx:{p:2,border:"1px solid orange",borderRadius:1,backgroundColor:"rgba(255, 165, 0, 0.1)"},children:[l.jsx("strong",{children:"Error Loading Markdown:"})," ",a.message]})):l.jsx(H0,{...c})}class EU{constructor(){this.measurements=[],this.isEnabled=!0,this.isEnabled&&this.initializeListeners()}initializeListeners(){typeof window>"u"||(window.addEventListener("theme-changed",t=>{var r;this.measureThemeSwitch("theme",(r=t.detail)==null?void 0:r.theme)}),window.addEventListener("palette-changed",t=>{var r;this.measureThemeSwitch("palette",(r=t.detail)==null?void 0:r.palette)}))}measureThemeSwitch(t,r){if(!this.isEnabled||typeof window>"u"||typeof performance>"u")return;const n=performance.now();requestAnimationFrame(()=>{requestAnimationFrame(()=>{const a=performance.now()-n,c={type:t,value:r,duration:a,timestamp:new Date().toISOString()};this.measurements.push(c),this.measurements.length>50&&this.measurements.shift(),a>100?console.warn(`Slow ${t} switch detected:`,c):console.log(`${t} switch performance:`,`${a.toFixed(2)}ms`)})})}getStatistics(){if(!this.isEnabled||this.measurements.length===0)return null;const t=this.measurements.map(a=>a.duration),r=t.reduce((a,c)=>a+c,0)/t.length,n=Math.min(...t),o=Math.max(...t);return{totalMeasurements:this.measurements.length,averageDuration:r.toFixed(2),minDuration:n.toFixed(2),maxDuration:o.toFixed(2),recentMeasurements:this.measurements.slice(-10)}}logStatistics(){if(!this.isEnabled)return;const t=this.getStatistics();t&&(console.group("Theme Performance Statistics"),console.log("Total measurements:",t.totalMeasurements),console.log("Average duration:",t.averageDuration+"ms"),console.log("Min duration:",t.minDuration+"ms"),console.log("Max duration:",t.maxDuration+"ms"),console.log("Recent measurements:",t.recentMeasurements),console.groupEnd())}reset(){this.measurements=[]}}new EU;var J2;(function(e){e.POST="POST",e.PUT="PUT",e.PATCH="PATCH"})(J2||(J2={}));var Z2;(function(e){e.NAVIGATE="navigate",e.SUBMIT="submit",e.RESET="reset",e.CANCEL="cancel"})(Z2||(Z2={}));class V0{constructor(t){this.app=Object.freeze({...t.app}),this.build=Object.freeze({...t.build}),this.pwa=Object.freeze({...t.pwa}),this.ui=Object.freeze({...t.ui}),this.copyright=Object.freeze({...t.copyright}),Object.freeze(this)}get viteConfig(){return{server:{port:this.build.port,host:!0},preview:{port:this.build.previewPort,host:!0},build:{outDir:this.build.outputDir},base:this.build.base,publicDir:"public",define:{__APP_NAME__:JSON.stringify(this.app.name),__APP_ID__:JSON.stringify(this.app.id),__APP_VERSION__:JSON.stringify(this.app.version)}}}get pwaManifest(){return{name:this.app.name,short_name:this.app.shortName,description:this.app.description,start_url:this.pwa.startUrl,display:this.pwa.display,orientation:this.pwa.orientation,theme_color:this.pwa.themeColor,background_color:this.pwa.backgroundColor,scope:this.pwa.scope,icons:[{src:"pwa-192x192.png",sizes:"192x192",type:"image/png"},{src:"pwa-512x512.png",sizes:"512x512",type:"image/png"}]}}toJSON(){return{app:this.app,build:this.build,pwa:this.pwa,ui:this.ui,copyright:this.copyright}}with(t){return new V0({app:{...this.app,...t.app},build:{...this.build,...t.build},pwa:{...this.pwa,...t.pwa},ui:{...this.ui,...t.ui},copyright:{...this.copyright,...t.copyright}})}}let ju,Pu;try{typeof window>"u"&&typeof process<"u"&&(ju=require("fs"),Pu=require("path"))}catch{}class U0{constructor(){this.config={app:{},build:{},pwa:{},ui:{},copyright:{}},this.options={}}static create(){return new U0}withConfig(t){if(!ju||!Pu)return typeof window>"u"&&console.warn("Warning: File system operations not available in browser environment"),this;try{const r=Pu.resolve(t),n=JSON.parse(ju.readFileSync(r,"utf-8"));n.app&&Object.assign(this.config.app,n.app),n.build&&Object.assign(this.config.build,n.build),n.pwa&&Object.assign(this.config.pwa,n.pwa),n.ui&&Object.assign(this.config.ui,n.ui),n.copyright&&Object.assign(this.config.copyright,n.copyright)}catch{console.warn(`Warning: Could not load config file: ${t}`)}return this}withOptions(t){return this.options={...this.options,...t},this}withName(t){return this.config.app.name=t,this}withId(t){return this.config.app.id=t,this}withShortName(t){return this.config.app.shortName=t,this}withDescription(t){return this.config.app.description=t,this}withVersion(t){return this.config.app.version=t,this}withLogo(t){return this.config.app.logo=t,this}withAuthor(t){return this.config.app.author=t,this}withHomepage(t){return this.config.app.homepage=t,this}withPort(t){return this.config.build.port=t,this}withPreviewPort(t){return this.config.build.previewPort=t,this}withOutputDir(t){return this.config.build.outputDir=t,this}withPublicPath(t){return this.config.build.publicPath=t,this}withBase(t){return this.config.build.base=t,this}withThemeColor(t){return this.config.pwa.themeColor=t,this}withBackgroundColor(t){return this.config.pwa.backgroundColor=t,this}withStartUrl(t){return this.config.pwa.startUrl=t,this}withScope(t){return this.config.pwa.scope=t,this}withDisplay(t){return this.config.pwa.display=t,this}withOrientation(t){return this.config.pwa.orientation=t,this}withDefaultTheme(t){return this.config.ui.defaultTheme=t,this}withDefaultPalette(t){return this.config.ui.defaultPalette=t,this}withScaffolding(t){return this.config.ui.enableScaffolding=t,this}withThemeSwitcher(t){return this.config.ui.showThemeSwitcher=t,this}withPaletteSwitcher(t){return this.config.ui.showPaletteSwitcher=t,this}withCopyright(t,r,n){return this.config.copyright.year=t,this.config.copyright.author=r,n!==void 0&&(this.config.copyright.text=n),this}withCopyrightYear(t){return this.config.copyright.year=t,this}withCopyrightAuthor(t){return this.config.copyright.author=t,this}withCopyrightText(t){return this.config.copyright.text=t,this}build(){const t=this.validate();if(t.warnings.forEach(n=>{console.warn(`⚠️ AppConfig: ${n}`)}),!t.isValid)throw new Error(`AppConfig validation failed:
|
|
463
463
|
${t.errors.map(n=>` - ${n}`).join(`
|
|
464
|
-
`)}`);const r=this.applyDefaults();return new V0(r)}validate(){const t=[],r=[];if(this.config.app.name||r.push("App name is required"),this.config.app.id||r.push("App ID is required"),this.config.copyright.year&&this.config.copyright.year!=="auto"&&(!Number.isInteger(this.config.copyright.year)||this.config.copyright.year<1900)&&t.push('Copyright year should be "auto" or a valid year >= 1900'),this.config.app.logo&&!this.options.skipValidation&&ju&&Pu){const n=Pu.resolve(this.options.baseDir||process.cwd(),this.config.app.logo);ju.existsSync(n)||t.push(`Logo file not found: ${this.config.app.logo} (will use default)`)}return this.config.build.port!==void 0&&(!Number.isInteger(this.config.build.port)||this.config.build.port<1||this.config.build.port>65535)&&r.push("Port must be a valid integer between 1 and 65535"),this.config.build.previewPort!==void 0&&(!Number.isInteger(this.config.build.previewPort)||this.config.build.previewPort<1||this.config.build.previewPort>65535)&&r.push("Preview port must be a valid integer between 1 and 65535"),this.config.pwa.themeColor&&!this.isValidColor(this.config.pwa.themeColor)&&t.push(`Theme color may not be valid: ${this.config.pwa.themeColor}`),this.config.pwa.backgroundColor&&!this.isValidColor(this.config.pwa.backgroundColor)&&t.push(`Background color may not be valid: ${this.config.pwa.backgroundColor}`),{warnings:t,errors:r,isValid:r.length===0}}applyDefaults(){const t={id:this.config.app.id,name:this.config.app.name,shortName:this.config.app.shortName||this.config.app.name,description:this.config.app.description||this.config.app.name,version:this.config.app.version||"1.0.0",logo:this.config.app.logo||"/favicon.ico",author:this.config.app.author,homepage:this.config.app.homepage},r={port:this.config.build.port||3e3,previewPort:this.config.build.previewPort||4173,outputDir:this.config.build.outputDir||"dist",publicPath:this.config.build.publicPath||"/",base:this.config.build.base||"/"},n={themeColor:this.config.pwa.themeColor||"#000000",backgroundColor:this.config.pwa.backgroundColor||"#ffffff",startUrl:this.config.pwa.startUrl||"/",scope:this.config.pwa.scope||"/",display:this.config.pwa.display||"standalone",orientation:this.config.pwa.orientation},o={defaultTheme:this.config.ui.defaultTheme||"light",defaultPalette:this.config.ui.defaultPalette||"default",enableScaffolding:this.config.ui.enableScaffolding??!0,showThemeSwitcher:this.config.ui.showThemeSwitcher??!1,showPaletteSwitcher:this.config.ui.showPaletteSwitcher??!1},a={year:this.config.copyright.year||"auto",author:this.config.copyright.author||t.author||t.name,text:this.config.copyright.text};return{app:t,build:r,pwa:n,ui:o,copyright:a}}isValidColor(t){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t)||/^(black|white|red|green|blue|yellow|orange|purple|pink|gray|grey)$/i.test(t)||/^rgba?\([^)]+\)$/i.test(t)}}let ua=class extends xt{};_([z(),D({field_type:B.TEXT,label:"Field Label",description:"Label/title for the choice input field",placeholder:"Options"}),W(),ae(),F("design:type",String)],ua.prototype,"label",void 0);_([z(),D({field_type:B.TEXTAREA,label:"Options",description:"Array of option values (HTML content supported) - JSON array format"}),W(),dn(),ae({each:!0}),F("design:type",Array)],ua.prototype,"options",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Disabled",description:"Whether the input fields are disabled"}),W(),Bt(),F("design:type",Boolean)],ua.prototype,"disabled",void 0);_([z(),D({field_type:B.TEXT,label:"Placeholder Text",description:"Placeholder text for option inputs",placeholder:"Enter option text. HTML formatting supported."}),W(),ae(),F("design:type",String)],ua.prototype,"placeholder",void 0);_([z(),D({field_type:B.TEXT,label:"Option Label Prefix",description:'Prefix for each option label (e.g., "Option", "Choice")',placeholder:"Option"}),W(),ae(),F("design:type",String)],ua.prototype,"optionLabelPrefix",void 0);_([z({defaultValue:2}),D({field_type:B.NUMBER,label:"Input Rows",description:"Number of rows for each option input field"}),W(),Pr(),F("design:type",Number)],ua.prototype,"rows",void 0);_([z(),D({field_type:B.TEXT,label:"Add Button Text",description:"Text for the add option button",placeholder:"Add Option"}),W(),ae(),F("design:type",String)],ua.prototype,"addButtonText",void 0);ua=_([Ft("ChoiceInputField","1.0.0")],ua);let da=class extends AT{};_([z(),D({field_type:B.TEXTAREA,label:"Content",description:"Raw code text. If provided, React children are ignored in serialization.",placeholder:"Enter code content..."}),W(),ae(),F("design:type",String)],da.prototype,"content",void 0);_([z(),D({field_type:B.TEXT,label:"Language",description:"Programming language for syntax highlighting (e.g., typescript, javascript, python)",placeholder:"javascript"}),W(),ae(),F("design:type",String)],da.prototype,"language",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Show Copy Button",description:"Display a copy-to-clipboard button"}),W(),Bt(),F("design:type",Boolean)],da.prototype,"showCopy",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Show Line Numbers",description:"Display line numbers alongside the code"}),W(),Bt(),F("design:type",Boolean)],da.prototype,"showLineNumbers",void 0);_([z(),D({field_type:B.TEXT,label:"Title",description:"Optional title or filename to display above the code",placeholder:"File name or title"}),W(),ae(),F("design:type",String)],da.prototype,"title",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Wrap Long Lines",description:"Allow long lines to wrap instead of scrolling horizontally"}),W(),Bt(),F("design:type",Boolean)],da.prototype,"wrapLines",void 0);_([z(),D({field_type:B.TEXT,label:"Background Color",description:"Custom background color override",placeholder:"#f5f5f5"}),W(),ae(),F("design:type",String)],da.prototype,"codeBackground",void 0);da=_([Ft("Code","1.0.0")],da);let ro=class extends sa{};_([z(),D({field_type:B.NUMBER,label:"Span",description:"Number of columns to span (1-12)",placeholder:"12"}),W(),Pr(),Ue([1,2,3,4,5,6,7,8,9,10,11,12]),F("design:type",Number)],ro.prototype,"span",void 0);_([z(),D({field_type:B.NUMBER,label:"XS (Mobile)",description:"Columns on extra small screens (1-12)",placeholder:"12"}),W(),Pr(),Ue([1,2,3,4,5,6,7,8,9,10,11,12]),F("design:type",Number)],ro.prototype,"xs",void 0);_([z(),D({field_type:B.NUMBER,label:"SM (Tablet)",description:"Columns on small screens (1-12)",placeholder:"6"}),W(),Pr(),Ue([1,2,3,4,5,6,7,8,9,10,11,12]),F("design:type",Number)],ro.prototype,"sm",void 0);_([z(),D({field_type:B.NUMBER,label:"MD (Desktop)",description:"Columns on medium screens (1-12)",placeholder:"4"}),W(),Pr(),Ue([1,2,3,4,5,6,7,8,9,10,11,12]),F("design:type",Number)],ro.prototype,"md",void 0);_([z(),D({field_type:B.NUMBER,label:"LG (Large Desktop)",description:"Columns on large screens (1-12)",placeholder:"3"}),W(),Pr(),Ue([1,2,3,4,5,6,7,8,9,10,11,12]),F("design:type",Number)],ro.prototype,"lg",void 0);_([z(),D({field_type:B.NUMBER,label:"XL (Extra Large)",description:"Columns on extra large screens (1-12)",placeholder:"2"}),W(),Pr(),Ue([1,2,3,4,5,6,7,8,9,10,11,12]),F("design:type",Number)],ro.prototype,"xl",void 0);_([z(),D({field_type:B.TEXT,label:"Background",description:'Background color or theme color (e.g., "primary.main", "#ffffff")',placeholder:"transparent"}),W(),ae(),F("design:type",String)],ro.prototype,"background",void 0);_([z(),D({field_type:B.TEXT,label:"Padding",description:'Internal spacing (e.g., "medium", "16px", "1rem")',placeholder:"medium"}),W(),ae(),F("design:type",String)],ro.prototype,"padding",void 0);_([z(),D({field_type:B.TEXT,label:"Margin",description:'External spacing (e.g., "small", "8px", "0.5rem")',placeholder:"0"}),W(),ae(),F("design:type",String)],ro.prototype,"margin",void 0);_([z(),D({field_type:B.TEXT,label:"Height",description:'Cell height (e.g., "200px", "medium")',placeholder:"auto"}),W(),ae(),F("design:type",String)],ro.prototype,"height",void 0);_([z(),D({field_type:B.TEXT,label:"Width",description:'Cell width (e.g., "100%", "300px")',placeholder:"100%"}),W(),ae(),F("design:type",String)],ro.prototype,"width",void 0);_([z(),D({field_type:B.TEXT,label:"CSS Class",description:"Additional CSS class names",placeholder:"custom-cell-class"}),W(),ae(),F("design:type",String)],ro.prototype,"className",void 0);ro=_([Ft("GridCell","1.0.0")],ro);let Fo=class extends sa{};_([z(),D({field_type:B.NUMBER,label:"Columns",description:"Number of equal-width columns for auto-distribution"}),W(),Pr(),io(1),F("design:type",Number)],Fo.prototype,"columns",void 0);_([z({defaultValue:"small"}),D({field_type:B.SELECT,label:"Spacing",description:"Spacing between grid items"}),W(),ae(),Ue(["tiny","small","medium","large","huge"]),F("design:type",String)],Fo.prototype,"spacing",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Equal Height",description:"Make all grid items the same height"}),W(),Bt(),F("design:type",Boolean)],Fo.prototype,"equalHeight",void 0);_([z(),D({field_type:B.TEXT,label:"Height",description:'Grid container height (e.g., "400px", "50vh", "medium")',placeholder:"auto"}),W(),ae(),F("design:type",String)],Fo.prototype,"height",void 0);_([z(),D({field_type:B.TEXT,label:"Width",description:'Grid container width (e.g., "100%", "800px", "large")',placeholder:"100%"}),W(),ae(),F("design:type",String)],Fo.prototype,"width",void 0);_([z(),D({field_type:B.TEXT,label:"Min Height",description:"Minimum grid container height",placeholder:"auto"}),W(),ae(),F("design:type",String)],Fo.prototype,"minHeight",void 0);_([z(),D({field_type:B.TEXT,label:"Min Width",description:"Minimum grid container width",placeholder:"auto"}),W(),ae(),F("design:type",String)],Fo.prototype,"minWidth",void 0);_([z(),D({field_type:B.TEXT,label:"Max Height",description:"Maximum grid container height",placeholder:"none"}),W(),ae(),F("design:type",String)],Fo.prototype,"maxHeight",void 0);_([z(),D({field_type:B.TEXT,label:"Max Width",description:"Maximum grid container width",placeholder:"none"}),W(),ae(),F("design:type",String)],Fo.prototype,"maxWidth",void 0);_([z(),D({field_type:B.TEXT,label:"CSS Class",description:"Additional CSS class names",placeholder:"custom-grid-class"}),W(),ae(),F("design:type",String)],Fo.prototype,"className",void 0);Fo=_([Ft("GridLayout","1.0.0")],Fo);let Ho=class extends sa{};_([z(),D({field_type:B.TEXT,label:"Title",description:"Main headline text",placeholder:"Enter hero title..."}),ae(),F("design:type",String)],Ho.prototype,"title",void 0);_([z(),D({field_type:B.TEXT,label:"Subtitle",description:"Subtitle or description text",placeholder:"Enter subtitle..."}),W(),ae(),F("design:type",String)],Ho.prototype,"subtitle",void 0);_([z(),D({field_type:B.IMAGE,label:"Background Image",description:"Background image URL",placeholder:"https://..."}),W(),Ah(),F("design:type",String)],Ho.prototype,"backgroundImage",void 0);_([z(),D({field_type:B.TEXT,label:"Background Gradient",description:"Background gradient CSS value",placeholder:"linear-gradient(...)"}),W(),ae(),F("design:type",String)],Ho.prototype,"backgroundGradient",void 0);_([z({defaultValue:"default"}),D({field_type:B.SELECT,label:"Background Color",description:"Background color theme variant",validation:{options:[{label:"Default",value:"default"},{label:"Primary",value:"primary"},{label:"Secondary",value:"secondary"},{label:"Surface",value:"surface"}]}}),W(),Ue(["default","primary","secondary","surface"]),F("design:type",String)],Ho.prototype,"backgroundColor",void 0);_([z({type:ut.ARRAY}),D({field_type:B.REPEATER,label:"Actions",description:"Action buttons for the hero section"}),W(),dn(),oo({each:!0}),ao(()=>eo),F("design:type",Array)],Ho.prototype,"actions",void 0);_([z({defaultValue:"center"}),D({field_type:B.SELECT,label:"Text Alignment",description:"Text alignment",validation:{options:[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}]}}),W(),Ue(["left","center","right"]),F("design:type",String)],Ho.prototype,"textAlign",void 0);_([z({defaultValue:"medium"}),D({field_type:B.SELECT,label:"Block Height",description:"Block height preset",validation:{options:[{label:"Small",value:"small"},{label:"Medium",value:"medium"},{label:"Large",value:"large"},{label:"Viewport",value:"viewport"}]}}),W(),Ue(["small","medium","large","viewport"]),F("design:type",String)],Ho.prototype,"blockHeight",void 0);_([z(),D({field_type:B.NUMBER,label:"Overlay Opacity",description:"Custom overlay opacity (0-1) when using background images",validation:{min:0,max:1}}),W(),Pr(),io(0),Qs(1),F("design:type",Number)],Ho.prototype,"overlayOpacity",void 0);_([z(),D({field_type:B.TEXT,label:"CSS Class",description:"Additional CSS class name",placeholder:"custom-hero-class"}),W(),ae(),F("design:type",String)],Ho.prototype,"className",void 0);Ho=_([Ft("HeroBlock","1.0.0")],Ho);let tn=class extends xt{};_([z({dataType:ut.STRING}),D({field_type:B.IMAGE,label:"Image Source",description:"Image source URL or path",placeholder:"https://example.com/image.jpg"}),W(),ae(),F("design:type",String)],tn.prototype,"src",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXT,label:"Alt Text",description:"Alternative text for accessibility (required for images with src)",placeholder:"Describe the image for screen readers"}),W(),ae(),F("design:type",String)],tn.prototype,"alt",void 0);_([z({dataType:ut.NUMBER}),D({field_type:B.NUMBER,label:"Width",description:"Image width in pixels (optional)",placeholder:"300"}),W(),Pr(),F("design:type",Number)],tn.prototype,"width",void 0);_([z({dataType:ut.NUMBER}),D({field_type:B.NUMBER,label:"Height",description:"Image height in pixels (optional)",placeholder:"200"}),W(),Pr(),F("design:type",Number)],tn.prototype,"height",void 0);_([z({defaultValue:"cover",dataType:ut.STRING}),D({field_type:B.SELECT,label:"Object Fit",description:"How the image should be resized to fit its container",validation:{options:[{label:"Fill",value:"fill"},{label:"Contain",value:"contain"},{label:"Cover",value:"cover"},{label:"None",value:"none"},{label:"Scale Down",value:"scale-down"}]}}),W(),ae(),Ue(["fill","contain","cover","none","scale-down"]),F("design:type",String)],tn.prototype,"objectFit",void 0);_([z({defaultValue:"center",dataType:ut.STRING}),D({field_type:B.SELECT,label:"Object Position",description:"Position of the image within its container",validation:{options:[{label:"Center",value:"center"},{label:"Top",value:"top"},{label:"Bottom",value:"bottom"},{label:"Left",value:"left"},{label:"Right",value:"right"},{label:"Top Left",value:"top-left"},{label:"Top Right",value:"top-right"},{label:"Bottom Left",value:"bottom-left"},{label:"Bottom Right",value:"bottom-right"}]}}),W(),ae(),Ue(["center","top","bottom","left","right","top-left","top-right","bottom-left","bottom-right"]),F("design:type",String)],tn.prototype,"objectPosition",void 0);_([z({defaultValue:"lazy",dataType:ut.STRING}),D({field_type:B.SELECT,label:"Loading",description:"Image loading behavior",validation:{options:[{label:"Lazy (load when visible)",value:"lazy"},{label:"Eager (load immediately)",value:"eager"}]}}),W(),ae(),Ue(["lazy","eager"]),F("design:type",String)],tn.prototype,"loading",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXT,label:"Title",description:"Image title (tooltip text)",placeholder:"Tooltip text on hover"}),W(),ae(),F("design:type",String)],tn.prototype,"title",void 0);_([z({defaultValue:!1,dataType:ut.BOOLEAN}),D({field_type:B.BOOLEAN,label:"Draggable",description:"Allow the image to be dragged"}),W(),Bt(),F("design:type",Boolean)],tn.prototype,"draggable",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXT,label:"Border Radius",description:'CSS border radius (e.g., "8px", "50%", "1rem")',placeholder:"8px"}),W(),ae(),F("design:type",String)],tn.prototype,"borderRadius",void 0);_([z({defaultValue:!1,dataType:ut.BOOLEAN}),D({field_type:B.BOOLEAN,label:"Show Loading State",description:"Display a loading placeholder while the image loads"}),W(),Bt(),F("design:type",Boolean)],tn.prototype,"showLoading",void 0);_([z({defaultValue:!1,dataType:ut.BOOLEAN}),D({field_type:B.BOOLEAN,label:"Show Error State",description:"Display an error message if the image fails to load"}),W(),Bt(),F("design:type",Boolean)],tn.prototype,"showError",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXT,label:"Fallback Image",description:"Fallback image URL to use if the main image fails to load",placeholder:"https://example.com/fallback.jpg"}),W(),ae(),F("design:type",String)],tn.prototype,"fallbackSrc",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXTAREA,label:"Responsive Sizes",description:"Responsive image sizes attribute for optimized loading",placeholder:"(max-width: 768px) 100vw, 50vw"}),W(),ae(),F("design:type",String)],tn.prototype,"sizes",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXTAREA,label:"Source Set",description:"Source set for responsive images (comma-separated)",placeholder:"image-320w.jpg 320w, image-640w.jpg 640w, image-1280w.jpg 1280w"}),W(),ae(),F("design:type",String)],tn.prototype,"srcSet",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXTAREA,label:"Loading Placeholder",description:"Custom loading placeholder content (for advanced use)",placeholder:"Custom loading content..."}),W(),F("design:type",Object)],tn.prototype,"loadingPlaceholder",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXTAREA,label:"Error Placeholder",description:"Custom error placeholder content (for advanced use)",placeholder:"Custom error content..."}),W(),F("design:type",Object)],tn.prototype,"errorPlaceholder",void 0);tn=_([Ft("Image","1.0.0")],tn);let Gs=class extends sa{};_([z(),D({field_type:B.TEXT,label:"Background Color",description:"Background color (CSS color, theme path, or palette color)",placeholder:"#ffffff or primary.main"}),W(),ae(),F("design:type",String)],Gs.prototype,"background",void 0);_([z(),D({field_type:B.TEXT,label:"Text Color",description:"Text color (CSS color, theme path, or palette color)",placeholder:"#000000 or text.primary"}),W(),ae(),F("design:type",String)],Gs.prototype,"color",void 0);_([z(),D({field_type:B.SELECT,label:"Section Padding",description:"Vertical padding/spacing for the section",validation:{options:[{value:"none",label:"None"},{value:"tiny",label:"Tiny (8px)"},{value:"small",label:"Small (16px)"},{value:"medium",label:"Medium (32px)"},{value:"large",label:"Large (64px)"},{value:"extra-large",label:"Extra Large (96px)"}]}}),W(),Ue(["none","tiny","small","medium","large","extra-large"]),F("design:type",String)],Gs.prototype,"padding",void 0);_([z(),D({field_type:B.SELECT,label:"Content Max Width",description:"Maximum width for the content container",validation:{options:[{value:"xs",label:"Extra Small (444px)"},{value:"sm",label:"Small (600px)"},{value:"md",label:"Medium (900px)"},{value:"lg",label:"Large (1200px)"},{value:"xl",label:"Extra Large (1536px)"},{value:"false",label:"Full Width"}]}}),W(),Ue(["xs","sm","md","lg","xl","false"]),F("design:type",String)],Gs.prototype,"contentMaxWidth",void 0);_([z(),D({field_type:B.SELECT,label:"HTML Element",description:"HTML element type to use for the section",validation:{options:[{value:"section",label:"Section"},{value:"div",label:"Div"},{value:"article",label:"Article"},{value:"main",label:"Main"}]}}),W(),Ue(["section","div","article","main"]),F("design:type",String)],Gs.prototype,"component",void 0);Gs=_([Ft("Section","1.0.0")],Gs);let Eo=class extends xt{};_([z(),D({field_type:B.TEXT,label:"Field Label",description:"The label displayed for the text input field",placeholder:"Enter field label..."}),ae(),F("design:type",String)],Eo.prototype,"label",void 0);_([z(),D({field_type:B.TEXT,label:"Value",description:"Current field value",placeholder:"Enter value..."}),W(),ae(),F("design:type",String)],Eo.prototype,"value",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Required",description:"Whether the field is required"}),W(),Bt(),F("design:type",Boolean)],Eo.prototype,"required",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Disabled",description:"Whether the field is disabled"}),W(),Bt(),F("design:type",Boolean)],Eo.prototype,"disabled",void 0);_([z(),D({field_type:B.TEXT,label:"Error Message",description:"Error message to display if validation fails",placeholder:"Enter error message..."}),W(),ae(),F("design:type",String)],Eo.prototype,"error",void 0);_([z(),D({field_type:B.TEXT,label:"Helper Text",description:"Helper text to guide the user",placeholder:"Enter helper text..."}),W(),ae(),F("design:type",String)],Eo.prototype,"helperText",void 0);_([z(),D({field_type:B.TEXT,label:"Placeholder",description:"Placeholder text shown when field is empty",placeholder:"Enter placeholder text..."}),W(),ae(),F("design:type",String)],Eo.prototype,"placeholder",void 0);_([z(),D({field_type:B.TEXT,label:"Input Type",description:"HTML input type (text, email, number, password, etc.)",placeholder:"text"}),W(),ae(),F("design:type",String)],Eo.prototype,"type",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Multiline",description:"Whether the field supports multiple lines (textarea)"}),W(),Bt(),F("design:type",Boolean)],Eo.prototype,"multiline",void 0);_([z(),D({field_type:B.NUMBER,label:"Rows",description:"Number of rows for multiline fields"}),W(),Pr(),F("design:type",Number)],Eo.prototype,"rows",void 0);_([z(),D({field_type:B.NUMBER,label:"Max Rows",description:"Maximum number of rows for multiline fields"}),W(),Pr(),F("design:type",Number)],Eo.prototype,"maxRows",void 0);Eo=_([Ft("TextInputField","1.0.0")],Eo);let qr=class extends mr{};_([z({dataType:ut.STRING}),D({field_type:B.TEXTAREA,label:"Text Content",description:"The text content to display",placeholder:"Enter your text content here..."}),W(),ae(),F("design:type",String)],qr.prototype,"content",void 0);_([z({defaultValue:"body1",dataType:ut.STRING}),D({field_type:B.SELECT,label:"Typography Variant",description:"Typography variant that determines font size, weight, and line height",validation:{options:[{label:"Heading 1",value:"h1"},{label:"Heading 2",value:"h2"},{label:"Heading 3",value:"h3"},{label:"Heading 4",value:"h4"},{label:"Heading 5",value:"h5"},{label:"Heading 6",value:"h6"},{label:"Subtitle 1",value:"subtitle1"},{label:"Subtitle 2",value:"subtitle2"},{label:"Body 1",value:"body1"},{label:"Body 2",value:"body2"},{label:"Button",value:"button"},{label:"Caption",value:"caption"},{label:"Overline",value:"overline"}]}}),W(),ae(),Ue(["h1","h2","h3","h4","h5","h6","subtitle1","subtitle2","body1","body2","button","caption","overline"]),F("design:type",String)],qr.prototype,"variant",void 0);_([z({defaultValue:"inherit",dataType:ut.STRING}),D({field_type:B.SELECT,label:"Text Color",description:"Color variant for the text",validation:{options:[{label:"Primary",value:"primary"},{label:"Secondary",value:"secondary"},{label:"Text Primary",value:"textPrimary"},{label:"Text Secondary",value:"textSecondary"},{label:"Error",value:"error"},{label:"Warning",value:"warning"},{label:"Info",value:"info"},{label:"Success",value:"success"},{label:"Inherit",value:"inherit"}]}}),W(),ae(),Ue(["primary","secondary","textPrimary","textSecondary","error","warning","info","success","inherit"]),F("design:type",String)],qr.prototype,"color",void 0);_([z({defaultValue:"inherit",dataType:ut.STRING}),D({field_type:B.SELECT,label:"Text Alignment",description:"How to align the text horizontally",validation:{options:[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"},{label:"Justify",value:"justify"},{label:"Inherit",value:"inherit"}]}}),W(),ae(),Ue(["left","center","right","justify","inherit"]),F("design:type",String)],qr.prototype,"align",void 0);_([z({defaultValue:"p",dataType:ut.STRING}),D({field_type:B.SELECT,label:"HTML Element",description:"The HTML element to render (affects semantics and accessibility)",validation:{options:[{label:"Paragraph (p)",value:"p"},{label:"Span",value:"span"},{label:"Div",value:"div"},{label:"Heading 1 (h1)",value:"h1"},{label:"Heading 2 (h2)",value:"h2"},{label:"Heading 3 (h3)",value:"h3"},{label:"Heading 4 (h4)",value:"h4"},{label:"Heading 5 (h5)",value:"h5"},{label:"Heading 6 (h6)",value:"h6"},{label:"Label",value:"label"},{label:"Legend",value:"legend"}]}}),W(),ae(),Ue(["p","span","div","h1","h2","h3","h4","h5","h6","label","legend"]),F("design:type",String)],qr.prototype,"component",void 0);_([z({defaultValue:"inherit",dataType:ut.STRING}),D({field_type:B.SELECT,label:"Font Weight",description:"The weight (thickness) of the font",validation:{options:[{label:"Inherit",value:"inherit"},{label:"Lighter",value:"lighter"},{label:"Normal",value:"normal"},{label:"Bold",value:"bold"},{label:"Bolder",value:"bolder"},{label:"100",value:"100"},{label:"200",value:"200"},{label:"300",value:"300"},{label:"400",value:"400"},{label:"500",value:"500"},{label:"600",value:"600"},{label:"700",value:"700"},{label:"800",value:"800"},{label:"900",value:"900"}]}}),W(),ae(),Ue(["inherit","lighter","normal","bold","bolder","100","200","300","400","500","600","700","800","900"]),F("design:type",String)],qr.prototype,"fontWeight",void 0);_([z({defaultValue:"none",dataType:ut.STRING}),D({field_type:B.SELECT,label:"Text Decoration",description:"Text decoration style",validation:{options:[{label:"None",value:"none"},{label:"Underline",value:"underline"},{label:"Overline",value:"overline"},{label:"Line Through",value:"line-through"}]}}),W(),ae(),Ue(["none","underline","overline","line-through"]),F("design:type",String)],qr.prototype,"textDecoration",void 0);_([z({defaultValue:"none",dataType:ut.STRING}),D({field_type:B.SELECT,label:"Text Transform",description:"How to transform the text case",validation:{options:[{label:"None",value:"none"},{label:"Capitalize",value:"capitalize"},{label:"Uppercase",value:"uppercase"},{label:"Lowercase",value:"lowercase"},{label:"Inherit",value:"inherit"}]}}),W(),ae(),Ue(["none","capitalize","uppercase","lowercase","inherit"]),F("design:type",String)],qr.prototype,"textTransform",void 0);_([z({defaultValue:!1,dataType:ut.BOOLEAN}),D({field_type:B.BOOLEAN,label:"No Wrap",description:"Prevent text from wrapping to multiple lines"}),W(),Bt(),F("design:type",Boolean)],qr.prototype,"noWrap",void 0);_([z({defaultValue:!1,dataType:ut.BOOLEAN}),D({field_type:B.BOOLEAN,label:"Paragraph Mode",description:"Apply paragraph spacing and formatting"}),W(),Bt(),F("design:type",Boolean)],qr.prototype,"paragraph",void 0);_([z({defaultValue:!1,dataType:ut.BOOLEAN}),D({field_type:B.BOOLEAN,label:"Gutter Bottom",description:"Add margin bottom for spacing (useful for headings)"}),W(),Bt(),F("design:type",Boolean)],qr.prototype,"gutterBottom",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXT,label:"Font Size",description:'Custom font size (overrides variant sizing, e.g., "16px", "1.2rem")',placeholder:"16px"}),W(),ae(),F("design:type",String)],qr.prototype,"fontSize",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXT,label:"Line Height",description:'Custom line height (e.g., "1.5", "24px", "150%")',placeholder:"1.5"}),W(),ae(),F("design:type",String)],qr.prototype,"lineHeight",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXT,label:"Letter Spacing",description:'Custom letter spacing (e.g., "0.1em", "1px")',placeholder:"0.1em"}),W(),ae(),F("design:type",String)],qr.prototype,"letterSpacing",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXT,label:"Font Family",description:'Custom font family (e.g., "Arial, sans-serif")',placeholder:"Arial, sans-serif"}),W(),ae(),F("design:type",String)],qr.prototype,"fontFamily",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXTAREA,label:"Custom Color",description:"Custom text color (CSS color value, overrides color variant)",placeholder:"#333333 or rgb(51, 51, 51)"}),W(),ae(),F("design:type",String)],qr.prototype,"customColor",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXTAREA,label:"Max Width",description:'Maximum width for the text (e.g., "300px", "50%")',placeholder:"300px"}),W(),ae(),F("design:type",String)],qr.prototype,"maxWidth",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXTAREA,label:"Rich Content",description:"Rich text content with React elements (for advanced use)",placeholder:"Rich content..."}),W(),F("design:type",Object)],qr.prototype,"children",void 0);qr=_([Ft("Text","1.0.0")],qr);let Gr=class extends mr{};_([z({defaultValue:"light"}),D({field_type:B.SELECT,label:"Print Theme",description:"Theme mode to use when printing",validation:{options:[{label:"Light",value:"light"},{label:"Dark",value:"dark"}]}}),W(),Ue(["light","dark"]),F("design:type",String)],Gr.prototype,"theme",void 0);_([z({defaultValue:"default"}),D({field_type:B.SELECT,label:"Print Palette",description:"Color palette to use for print output",validation:{options:[{label:"Default",value:"default"},{label:"Autumn",value:"autumn"},{label:"Cosmic",value:"cosmic"},{label:"Ocean",value:"ocean"},{label:"Spring",value:"spring"},{label:"Winter",value:"winter"}]}}),W(),ae(),F("design:type",String)],Gr.prototype,"palette",void 0);_([z({defaultValue:!0}),D({field_type:B.BOOLEAN,label:"Hide Scaffolding",description:"Hide app scaffolding (navigation, headers) when printing"}),W(),Bt(),F("design:type",Boolean)],Gr.prototype,"hideScaffolding",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Hide Interactive Elements",description:"Hide buttons and interactive elements when printing"}),W(),Bt(),F("design:type",Boolean)],Gr.prototype,"hideInteractiveElements",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Optimize For Monochrome",description:"Optimize design for black and white printing"}),W(),Bt(),F("design:type",Boolean)],Gr.prototype,"optimizeForMonochrome",void 0);_([z(),D({field_type:B.TEXT,label:"Print Title",description:"Custom title to show when printing (optional)",placeholder:"Document Title"}),W(),ae(),F("design:type",String)],Gr.prototype,"printTitle",void 0);_([z({defaultValue:!0}),D({field_type:B.BOOLEAN,label:"Show Print Date",description:"Include print date and time in printed output"}),W(),Bt(),F("design:type",Boolean)],Gr.prototype,"showPrintDate",void 0);_([z(),D({field_type:B.TEXT,label:"Print Header",description:"Custom header content for printed pages (HTML string or React component)",placeholder:"<div>Custom header content...</div>"}),W(),F("design:type",Object)],Gr.prototype,"printHeader",void 0);_([z(),D({field_type:B.TEXT,label:"Print Header (First Page)",description:"Different header for the first page only (overrides main header on page 1)",placeholder:"<div>First page header...</div>"}),W(),F("design:type",Object)],Gr.prototype,"printHeaderFirstPage",void 0);_([z(),D({field_type:B.TEXT,label:"Print Footer",description:"Custom footer content for printed pages (HTML string or React component)",placeholder:"<div>Custom footer content...</div>"}),W(),F("design:type",Object)],Gr.prototype,"printFooter",void 0);_([z(),D({field_type:B.TEXT,label:"Print Footer (First Page)",description:"Different footer for the first page only (overrides main footer on page 1)",placeholder:"<div>First page footer...</div>"}),W(),F("design:type",Object)],Gr.prototype,"printFooterFirstPage",void 0);_([z({defaultValue:"12mm"}),D({field_type:B.SELECT,label:"Page Margins",description:"Print page margins",validation:{options:[{label:"Compact (6mm)",value:"6mm"},{label:"Standard (12mm)",value:"12mm"},{label:"Large (20mm)",value:"20mm"},{label:"Formal (25mm)",value:"25mm"}]}}),W(),ae(),F("design:type",String)],Gr.prototype,"pageMargins",void 0);_([z({defaultValue:"60px"}),D({field_type:B.TEXT,label:"Print Header Height",description:"Height allocated for print header (CSS units: px, mm, etc.)",placeholder:"60px"}),W(),ae(),F("design:type",String)],Gr.prototype,"printHeaderHeight",void 0);_([z({defaultValue:"40px"}),D({field_type:B.TEXT,label:"Print Footer Height",description:"Height allocated for print footer (CSS units: px, mm, etc.)",placeholder:"40px"}),W(),ae(),F("design:type",String)],Gr.prototype,"printFooterHeight",void 0);_([z(),D({field_type:B.TEXT,label:"Print Background",description:"CSS background for all printed pages (color, gradient, or image)",placeholder:"linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%)"}),W(),ae(),F("design:type",String)],Gr.prototype,"printBackground",void 0);_([z(),D({field_type:B.TEXT,label:"Print Background (First Page)",description:"Different background for the first page only",placeholder:"url(/logo-watermark.png) no-repeat center, #ffffff"}),W(),ae(),F("design:type",String)],Gr.prototype,"printBackgroundFirstPage",void 0);Gr=_([Ft("PrintConfig","1.0.0")],Gr);let un=class extends xt{};_([z(),D({field_type:B.TEXT,label:"Page Slug",description:'URL-friendly page identifier (e.g., "about-us")',placeholder:"page-slug"}),W(),ae(),F("design:type",String)],un.prototype,"slug",void 0);_([z(),D({field_type:B.TEXT,label:"Page Name",description:"Human-readable page name",placeholder:"About Us"}),W(),ae(),F("design:type",String)],un.prototype,"name",void 0);_([z(),D({field_type:B.TEXTAREA,label:"Page Description",description:"Description of the page content (used for SEO)",placeholder:"Brief description of this page..."}),W(),ae(),F("design:type",String)],un.prototype,"description",void 0);_([z(),D({field_type:B.TEXT,label:"Page Title",description:"HTML title tag content (defaults to name if not provided)",placeholder:"Page Title | Site Name"}),W(),ae(),F("design:type",String)],un.prototype,"title",void 0);_([z(),D({field_type:B.TEXTAREA,label:"Meta Keywords",description:"SEO keywords (comma-separated)",placeholder:"keyword1, keyword2, keyword3"}),W(),ae(),F("design:type",String)],un.prototype,"metaKeywords",void 0);_([z(),D({field_type:B.TEXT,label:"Meta Author",description:"Page author information",placeholder:"Author Name"}),W(),ae(),F("design:type",String)],un.prototype,"metaAuthor",void 0);_([z(),D({field_type:B.URL,label:"Canonical URL",description:"Canonical URL for SEO (optional)",placeholder:"https://example.com/page"}),W(),ae(),F("design:type",String)],un.prototype,"canonicalUrl",void 0);_([z(),D({field_type:B.TEXTAREA,label:"Page Content",description:"Main page content - can include React components and HTML"}),W(),F("design:type",Object)],un.prototype,"children",void 0);_([z(),D({field_type:B.FORM,label:"Print Configuration",description:"Configuration for print mode behavior"}),W(),oo(),ao(()=>Gr),F("design:type",Gr)],un.prototype,"printConfig",void 0);_([z(),D({field_type:B.TEXT,label:"Layout Template",description:"Layout template identifier to use for this page",placeholder:"default, fullwidth, sidebar, etc."}),W(),ae(),F("design:type",String)],un.prototype,"layout",void 0);_([z(),D({field_type:B.TEXT,label:"Page Icon",description:"Icon identifier for page (used in navigation)",placeholder:"home, about, contact"}),W(),ae(),F("design:type",String)],un.prototype,"icon",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Requires Authentication",description:"Whether this page requires user authentication"}),W(),F("design:type",Boolean)],un.prototype,"requiresAuth",void 0);_([z(),D({field_type:B.TEXT,label:"Required Roles",description:"Comma-separated list of roles required to access this page",placeholder:"admin, user, moderator"}),W(),ae(),F("design:type",String)],un.prototype,"requiredRoles",void 0);_([z({defaultValue:!0}),D({field_type:B.BOOLEAN,label:"Show in Navigation",description:"Whether to include this page in navigation menus"}),W(),F("design:type",Boolean)],un.prototype,"showInNavigation",void 0);_([z({defaultValue:0}),D({field_type:B.NUMBER,label:"Navigation Priority",description:"Priority in navigation (lower numbers appear first)"}),W(),F("design:type",Number)],un.prototype,"navigationPriority",void 0);_([z({defaultValue:!0}),D({field_type:B.BOOLEAN,label:"Indexable",description:"Whether search engines should index this page"}),W(),F("design:type",Boolean)],un.prototype,"indexable",void 0);un=_([Ft("PageTemplate","1.0.0")],un);const TU=U0.create().withName("Control Panel").withId("com.qwickapps.control-panel").withVersion("1.0.0").withDefaultTheme("dark").withDefaultPalette("cosmic").withThemeSwitcher(!0).withPaletteSwitcher(!0).withDisplay("standalone").build(),lj=b.createContext(null);function kU({initialWidgets:e=[],children:t}){const[r,n]=b.useState(e.map(d=>({...d,visible:d.visible!==!1,priority:d.priority??100}))),o=b.useCallback(d=>{n(f=>f.some(v=>v.id===d.id)?f.map(v=>v.id===d.id?{...d,visible:d.visible!==!1,priority:d.priority??100}:v):[...f,{...d,visible:d.visible!==!1,priority:d.priority??100}])},[]),a=b.useCallback(d=>{n(f=>f.filter(h=>h.id!==d))},[]),c=b.useCallback((d,f)=>{n(h=>h.map(v=>v.id===d?{...v,visible:f??!v.visible}:v))},[]),u=b.useCallback(()=>r.filter(d=>d.visible!==!1).sort((d,f)=>(d.priority??100)-(f.priority??100)),[r]);return l.jsx(lj.Provider,{value:{widgets:r,registerWidget:o,unregisterWidget:a,toggleWidget:c,getVisibleWidgets:u},children:t})}function jU(){const e=b.useContext(lj);if(!e)throw new Error("useDashboardWidgets must be used within a DashboardWidgetProvider");return e}function PU(){const{getVisibleWidgets:e}=jU(),t=e();return t.length===0?null:l.jsx(l.Fragment,{children:t.map(r=>l.jsxs(ne,{sx:{mt:4},children:[r.title&&l.jsx(pe,{variant:"h6",sx:{mb:2,color:"var(--theme-text-primary)"},children:r.title}),r.component]},r.id))})}const cj=b.createContext(null);function IU({initialComponents:e=[],children:t}){const[r,n]=b.useState(()=>{const h=new Map;for(const v of e)h.set(v.name,v.component);return h}),o=b.useCallback((h,v)=>{n(m=>{const y=new Map(m);return y.set(h,v),y})},[]),a=b.useCallback(h=>{n(v=>{const m=new Map(v);for(const y of h)m.set(y.name,y.component);return m})},[]),c=b.useCallback(h=>r.get(h)??null,[r]),u=b.useCallback(h=>r.has(h),[r]),d=b.useCallback(()=>Array.from(r.keys()),[r]),f=b.useMemo(()=>({registerComponent:o,registerComponents:a,getComponent:c,hasComponent:u,getRegisteredNames:d}),[o,a,c,u,d]);return l.jsx(cj.Provider,{value:f,children:t})}function MU(){const e=b.useContext(cj);if(!e)throw new Error("useWidgetComponentRegistry must be used within a WidgetComponentRegistryProvider");return e}class RU{constructor(t=""){ks(this,"baseUrl");this.baseUrl=t}setBaseUrl(t){this.baseUrl=t}getBaseUrl(){return this.baseUrl}async fetch(t,r){const n=`${this.baseUrl}/api${t.startsWith("/")?t:`/${t}`}`,o=await fetch(n,{...r,headers:{"Content-Type":"application/json",...r==null?void 0:r.headers}});if(!o.ok){const a=await o.json().catch(()=>({}));throw new Error(a.error||a.message||`Request failed: ${o.statusText}`)}return o.json()}async detectFeatures(){const[t,r,n]=await Promise.all([this.checkEndpoint("/api/users"),this.checkEndpoint("/api/bans"),this.checkEndpoint("/api/entitlements/available")]);let o=!0;if(n)try{o=(await this.getEntitlementsStatus()).readonly}catch{}return{users:t,bans:r,entitlements:n,entitlementsReadonly:o}}async checkEndpoint(t){try{return(await fetch(`${this.baseUrl}${t}`,{method:"HEAD"})).status!==404}catch{return!1}}async getUsers(t={}){const r=new URLSearchParams;t.limit&&r.set("limit",t.limit.toString()),t.page&&r.set("page",t.page.toString()),t.search&&r.set("q",t.search);const n=await fetch(`${this.baseUrl}/api/users?${r}`);if(!n.ok)throw new Error(`Users request failed: ${n.statusText}`);return n.json()}async getUserById(t){const r=await fetch(`${this.baseUrl}/api/users/${t}`);if(!r.ok)throw new Error(`User request failed: ${r.statusText}`);return r.json()}async getBans(){const t=await fetch(`${this.baseUrl}/api/bans`);if(!t.ok)throw new Error(`Bans request failed: ${t.statusText}`);return t.json()}async banUser(t,r,n){let o;if(n){const c=new Date(n),u=new Date;o=Math.max(0,Math.floor((c.getTime()-u.getTime())/1e3))}const a=await fetch(`${this.baseUrl}/api/bans/email/${encodeURIComponent(t)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:r,duration:o})});if(!a.ok){const c=await a.json().catch(()=>({}));throw new Error(c.error||`Ban request failed: ${a.statusText}`)}}async unbanUser(t){const r=await fetch(`${this.baseUrl}/api/bans/email/${encodeURIComponent(t)}`,{method:"DELETE"});if(!r.ok)throw new Error(`Unban request failed: ${r.statusText}`)}async checkBan(t){const r=await fetch(`${this.baseUrl}/api/bans/email/${encodeURIComponent(t)}`);if(!r.ok)throw new Error(`Ban check failed: ${r.statusText}`);return{banned:(await r.json()).isBanned}}async getEntitlements(t){const r=await fetch(`${this.baseUrl}/api/entitlements/${encodeURIComponent(t)}`);if(!r.ok)throw new Error(`Entitlements request failed: ${r.statusText}`);return r.json()}async refreshEntitlements(t){const r=await fetch(`${this.baseUrl}/api/entitlements/${encodeURIComponent(t)}/refresh`,{method:"POST"});if(!r.ok)throw new Error(`Entitlements refresh failed: ${r.statusText}`);return r.json()}async checkEntitlement(t,r){const n=await fetch(`${this.baseUrl}/api/entitlements/${encodeURIComponent(t)}/check/${encodeURIComponent(r)}`);if(!n.ok)throw new Error(`Entitlement check failed: ${n.statusText}`);return n.json()}async getAvailableEntitlements(){const t=await fetch(`${this.baseUrl}/api/entitlements/available`);if(!t.ok)throw new Error(`Available entitlements request failed: ${t.statusText}`);return(await t.json()).entitlements}async grantEntitlement(t,r){const n=await fetch(`${this.baseUrl}/api/entitlements/${encodeURIComponent(t)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({entitlement:r})});if(!n.ok){const o=await n.json().catch(()=>({}));throw new Error(o.error||`Grant entitlement failed: ${n.statusText}`)}}async revokeEntitlement(t,r){const n=await fetch(`${this.baseUrl}/api/entitlements/${encodeURIComponent(t)}/${encodeURIComponent(r)}`,{method:"DELETE"});if(!n.ok)throw new Error(`Revoke entitlement failed: ${n.statusText}`)}async invalidateEntitlementCache(t){const r=await fetch(`${this.baseUrl}/api/entitlements/cache/${encodeURIComponent(t)}`,{method:"DELETE"});if(!r.ok)throw new Error(`Cache invalidation failed: ${r.statusText}`)}async getEntitlementsStatus(){const t=await fetch(`${this.baseUrl}/api/entitlements/status`);if(!t.ok)throw new Error(`Entitlements status request failed: ${t.statusText}`);return t.json()}async getHealth(){const t=await fetch(`${this.baseUrl}/api/health`);if(!t.ok)throw new Error(`Health check failed: ${t.statusText}`);return t.json()}async getInfo(){const t=await fetch(`${this.baseUrl}/api/info`);if(!t.ok)throw new Error(`Info request failed: ${t.statusText}`);return t.json()}async getDiagnostics(){const t=await fetch(`${this.baseUrl}/api/diagnostics`);if(!t.ok)throw new Error(`Diagnostics request failed: ${t.statusText}`);return t.json()}async getConfig(){const t=await fetch(`${this.baseUrl}/api/config`);if(!t.ok)throw new Error(`Config request failed: ${t.statusText}`);return t.json()}async getLogs(t={}){const r=new URLSearchParams;t.source&&r.set("source",t.source),t.level&&r.set("level",t.level),t.search&&r.set("search",t.search),t.limit&&r.set("limit",t.limit.toString()),t.page&&r.set("page",t.page.toString());const n=await fetch(`${this.baseUrl}/api/logs?${r}`);if(!n.ok)throw new Error(`Logs request failed: ${n.statusText}`);return n.json()}async getLogSources(){const t=await fetch(`${this.baseUrl}/api/logs/sources`);if(!t.ok)throw new Error(`Log sources request failed: ${t.statusText}`);return(await t.json()).sources}async getPlugins(){const t=await fetch(`${this.baseUrl}/api/plugins`);if(!t.ok)throw new Error(`Plugins request failed: ${t.statusText}`);return t.json()}async getPluginDetail(t){const r=await fetch(`${this.baseUrl}/api/plugins/${encodeURIComponent(t)}`);if(!r.ok)throw r.status===404?new Error(`Plugin not found: ${t}`):new Error(`Plugin detail request failed: ${r.statusText}`);return r.json()}async getUiContributions(){const t=await fetch(`${this.baseUrl}/api/ui-contributions`);if(!t.ok)throw new Error(`UI contributions request failed: ${t.statusText}`);return t.json()}async getAuthConfigStatus(){const t=await fetch(`${this.baseUrl}/api/auth/config/status`);if(!t.ok){if(t.status===404)return{state:"disabled",adapter:null};throw new Error(`Auth config status request failed: ${t.statusText}`)}return t.json()}async getAuthConfig(){const t=await fetch(`${this.baseUrl}/api/auth/config`);if(!t.ok){if(t.status===404)return{state:"disabled",adapter:null};throw new Error(`Auth config request failed: ${t.statusText}`)}return t.json()}async updateAuthConfig(t){const r=await fetch(`${this.baseUrl}/api/auth/config`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const n=await r.json().catch(()=>({}));throw new Error(n.error||`Auth config update failed: ${r.statusText}`)}return r.json()}async deleteAuthConfig(){const t=await fetch(`${this.baseUrl}/api/auth/config`,{method:"DELETE"});if(!t.ok){const r=await t.json().catch(()=>({}));throw new Error(r.error||`Auth config delete failed: ${t.statusText}`)}return t.json()}async testAuthProvider(t){const r=await fetch(`${this.baseUrl}/api/auth/test-provider`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const n=await r.json().catch(()=>({}));throw new Error(n.error||`Provider test failed: ${r.statusText}`)}return r.json()}async testCurrentAuthProvider(){const t=await fetch(`${this.baseUrl}/api/auth/test-current`,{method:"POST",headers:{"Content-Type":"application/json"}});if(!t.ok){const r=await t.json().catch(()=>({}));throw new Error(r.error||`Provider test failed: ${t.statusText}`)}return t.json()}async getRateLimitConfig(){const t=await fetch(`${this.baseUrl}/api/rate-limit/config`);if(!t.ok)throw new Error(`Rate limit config request failed: ${t.statusText}`);return t.json()}async updateRateLimitConfig(t){const r=await fetch(`${this.baseUrl}/api/rate-limit/config`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const n=await r.json().catch(()=>({}));throw new Error(n.error||`Rate limit config update failed: ${r.statusText}`)}return r.json()}async getNotificationsStats(){const t=await fetch(`${this.baseUrl}/api/notifications/stats`);if(!t.ok)throw new Error(`Notifications stats request failed: ${t.statusText}`);return t.json()}async getNotificationsClients(){const t=await fetch(`${this.baseUrl}/api/notifications/clients`);if(!t.ok)throw new Error(`Notifications clients request failed: ${t.statusText}`);return t.json()}async disconnectNotificationsClient(t){const r=await fetch(`${this.baseUrl}/api/notifications/clients/${encodeURIComponent(t)}`,{method:"DELETE"});if(!r.ok){const n=await r.json().catch(()=>({}));throw new Error(n.error||`Disconnect client failed: ${r.statusText}`)}return r.json()}async forceNotificationsReconnect(){const t=await fetch(`${this.baseUrl}/api/notifications/reconnect`,{method:"POST"});if(!t.ok){const r=await t.json().catch(()=>({}));throw new Error(r.error||`Force reconnect failed: ${t.statusText}`)}return t.json()}}const At=new RU;function AU({defaultOnly:e=!0,additionalWidgetIds:t=[]}){const[r,n]=b.useState([]),[o,a]=b.useState(!0),[c,u]=b.useState(null),{getComponent:d,hasComponent:f}=MU();if(b.useEffect(()=>{(async()=>{try{const m=await At.getUiContributions();n(m.widgets||[]),u(null)}catch(m){u(m instanceof Error?m.message:"Failed to fetch widgets")}finally{a(!1)}})()},[]),o)return l.jsx(ne,{sx:{display:"flex",justifyContent:"center",py:4},children:l.jsx(cr,{size:24})});if(c)return l.jsx(Kt,{severity:"error",sx:{mt:2},children:c});const h=r.filter(v=>e?v.showByDefault||t.includes(v.id):!0).filter(v=>f(v.component)?!0:(console.warn(`Widget "${v.id}" references unregistered component "${v.component}"`),!1)).sort((v,m)=>(v.priority??100)-(m.priority??100));return h.length===0?null:l.jsx(l.Fragment,{children:h.map(v=>{const m=d(v.component);return l.jsxs(ne,{sx:{mt:4},children:[v.title&&l.jsx(pe,{variant:"h6",sx:{mb:2,color:"var(--theme-text-primary)"},children:v.title}),m&&l.jsx(m,{})]},v.id)})})}function _U(e){switch(e){case"healthy":return l.jsx(Di,{sx:{fontSize:24,color:"var(--theme-success)"}});case"degraded":return l.jsx(ed,{sx:{fontSize:24,color:"var(--theme-warning)"}});case"unhealthy":return l.jsx(Wo,{sx:{fontSize:24,color:"var(--theme-error)"}});default:return l.jsx(ed,{sx:{fontSize:24,color:"var(--theme-text-secondary)"}})}}function eC(e){switch(e){case"healthy":return"var(--theme-success)";case"degraded":return"var(--theme-warning)";case"unhealthy":return"var(--theme-error)";default:return"var(--theme-text-secondary)"}}function LU(e){return e<=1?1:e===2?2:e===3?3:4}function OU(){const[e,t]=b.useState(null),[r,n]=b.useState(null);if(b.useEffect(()=>{const c=async()=>{try{const d=await At.getHealth();t(d),n(null)}catch(d){n(d instanceof Error?d.message:"Failed to fetch health")}};c();const u=setInterval(c,1e4);return()=>clearInterval(u)},[]),r)return l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",border:"1px solid var(--theme-error)"},children:l.jsx(gt,{children:l.jsx(vt,{variant:"body2",customColor:"var(--theme-error)",content:r})})});const o=e?Object.entries(e.checks):[];if(o.length===0)return l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsx(vt,{variant:"body2",customColor:"var(--theme-text-secondary)",content:"No health checks configured"})})});const a=LU(o.length);return l.jsx(kc,{columns:a,spacing:"medium",equalHeight:!0,children:o.map(([c,u])=>l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[_U(u.status),l.jsxs(ne,{sx:{flex:1,minWidth:0},children:[l.jsx(vt,{variant:"body1",fontWeight:"500",content:c.charAt(0).toUpperCase()+c.slice(1),customColor:"var(--theme-text-primary)"}),l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1,mt:.5},children:[l.jsx(qt,{label:u.status,size:"small",sx:{bgcolor:eC(u.status)+"20",color:eC(u.status),fontSize:"0.75rem",height:20}}),u.latency!==void 0&&l.jsx(vt,{variant:"caption",content:`${u.latency}ms`,customColor:"var(--theme-text-secondary)"})]})]})]})})},c))})}function NU(){const[e,t]=b.useState(null),[r,n]=b.useState(!0),[o,a]=b.useState(null);if(b.useEffect(()=>{(async()=>{try{const f=await At.fetch("/ai-proxy/config");t(f)}catch(f){a(f instanceof Error?f.message:"Failed to fetch integrations")}finally{n(!1)}})()},[]),r)return l.jsx(ne,{sx:{display:"flex",justifyContent:"center",py:2},children:l.jsx(cr,{size:20})});if(o)return l.jsx(Kt,{severity:"warning",sx:{py:.5,fontSize:13},children:"Unable to load integrations"});if(!e)return null;const c=e.integrations.filter(d=>d.configured).length,u=e.integrations.length;return l.jsxs(ne,{sx:{bgcolor:"var(--theme-surface)",borderRadius:2,p:2,border:"1px solid var(--theme-border)"},children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[l.jsxs(pe,{variant:"subtitle2",sx:{color:"var(--theme-text-secondary)"},children:[c," of ",u," configured"]}),l.jsxs(pe,{variant:"subtitle2",sx:{color:"var(--theme-text-secondary)"},children:[e.stats.totalRequests," requests"]})]}),l.jsx(ne,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:e.integrations.map(d=>l.jsxs(ne,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",p:1.5,bgcolor:"var(--theme-background)",borderRadius:1},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[d.configured?l.jsx(Di,{sx:{color:"var(--theme-success)",fontSize:18}}):l.jsx(Wo,{sx:{color:"var(--theme-text-secondary)",fontSize:18}}),l.jsxs(ne,{children:[l.jsx(pe,{variant:"body2",sx:{color:"var(--theme-text-primary)",fontWeight:500},children:d.name}),l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:d.description})]})]}),l.jsx(qt,{label:d.configured?"Connected":"Not Configured",size:"small",sx:{bgcolor:d.configured?"var(--theme-success)20":"transparent",color:d.configured?"var(--theme-success)":"var(--theme-text-secondary)",border:d.configured?"none":"1px solid var(--theme-border)",fontWeight:500,fontSize:11}})]},d.id))})]})}const $U={supertokens:"SuperTokens",auth0:"Auth0",supabase:"Supabase",basic:"Basic Auth"};function BU(){const[e,t]=b.useState(null),[r,n]=b.useState(!0),[o,a]=b.useState(null);if(b.useEffect(()=>{(async()=>{try{const f=await At.fetch("/auth/config/status");t(f)}catch(f){a(f instanceof Error?f.message:"Failed to fetch auth status")}finally{n(!1)}})()},[]),r)return l.jsx(ne,{sx:{display:"flex",justifyContent:"center",py:2},children:l.jsx(cr,{size:20})});if(o)return l.jsx(Kt,{severity:"warning",sx:{py:.5,fontSize:13},children:"Unable to load auth status"});if(!e)return null;const c=()=>{switch(e.state){case"enabled":return l.jsx(Di,{sx:{color:"var(--theme-success)",fontSize:32}});case"error":return l.jsx(Wo,{sx:{color:"var(--theme-error)",fontSize:32}});case"disabled":default:return l.jsx(_h,{sx:{color:"var(--theme-text-secondary)",fontSize:32}})}},u=()=>{switch(e.state){case"enabled":return"var(--theme-success)";case"error":return"var(--theme-error)";case"disabled":default:return"var(--theme-text-secondary)"}};return l.jsxs(ne,{sx:{bgcolor:"var(--theme-surface)",borderRadius:2,p:2,border:"1px solid var(--theme-border)"},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[c(),l.jsxs(ne,{sx:{flex:1},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[l.jsx(pe,{variant:"subtitle1",sx:{color:"var(--theme-text-primary)",fontWeight:600},children:e.state==="enabled"&&e.adapter?$U[e.adapter]||e.adapter:e.state==="disabled"?"Not Configured":"Configuration Error"}),l.jsx(qt,{label:e.state.toUpperCase(),size:"small",sx:{bgcolor:`${u()}20`,color:u(),fontWeight:600,fontSize:10,height:20}})]}),l.jsx(pe,{variant:"body2",sx:{color:"var(--theme-text-secondary)"},children:e.state==="enabled"?"Authentication is active":e.state==="disabled"?"Set AUTH_ADAPTER environment variable":e.error||"Check configuration"})]})]}),e.missingVars&&e.missingVars.length>0&&l.jsxs(Kt,{severity:"warning",sx:{mt:2,py:.5,"& .MuiAlert-message":{fontSize:12}},children:["Missing: ",e.missingVars.join(", ")]})]})}function Ha({icon:e,label:t,value:r,subValue:n,color:o="var(--theme-primary)"}){return l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",height:"100%"},children:l.jsx(gt,{sx:{py:1.5,"&:last-child":{pb:1.5}},children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1.5},children:[l.jsx(ne,{sx:{color:o},children:e}),l.jsxs(ne,{sx:{flex:1,minWidth:0},children:[l.jsx(vt,{variant:"h4",content:String(r),customColor:"var(--theme-text-primary)",fontWeight:"600"}),l.jsx(vt,{variant:"caption",content:t,customColor:"var(--theme-text-secondary)"}),n&&l.jsx(vt,{variant:"caption",content:n,customColor:"var(--theme-text-secondary)",sx:{display:"block",mt:.25}})]})]})})})}function Kl(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString()}function xv(e){return e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(0)}s`:e<36e5?`${(e/6e4).toFixed(0)}m`:`${(e/36e5).toFixed(1)}h`}function $l(e,t=12){return e.length>t?`${e.substring(0,t)}...`:e}function zU(){const[e,t]=b.useState(null),[r,n]=b.useState(null),[o,a]=b.useState(!0);if(b.useEffect(()=>{const d=async()=>{try{const h=await At.getNotificationsStats();t(h),n(null)}catch(h){h instanceof Error&&h.message.includes("404")?n("Notifications plugin not enabled"):n(h instanceof Error?h.message:"Failed to fetch stats")}finally{a(!1)}};d();const f=setInterval(d,5e3);return()=>clearInterval(f)},[]),o)return l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsx(Sd,{})})});if(r)return l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",border:"1px solid var(--theme-border)"},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(Hf,{sx:{color:"var(--theme-text-secondary)"}}),l.jsx(vt,{variant:"body2",customColor:"var(--theme-text-secondary)",content:r})]})})});if(!e)return null;const c=e.connectionHealth.isHealthy,u=c?"var(--theme-success)":"var(--theme-warning)";return l.jsxs(ne,{children:[l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:2},children:l.jsx(gt,{sx:{py:1,"&:last-child":{pb:1}},children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[c?l.jsx(ST,{sx:{color:u,fontSize:20}}):l.jsx(Hf,{sx:{color:u,fontSize:20}}),l.jsx(vt,{variant:"body2",content:c?"Connected":"Reconnecting...",customColor:u,fontWeight:"500"}),e.connectionHealth.isReconnecting&&l.jsx(qt,{label:`Attempt ${e.connectionHealth.reconnectAttempts}`,size:"small",sx:{bgcolor:"var(--theme-warning)20",color:"var(--theme-warning)",fontSize:"0.7rem",height:18}})]}),l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[l.jsx(vt,{variant:"caption",content:`${e.channels.length} channel${e.channels.length!==1?"s":""}`,customColor:"var(--theme-text-secondary)"}),e.lastEventAt&&l.jsx(vt,{variant:"caption",content:`Last event: ${xv(e.connectionHealth.timeSinceLastEvent)} ago`,customColor:"var(--theme-text-secondary)"})]})]})})}),l.jsxs(kc,{columns:4,spacing:"small",equalHeight:!0,children:[l.jsx(Ha,{icon:l.jsx(Wy,{sx:{fontSize:28}}),label:"Active Clients",value:e.currentConnections,subValue:`${e.totalConnections} total`,color:"var(--theme-primary)"}),l.jsx(Ha,{icon:l.jsx(ac,{sx:{fontSize:28}}),label:"By Device",value:e.clientsByType.device,subValue:`${e.clientsByType.user} by user`,color:"var(--theme-info)"}),l.jsx(Ha,{icon:l.jsx(p0,{sx:{fontSize:28}}),label:"Events Routed",value:Kl(e.eventsRouted),subValue:`${Kl(e.eventsProcessed)} processed`,color:"var(--theme-success)"}),l.jsx(Ha,{icon:l.jsx(Wo,{sx:{fontSize:28}}),label:"Dropped",value:Kl(e.eventsDroppedNoClients),subValue:`${e.eventsParseFailed} parse errors`,color:e.eventsDroppedNoClients>0?"var(--theme-warning)":"var(--theme-text-secondary)"})]})]})}function DU(){return[{name:"ServiceHealthWidget",component:OU},{name:"IntegrationStatusWidget",component:NU},{name:"AuthStatusWidget",component:BU},{name:"NotificationsStatsWidget",component:zU}]}function FU(e){switch(e){case"healthy":return l.jsx(Di,{sx:{color:"var(--theme-success)"}});case"degraded":return l.jsx(ed,{sx:{color:"var(--theme-warning)"}});case"unhealthy":return l.jsx(Wo,{sx:{color:"var(--theme-error)"}});default:return l.jsx(cr,{size:20})}}function ay(e){switch(e){case"healthy":return"var(--theme-success)";case"degraded":return"var(--theme-warning)";case"unhealthy":return"var(--theme-error)";default:return"var(--theme-text-secondary)"}}function HU(){var m,y;const e=Ev(),[t,r]=b.useState(null),[n,o]=b.useState(null),[a,c]=b.useState(!0),[u,d]=b.useState(null);if(b.useEffect(()=>{const x=async()=>{try{const[C,P]=await Promise.all([At.getHealth(),At.getInfo()]);r(C),o(P),d(null)}catch(C){d(C instanceof Error?C.message:"Failed to fetch data")}finally{c(!1)}};x();const w=setInterval(x,1e4);return()=>clearInterval(w)},[]),a)return l.jsx(ne,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:"50vh"},children:l.jsx(cr,{})});if(u)return l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",border:"1px solid var(--theme-error)"},children:l.jsx(gt,{children:l.jsx(pe,{color:"error",children:u})})});const f=t?Object.entries(t.checks):[],h=f.filter(([,x])=>x.status==="healthy").length,v=f.length;return l.jsxs(ne,{children:[l.jsx(pe,{variant:"h4",sx:{mb:1,color:"var(--theme-text-primary)"},children:"Dashboard"}),l.jsxs(pe,{variant:"body2",sx:{mb:4,color:"var(--theme-text-secondary)"},children:["Real-time overview of ",(n==null?void 0:n.product)||"your service"]}),l.jsx(yt,{sx:{mb:4,bgcolor:"var(--theme-surface)",border:`2px solid ${ay((t==null?void 0:t.status)||"unknown")}`},children:l.jsx(V_,{onClick:()=>e("/health"),children:l.jsxs(gt,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[FU((t==null?void 0:t.status)||"unknown"),l.jsxs(ne,{children:[l.jsxs(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)"},children:["Service Status: ",(m=t==null?void 0:t.status)==null?void 0:m.charAt(0).toUpperCase(),(y=t==null?void 0:t.status)==null?void 0:y.slice(1)]}),l.jsx(pe,{variant:"body2",sx:{color:"var(--theme-text-secondary)"},children:"Click to view detailed health information"})]})]}),l.jsx(qt,{label:`${h}/${v} checks passing`,sx:{bgcolor:ay((t==null?void 0:t.status)||"unknown")+"20",color:ay((t==null?void 0:t.status)||"unknown")}})]})})}),l.jsx(AU,{}),l.jsx(PU,{})]})}function tC(e){switch(e.toLowerCase()){case"error":return"var(--theme-error)";case"warn":case"warning":return"var(--theme-warning)";case"info":return"var(--theme-info)";case"debug":return"var(--theme-text-secondary)";default:return"var(--theme-text-primary)"}}function VU(){const[e,t]=b.useState([]),[r,n]=b.useState([]),[o,a]=b.useState(!0),[c,u]=b.useState(null),[d,f]=b.useState(""),[h,v]=b.useState(""),[m,y]=b.useState(""),[x,w]=b.useState(1),[C,P]=b.useState(0),k=50,[I,T]=b.useState(!1),[M,R]=b.useState("desc"),L=b.useRef(null),A={total:C,errors:e.filter(V=>V.level.toLowerCase()==="error").length,warnings:e.filter(V=>["warn","warning"].includes(V.level.toLowerCase())).length,info:e.filter(V=>V.level.toLowerCase()==="info").length,debug:e.filter(V=>V.level.toLowerCase()==="debug").length},H=b.useCallback(async()=>{a(!0);try{const V=await At.getLogs({source:d||void 0,level:h||void 0,search:m||void 0,limit:k,page:x}),O=[...V.logs].sort((U,K)=>{const Y=new Date(U.timestamp).getTime(),Z=new Date(K.timestamp).getTime();return M==="desc"?Z-Y:Y-Z});t(O),P(V.total),u(null)}catch(V){u(V instanceof Error?V.message:"Failed to fetch logs")}finally{a(!1)}},[d,h,m,x,M]),G=async()=>{try{const V=await At.getLogSources();n(V)}catch{}};b.useEffect(()=>{G()},[]),b.useEffect(()=>{H()},[H]),b.useEffect(()=>(I?L.current=setInterval(H,5e3):L.current&&(clearInterval(L.current),L.current=null),()=>{L.current&&clearInterval(L.current)}),[I,H]);const $=()=>{w(1),H()},j=(V,O)=>{O!==null&&R(O)},q=Math.ceil(C/k);return l.jsxs(ne,{children:[l.jsx(pe,{variant:"h4",sx:{mb:1,color:"var(--theme-text-primary)"},children:"Logs"}),l.jsx(pe,{variant:"body2",sx:{mb:4,color:"var(--theme-text-secondary)"},children:"View and search application logs"}),l.jsxs($n,{container:!0,spacing:2,sx:{mb:3},children:[l.jsx($n,{size:{xs:6,sm:3,md:2.4},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{sx:{py:1.5,px:2,"&:last-child":{pb:1.5}},children:[l.jsx(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:l.jsx(pe,{variant:"h5",sx:{color:"var(--theme-text-primary)",fontWeight:600},children:A.total.toLocaleString()})}),l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:"Total Logs"})]})})}),l.jsx($n,{size:{xs:6,sm:3,md:2.4},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{sx:{py:1.5,px:2,"&:last-child":{pb:1.5}},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(Wo,{sx:{color:"var(--theme-error)",fontSize:20}}),l.jsx(pe,{variant:"h5",sx:{color:"var(--theme-error)",fontWeight:600},children:A.errors})]}),l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:"Errors"})]})})}),l.jsx($n,{size:{xs:6,sm:3,md:2.4},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{sx:{py:1.5,px:2,"&:last-child":{pb:1.5}},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(ed,{sx:{color:"var(--theme-warning)",fontSize:20}}),l.jsx(pe,{variant:"h5",sx:{color:"var(--theme-warning)",fontWeight:600},children:A.warnings})]}),l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:"Warnings"})]})})}),l.jsx($n,{size:{xs:6,sm:3,md:2.4},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{sx:{py:1.5,px:2,"&:last-child":{pb:1.5}},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(Gy,{sx:{color:"var(--theme-info)",fontSize:20}}),l.jsx(pe,{variant:"h5",sx:{color:"var(--theme-info)",fontWeight:600},children:A.info})]}),l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:"Info"})]})})}),l.jsx($n,{size:{xs:6,sm:3,md:2.4},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{sx:{py:1.5,px:2,"&:last-child":{pb:1.5}},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(R7,{sx:{color:"var(--theme-text-secondary)",fontSize:20}}),l.jsx(pe,{variant:"h5",sx:{color:"var(--theme-text-primary)",fontWeight:600},children:A.debug})]}),l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:"Debug"})]})})})]}),l.jsx(yt,{sx:{mb:3,bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",gap:2,flexWrap:"wrap",alignItems:"center"},children:[r.length>0&&l.jsxs(_i,{size:"small",sx:{minWidth:150},children:[l.jsx(Ga,{sx:{color:"var(--theme-text-secondary)"},children:"Source"}),l.jsxs(aa,{value:d,label:"Source",onChange:V=>f(V.target.value),sx:{color:"var(--theme-text-primary)"},children:[l.jsx(Sr,{value:"",children:"All Sources"}),r.map(V=>l.jsx(Sr,{value:V.name,children:V.name},V.name))]})]}),l.jsxs(_i,{size:"small",sx:{minWidth:120},children:[l.jsx(Ga,{sx:{color:"var(--theme-text-secondary)"},children:"Level"}),l.jsxs(aa,{value:h,label:"Level",onChange:V=>v(V.target.value),sx:{color:"var(--theme-text-primary)"},children:[l.jsx(Sr,{value:"",children:"All Levels"}),l.jsx(Sr,{value:"error",children:"Error"}),l.jsx(Sr,{value:"warn",children:"Warning"}),l.jsx(Sr,{value:"info",children:"Info"}),l.jsx(Sr,{value:"debug",children:"Debug"})]})]}),l.jsx(Rt,{size:"small",placeholder:"Search logs...",value:m,onChange:V=>y(V.target.value),onKeyPress:V=>V.key==="Enter"&&$(),sx:{flex:1,minWidth:200,"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}},InputProps:{startAdornment:l.jsx(Oh,{sx:{mr:1,color:"var(--theme-text-secondary)"}})}}),l.jsxs(U8,{value:M,exclusive:!0,onChange:j,size:"small","aria-label":"sort order",children:[l.jsx(bS,{value:"desc","aria-label":"newest first",children:l.jsx(fr,{title:"Newest First",children:l.jsx(P7,{fontSize:"small"})})}),l.jsx(bS,{value:"asc","aria-label":"oldest first",children:l.jsx(fr,{title:"Oldest First",children:l.jsx(I7,{fontSize:"small"})})})]}),l.jsx(fr,{title:I?"Pause auto-refresh":"Enable auto-refresh (5s)",children:l.jsx(Qt,{onClick:()=>T(!I),sx:{color:I?"var(--theme-success)":"var(--theme-text-secondary)",bgcolor:I?"var(--theme-success)20":"transparent"},children:I?l.jsx(pB,{}):l.jsx(sc,{})})}),l.jsx(fr,{title:"Refresh",children:l.jsx(Qt,{onClick:H,sx:{color:"var(--theme-primary)"},children:l.jsx(Ys,{})})})]})})}),c&&l.jsx(yt,{sx:{mb:3,bgcolor:"var(--theme-surface)",border:"1px solid var(--theme-error)"},children:l.jsx(gt,{children:l.jsx(pe,{color:"error",children:c})})}),l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:o?l.jsx(ne,{sx:{display:"flex",justifyContent:"center",p:4},children:l.jsx(cr,{})}):e.length===0?l.jsx(gt,{children:l.jsx(pe,{sx:{color:"var(--theme-text-secondary)",textAlign:"center"},children:"No logs found"})}):l.jsxs(l.Fragment,{children:[l.jsx(Qa,{children:l.jsxs(Xa,{size:"small",children:[l.jsx(Ya,{children:l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)",width:180},children:"Timestamp"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)",width:100},children:"Level"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)",width:120},children:"Component"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Message"})]})}),l.jsx(Ka,{children:e.map((V,O)=>l.jsxs(Ur,{hover:!0,children:[l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)",fontFamily:"monospace",fontSize:"0.75rem"},children:new Date(V.timestamp).toLocaleString()}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:l.jsx(qt,{label:V.level.toUpperCase(),size:"small",sx:{bgcolor:tC(V.level)+"20",color:tC(V.level),fontSize:"0.65rem",height:20}})}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)",fontSize:"0.75rem"},children:V.namespace||"-"}),l.jsx(Ve,{sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)",fontFamily:"monospace",fontSize:"0.8rem",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:V.message})]},O))})]})}),q>1&&l.jsx(ne,{sx:{display:"flex",justifyContent:"center",p:2},children:l.jsx(DN,{count:q,page:x,onChange:(V,O)=>w(O),sx:{"& .MuiPaginationItem-root":{color:"var(--theme-text-primary)"}}})})]})})]})}function sy(e){if(e===0)return"0 B";const t=1024,r=["B","KB","MB","GB"],n=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/Math.pow(t,n)).toFixed(2))+" "+r[n]}function UU(e){const t=Math.floor(e/1e3),r=Math.floor(t/60),n=Math.floor(r/60),o=Math.floor(n/24);return o>0?`${o}d ${n%24}h ${r%60}m`:n>0?`${n}h ${r%60}m ${t%60}s`:r>0?`${r}m ${t%60}s`:`${t}s`}function WU(e,t=20){switch(e){case"healthy":return l.jsx(Di,{sx:{color:"var(--theme-success)",fontSize:t}});case"degraded":return l.jsx(ed,{sx:{color:"var(--theme-warning)",fontSize:t}});case"unhealthy":return l.jsx(Wo,{sx:{color:"var(--theme-error)",fontSize:t}});default:return l.jsx(cr,{size:t})}}function wu(e){switch(e){case"healthy":return"var(--theme-success)";case"degraded":return"var(--theme-warning)";case"unhealthy":return"var(--theme-error)";default:return"var(--theme-text-secondary)"}}function qU(e){return e===void 0?"-":e<1e3?`${e}ms`:`${(e/1e3).toFixed(2)}s`}function GU(){const[e,t]=b.useState(null),[r,n]=b.useState(null),[o,a]=b.useState(!0),[c,u]=b.useState(null),[d,f]=b.useState({open:!1,message:""}),h=async()=>{a(!0);try{const[y,x]=await Promise.all([At.getDiagnostics(),At.getHealth().catch(()=>null)]);t(y),n(x),u(null)}catch(y){u(y instanceof Error?y.message:"Failed to fetch diagnostics")}finally{a(!1)}};b.useEffect(()=>{h();const y=setInterval(h,3e4);return()=>clearInterval(y)},[]);const v=()=>{navigator.clipboard.writeText(JSON.stringify(e,null,2)),f({open:!0,message:"Diagnostics copied to clipboard"})};if(o&&!e)return l.jsx(ne,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:"50vh"},children:l.jsx(cr,{})});if(c)return l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",border:"1px solid var(--theme-error)"},children:l.jsx(gt,{children:l.jsx(pe,{color:"error",children:c})})});const m=e?e.system.memory.used/e.system.memory.total*100:0;return l.jsxs(ne,{children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1},children:[l.jsx(pe,{variant:"h4",sx:{color:"var(--theme-text-primary)"},children:"System"}),l.jsxs(ne,{sx:{display:"flex",gap:1},children:[l.jsx(fr,{title:"Copy diagnostics JSON",children:l.jsx(Qt,{onClick:v,sx:{color:"var(--theme-primary)"},children:l.jsx(u0,{})})}),l.jsx(fr,{title:"Refresh",children:l.jsx(Qt,{onClick:h,sx:{color:"var(--theme-primary)"},children:l.jsx(Ys,{})})})]})]}),l.jsx(pe,{variant:"body2",sx:{mb:4,color:"var(--theme-text-secondary)"},children:"System information and diagnostics"}),l.jsxs($n,{container:!0,spacing:3,children:[l.jsx($n,{size:{xs:12,md:6},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",height:"100%"},children:l.jsxs(gt,{children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1,mb:3},children:[l.jsx(mT,{sx:{color:"var(--theme-primary)"}}),l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)"},children:"System Information"})]}),l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",gap:2},children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between"},children:[l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"QwickApps Server"}),l.jsx(qt,{label:e!=null&&e.frameworkVersion?`v${e.frameworkVersion}`:"N/A",size:"small",sx:{bgcolor:"var(--theme-primary)20",color:"var(--theme-primary)"}})]}),l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between"},children:[l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"Node.js"}),l.jsx(qt,{label:e==null?void 0:e.system.nodeVersion,size:"small",sx:{bgcolor:"var(--theme-background)",color:"var(--theme-text-primary)"}})]}),l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between"},children:[l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"Platform"}),l.jsx(qt,{label:e==null?void 0:e.system.platform,size:"small",sx:{bgcolor:"var(--theme-background)",color:"var(--theme-text-primary)"}})]}),l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between"},children:[l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"Architecture"}),l.jsx(qt,{label:e==null?void 0:e.system.arch,size:"small",sx:{bgcolor:"var(--theme-background)",color:"var(--theme-text-primary)"}})]})]})]})})}),l.jsx($n,{size:{xs:12,md:6},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",height:"100%"},children:l.jsxs(gt,{children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1,mb:3},children:[l.jsx(vT,{sx:{color:"var(--theme-warning)"}}),l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)"},children:"Memory Usage"})]}),l.jsxs(ne,{sx:{mb:2},children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",mb:1},children:[l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"Heap Used"}),l.jsx(pe,{sx:{color:"var(--theme-text-primary)"},children:sy((e==null?void 0:e.system.memory.used)||0)})]}),l.jsx(Sd,{variant:"determinate",value:m,sx:{height:8,borderRadius:4,bgcolor:"var(--theme-background)","& .MuiLinearProgress-bar":{bgcolor:m>80?"var(--theme-error)":"var(--theme-warning)",borderRadius:4}}})]}),l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",gap:2},children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between"},children:[l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"Heap Total"}),l.jsx(pe,{sx:{color:"var(--theme-text-primary)"},children:sy((e==null?void 0:e.system.memory.total)||0)})]}),l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between"},children:[l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"Heap Free"}),l.jsx(pe,{sx:{color:"var(--theme-text-primary)"},children:sy((e==null?void 0:e.system.memory.free)||0)})]})]})]})})}),l.jsx($n,{size:{xs:12,md:6},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",height:"100%"},children:l.jsxs(gt,{children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1,mb:3},children:[l.jsx(f0,{sx:{color:"var(--theme-info)"}}),l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)"},children:"Service Info"})]}),l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",gap:2},children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between"},children:[l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"Product"}),l.jsx(pe,{sx:{color:"var(--theme-text-primary)"},children:e==null?void 0:e.product})]}),l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between"},children:[l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"Version"}),l.jsx(qt,{label:(e==null?void 0:e.version)||"N/A",size:"small",sx:{bgcolor:"var(--theme-primary)20",color:"var(--theme-primary)"}})]}),l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between"},children:[l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"Timestamp"}),l.jsx(pe,{sx:{color:"var(--theme-text-primary)",fontSize:"0.875rem"},children:e!=null&&e.timestamp?new Date(e.timestamp).toLocaleString():"N/A"})]})]})]})})}),l.jsx($n,{size:{xs:12,md:6},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",height:"100%"},children:l.jsxs(gt,{children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1,mb:3},children:[l.jsx(T7,{sx:{color:"var(--theme-success)"}}),l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)"},children:"Uptime"})]}),l.jsx(pe,{variant:"h3",sx:{color:"var(--theme-success)",mb:1},children:UU((e==null?void 0:e.uptime)||0)}),l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"Service has been running without interruption"})]})})}),r&&l.jsx($n,{size:{xs:12},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1,mb:3},children:[l.jsx(qy,{sx:{color:wu(r.status)}}),l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)"},children:"Health Checks"}),l.jsx(qt,{label:r.status,size:"small",sx:{bgcolor:wu(r.status)+"20",color:wu(r.status),textTransform:"capitalize",ml:"auto"}})]}),l.jsx(Qa,{children:l.jsxs(Xa,{size:"small",children:[l.jsx(Ya,{children:l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Check"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Status"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Latency"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Last Checked"})]})}),l.jsx(Ka,{children:Object.entries(r.checks).map(([y,x])=>l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[WU(x.status),l.jsx(pe,{fontWeight:500,children:y})]})}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:l.jsx(qt,{label:x.status,size:"small",sx:{bgcolor:wu(x.status)+"20",color:wu(x.status),textTransform:"capitalize"}})}),l.jsx(Ve,{sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:qU(x.latency)}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:new Date(x.lastChecked).toLocaleTimeString()})]},y))})]})})]})})}),l.jsx($n,{size:{xs:12},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:2},children:"Raw Diagnostics JSON (for AI agents)"}),l.jsx(ne,{component:"pre",sx:{bgcolor:"var(--theme-background)",p:2,borderRadius:1,overflow:"auto",maxHeight:300,color:"var(--theme-text-primary)",fontFamily:"monospace",fontSize:"0.75rem"},children:JSON.stringify(e,null,2)})]})})})]}),l.jsx(XE,{open:d.open,autoHideDuration:2e3,onClose:()=>f({...d,open:!1}),anchorOrigin:{vertical:"bottom",horizontal:"center"},children:l.jsx(Kt,{severity:"success",variant:"filled",children:d.message})})]})}function XU(e){switch(e){case"active":return l.jsx(Di,{sx:{color:"var(--theme-success)",fontSize:20}});case"error":return l.jsx(Wo,{sx:{color:"var(--theme-error)",fontSize:20}});case"starting":return l.jsx(K7,{sx:{color:"var(--theme-warning)",fontSize:20}});case"stopped":return l.jsx(kB,{sx:{color:"var(--theme-text-secondary)",fontSize:20}});default:return null}}function rC(e){switch(e){case"active":return"var(--theme-success)";case"error":return"var(--theme-error)";case"starting":return"var(--theme-warning)";case"stopped":return"var(--theme-text-secondary)";default:return"var(--theme-text-secondary)"}}function KU({counts:e}){const t=[];return e.routes>0&&t.push(`${e.routes} route${e.routes>1?"s":""}`),e.menuItems>0&&t.push(`${e.menuItems} menu item${e.menuItems>1?"s":""}`),e.pages>0&&t.push(`${e.pages} page${e.pages>1?"s":""}`),e.widgets>0&&t.push(`${e.widgets} widget${e.widgets>1?"s":""}`),t.length===0?l.jsx(pe,{sx:{color:"var(--theme-text-secondary)",fontSize:"0.875rem"},children:"No contributions"}):l.jsx(pe,{sx:{color:"var(--theme-text-secondary)",fontSize:"0.875rem"},children:t.join(", ")})}function QU({plugin:e}){const[t,r]=b.useState(!1),[n,o]=b.useState(null),[a,c]=b.useState(!1),[u,d]=b.useState(null),f=async()=>{if(!t&&!n&&!u){c(!0),d(null);try{const v=await At.getPluginDetail(e.id);o(v.contributions)}catch(v){console.error("Failed to load plugin details:",v),d(v instanceof Error?v.message:"Failed to load details")}finally{c(!1)}}r(!t)},h=e.contributionCounts.routes>0||e.contributionCounts.menuItems>0||e.contributionCounts.pages>0||e.contributionCounts.widgets>0;return l.jsxs(l.Fragment,{children:[l.jsxs(Ur,{sx:{"& > *":{borderBottom:t?"none":void 0},cursor:h?"pointer":"default","&:hover":{bgcolor:h?"var(--theme-background)":void 0}},onClick:h?f:void 0,children:[l.jsx(Ve,{sx:{width:50,borderColor:"var(--theme-border)"},children:h&&l.jsx(Qt,{size:"small",sx:{color:"var(--theme-text-secondary)"},children:t?l.jsx(tB,{}):l.jsx(eB,{})})}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[XU(e.status),l.jsx(pe,{sx:{color:"var(--theme-text-primary)",fontWeight:500},children:e.name})]})}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:l.jsx(pe,{sx:{color:"var(--theme-text-secondary)",fontFamily:"monospace",fontSize:"0.875rem"},children:e.id})}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:e.version?l.jsx(qt,{label:`v${e.version}`,size:"small",sx:{bgcolor:"var(--theme-background)",color:"var(--theme-text-primary)"}}):l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"-"})}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:l.jsx(qt,{label:e.status,size:"small",sx:{bgcolor:rC(e.status)+"20",color:rC(e.status),textTransform:"capitalize"}})}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:l.jsx(KU,{counts:e.contributionCounts})})]}),l.jsx(Ur,{children:l.jsx(Ve,{style:{paddingBottom:0,paddingTop:0},colSpan:6,sx:{borderColor:"var(--theme-border)"},children:l.jsx(Xu,{in:t,timeout:"auto",unmountOnExit:!0,children:l.jsx(ne,{sx:{py:2,px:4},children:a?l.jsx(ne,{sx:{display:"flex",justifyContent:"center",py:2},children:l.jsx(cr,{size:24})}):u?l.jsx(Kt,{severity:"error",sx:{mb:1},children:u}):n?l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",gap:2},children:[e.status==="error"&&e.error&&l.jsx(Kt,{severity:"error",sx:{mb:1},children:e.error}),n.routes.length>0&&l.jsxs(ne,{children:[l.jsxs(pe,{variant:"subtitle2",sx:{color:"var(--theme-text-primary)",mb:1},children:["Routes (",n.routes.length,")"]}),l.jsx(ne,{sx:{display:"flex",flexWrap:"wrap",gap:1},children:n.routes.map((v,m)=>l.jsx(qt,{label:`${v.method.toUpperCase()} ${v.path}`,size:"small",sx:{bgcolor:"var(--theme-background)",color:"var(--theme-text-primary)",fontFamily:"monospace",fontSize:"0.75rem"}},m))})]}),n.menuItems.length>0&&l.jsxs(ne,{children:[l.jsxs(pe,{variant:"subtitle2",sx:{color:"var(--theme-text-primary)",mb:1},children:["Menu Items (",n.menuItems.length,")"]}),l.jsx(ne,{sx:{display:"flex",flexWrap:"wrap",gap:1},children:n.menuItems.map(v=>l.jsx(qt,{label:`${v.label} (${v.route})`,size:"small",sx:{bgcolor:"var(--theme-background)",color:"var(--theme-text-primary)"}},v.id))})]}),n.pages.length>0&&l.jsxs(ne,{children:[l.jsxs(pe,{variant:"subtitle2",sx:{color:"var(--theme-text-primary)",mb:1},children:["Pages (",n.pages.length,")"]}),l.jsx(ne,{sx:{display:"flex",flexWrap:"wrap",gap:1},children:n.pages.map(v=>l.jsx(qt,{label:`${v.title||v.id} (${v.route})`,size:"small",sx:{bgcolor:"var(--theme-background)",color:"var(--theme-text-primary)"}},v.id))})]}),n.widgets.length>0&&l.jsxs(ne,{children:[l.jsxs(pe,{variant:"subtitle2",sx:{color:"var(--theme-text-primary)",mb:1},children:["Widgets (",n.widgets.length,")"]}),l.jsx(ne,{sx:{display:"flex",flexWrap:"wrap",gap:1},children:n.widgets.map(v=>l.jsx(qt,{label:v.title,size:"small",sx:{bgcolor:"var(--theme-background)",color:"var(--theme-text-primary)"}},v.id))})]})]}):null})})})})]})}function YU(){const[e,t]=b.useState([]),[r,n]=b.useState(!0),[o,a]=b.useState(null);if(b.useEffect(()=>{(async()=>{try{const f=await At.getPlugins();t(f.plugins),a(null)}catch(f){a(f instanceof Error?f.message:"Failed to fetch plugins")}finally{n(!1)}})()},[]),r)return l.jsx(ne,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:"50vh"},children:l.jsx(cr,{})});if(o)return l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",border:"1px solid var(--theme-error)"},children:l.jsx(gt,{children:l.jsx(pe,{color:"error",children:o})})});const c=e.filter(d=>d.status==="active").length,u=e.filter(d=>d.status==="error").length;return l.jsxs(ne,{children:[l.jsx(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1},children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[l.jsx(pe,{variant:"h4",sx:{color:"var(--theme-text-primary)"},children:"Plugins"}),l.jsx(qt,{icon:l.jsx(V7,{sx:{fontSize:16}}),label:`${c}/${e.length} active`,size:"small",sx:{bgcolor:c===e.length?"var(--theme-success)20":"var(--theme-warning)20",color:c===e.length?"var(--theme-success)":"var(--theme-warning)"}}),u>0&&l.jsx(qt,{icon:l.jsx(Wo,{sx:{fontSize:16}}),label:`${u} error${u>1?"s":""}`,size:"small",sx:{bgcolor:"var(--theme-error)20",color:"var(--theme-error)"}})]})}),l.jsx(pe,{variant:"body2",sx:{mb:4,color:"var(--theme-text-secondary)"},children:"View registered plugins and their contributions to the control panel"}),e.length===0?l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsx(pe,{sx:{color:"var(--theme-text-secondary)",textAlign:"center",py:4},children:"No plugins registered"})})}):l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(Qa,{children:l.jsxs(Xa,{children:[l.jsx(Ya,{children:l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)",width:50}}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Name"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"ID"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Version"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Status"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Contributions"})]})}),l.jsx(Ka,{children:e.map(d=>l.jsx(QU,{plugin:d},d.id))})]})})})]})}function JU({title:e="User Management",subtitle:t="Manage users, bans, and entitlements",features:r,headerActions:n,onUserSelect:o}){const[a,c]=b.useState({users:(r==null?void 0:r.users)??!0,bans:(r==null?void 0:r.bans)??!1,entitlements:(r==null?void 0:r.entitlements)??!1,entitlementsReadonly:(r==null?void 0:r.entitlementsReadonly)??!0}),[u,d]=b.useState(!!r),[f,h]=b.useState(0),[v,m]=b.useState([]),[y,x]=b.useState(0),[w,C]=b.useState(0),[P,k]=b.useState(25),[I,T]=b.useState(""),[M,R]=b.useState({}),[L,A]=b.useState([]),[H,G]=b.useState(0),[$,j]=b.useState(!0),[q,V]=b.useState(null),[O,U]=b.useState(null),[K,Y]=b.useState(!1),[Z,Q]=b.useState({email:"",reason:"",expiresAt:""}),[X,re]=b.useState(!1),[de,J]=b.useState(""),[oe,ee]=b.useState(!1),[he,Ce]=b.useState(!1),[ye,ce]=b.useState(null),[Fe,Le]=b.useState(null),[Ne,$e]=b.useState([]),[Me,Xe]=b.useState(""),[dt,le]=b.useState(!1);b.useEffect(()=>{r||At.detectFeatures().then(ie=>{c(ie),d(!0)}).catch(()=>{d(!0)})},[r]),b.useEffect(()=>{u&&a.entitlements&&!a.entitlementsReadonly&&At.getAvailableEntitlements().then($e).catch(()=>{})},[u,a.entitlements,a.entitlementsReadonly]);const Ye=b.useCallback(async()=>{var ie;if(a.users){j(!0);try{const Pe=await At.getUsers({limit:P,page:w,search:I||void 0});if(m(Pe.users||[]),x(Pe.total),V(null),a.entitlements&&((ie=Pe.users)!=null&&ie.length)){const Be={};await Promise.all(Pe.users.map(async He=>{try{const Et=await At.getEntitlements(He.email);Be[He.email]=Et.entitlements.length}catch{Be[He.email]=0}})),R(He=>({...He,...Be}))}}catch(Pe){V(Pe instanceof Error?Pe.message:"Failed to fetch users")}finally{j(!1)}}},[a.users,a.entitlements,w,P,I]),We=b.useCallback(async()=>{if(a.bans){j(!0);try{const ie=await At.getBans();A(ie.bans||[]),G(ie.total),V(null)}catch(ie){V(ie instanceof Error?ie.message:"Failed to fetch bans")}finally{j(!1)}}},[a.bans]);b.useEffect(()=>{u&&(f===0&&a.users?Ye():f===1&&a.bans&&We())},[f,u,a.users,a.bans,Ye,We]),b.useEffect(()=>{u&&a.bans&&We()},[u,a.bans,We]),b.useEffect(()=>{if(!u)return;const ie=setTimeout(()=>{f===0&&a.users&&(C(0),Ye())},300);return()=>clearTimeout(ie)},[I,f,u,a.users,Ye]);const ft=async()=>{try{await At.banUser(Z.email,Z.reason,Z.expiresAt||void 0),U("User banned successfully"),Y(!1),Q({email:"",reason:"",expiresAt:""}),We()}catch(ie){V(ie instanceof Error?ie.message:"Failed to ban user")}},ze=async ie=>{if(confirm("Unban this user?"))try{await At.unbanUser(ie),U("User unbanned successfully"),We()}catch{V("Failed to unban user")}},Nt=async()=>{if(!de.trim()){Le("Please enter an email address");return}ee(!0),Le(null),ce(null);try{const ie=await At.getEntitlements(de);ce(ie)}catch(ie){Le(ie instanceof Error?ie.message:"Failed to lookup entitlements")}finally{ee(!1)}},ht=async()=>{if(ye){Ce(!0);try{const ie=await At.refreshEntitlements(de);ce(ie)}catch{Le("Failed to refresh entitlements")}finally{Ce(!1)}}},fe=async()=>{if(!(!Me||!ye)){le(!0);try{await At.grantEntitlement(ye.identifier,Me),U(`Entitlement "${Me}" granted`),Xe("");const ie=await At.refreshEntitlements(ye.identifier);ce(ie),R(Pe=>({...Pe,[ye.identifier]:ie.entitlements.length}))}catch(ie){V(ie instanceof Error?ie.message:"Failed to grant entitlement")}finally{le(!1)}}},we=async ie=>{if(ye&&confirm(`Revoke "${ie}" from ${ye.identifier}?`))try{await At.revokeEntitlement(ye.identifier,ie),U(`Entitlement "${ie}" revoked`);const Pe=await At.refreshEntitlements(ye.identifier);ce(Pe),R(Be=>({...Be,[ye.identifier]:Pe.entitlements.length}))}catch(Pe){V(Pe instanceof Error?Pe.message:"Failed to revoke entitlement")}},je=ie=>{ie&&(J(ie),ee(!0),Le(null),ce(null),At.getEntitlements(ie).then(ce).catch(Pe=>Le(Pe instanceof Error?Pe.message:"Failed to lookup entitlements")).finally(()=>ee(!1))),re(!0)},Re=ie=>ie?new Date(ie).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):"Never",qe=Ne.filter(ie=>!(ye!=null&&ye.entitlements.includes(ie.name))),et=[];return a.users&&et.push({label:"Users",count:y}),a.bans&&et.push({label:"Banned",count:H}),u?l.jsxs(ne,{children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[l.jsxs(ne,{children:[l.jsx(vt,{variant:"h4",content:e,customColor:"var(--theme-text-primary)"}),l.jsx(vt,{variant:"body2",content:t,customColor:"var(--theme-text-secondary)"})]}),l.jsxs(ne,{sx:{display:"flex",gap:1},children:[n,a.entitlements&&l.jsx(Nr,{variant:"outlined",icon:"person_search",label:"Lookup Entitlements",onClick:()=>je()}),a.bans&&l.jsx(Nr,{variant:"primary",color:"error",icon:"block",label:"Ban User",onClick:()=>Y(!0)})]})]}),$&&l.jsx(Sd,{sx:{mb:2}}),q&&l.jsx(Kt,{severity:"error",onClose:()=>V(null),sx:{mb:2},children:q}),O&&l.jsx(Kt,{severity:"success",onClose:()=>U(null),sx:{mb:2},children:O}),a.users&&l.jsxs(kc,{columns:a.bans?3:2,spacing:"medium",sx:{mb:3},equalHeight:!0,children:[l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[l.jsx(ac,{sx:{fontSize:40,color:"var(--theme-primary)"}}),l.jsxs(ne,{children:[l.jsx(vt,{variant:"h4",content:y.toLocaleString(),customColor:"var(--theme-text-primary)"}),l.jsx(vt,{variant:"body2",content:"Total Users",customColor:"var(--theme-text-secondary)"})]})]})})}),a.entitlements&&l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[l.jsx(ql,{sx:{fontSize:40,color:"var(--theme-success)"}}),l.jsxs(ne,{children:[l.jsx(vt,{variant:"body1",fontWeight:"500",content:"Entitlements",customColor:"var(--theme-text-primary)"}),l.jsx(vt,{variant:"body2",content:a.entitlementsReadonly?"Read-only Mode":"Plugin Active",customColor:a.entitlementsReadonly?"var(--theme-warning)":"var(--theme-success)"})]})]})})}),a.bans&&l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[l.jsx(_h,{sx:{fontSize:40,color:H>0?"var(--theme-error)":"var(--theme-text-secondary)"}}),l.jsxs(ne,{children:[l.jsx(vt,{variant:"h4",content:H.toString(),customColor:H>0?"var(--theme-error)":"var(--theme-text-primary)"}),l.jsx(vt,{variant:"body2",content:"Banned Users",customColor:"var(--theme-text-secondary)"})]})]})})})]}),l.jsxs(yt,{sx:{bgcolor:"var(--theme-surface)"},children:[et.length>1&&l.jsx(A8,{value:f,onChange:(ie,Pe)=>h(Pe),sx:{borderBottom:1,borderColor:"var(--theme-border)",px:2},children:et.map((ie,Pe)=>l.jsx(P$,{label:`${ie.label}${ie.count!==void 0?` (${ie.count})`:""}`},Pe))}),l.jsxs(gt,{sx:{p:0},children:[l.jsx(ne,{sx:{p:2,borderBottom:1,borderColor:"var(--theme-border)"},children:l.jsx(Rt,{size:"small",placeholder:"Search by email or name...",value:I,onChange:ie=>T(ie.target.value),InputProps:{startAdornment:l.jsx(Bf,{position:"start",children:l.jsx(Oh,{sx:{color:"var(--theme-text-secondary)"}})})},sx:{minWidth:300}})}),f===0&&a.users&&l.jsxs(l.Fragment,{children:[l.jsx(Qa,{children:l.jsxs(Xa,{children:[l.jsx(Ya,{children:l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"ID"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Name"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Email"}),a.entitlements&&l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},align:"center",children:"Entitlements"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Created"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},align:"right",children:"Actions"})]})}),l.jsxs(Ka,{children:[v.map(ie=>l.jsxs(Ur,{hover:!0,sx:{cursor:o?"pointer":"default"},onClick:()=>o==null?void 0:o(ie),children:[l.jsxs(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)",fontFamily:"monospace",fontSize:"0.75rem"},children:[ie.id.substring(0,8),"..."]}),l.jsx(Ve,{sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:l.jsx(vt,{variant:"body1",content:ie.name||"--",fontWeight:"500"})}),l.jsx(Ve,{sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:ie.email}),a.entitlements&&l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},align:"center",children:l.jsx(qt,{size:"small",icon:l.jsx(ql,{sx:{fontSize:14}}),label:M[ie.email]??"...",sx:{bgcolor:"var(--theme-primary)20",color:"var(--theme-primary)"}})}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:Re(ie.created_at)}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},align:"right",children:a.entitlements&&l.jsx(fr,{title:"View entitlements",children:l.jsx(Qt,{size:"small",onClick:Pe=>{Pe.stopPropagation(),je(ie.email)},children:l.jsx(ql,{fontSize:"small"})})})})]},ie.id)),v.length===0&&!$&&l.jsx(Ur,{children:l.jsx(Ve,{colSpan:a.entitlements?6:5,align:"center",sx:{py:4,color:"var(--theme-text-secondary)"},children:I?"No users match your search":"No users found"})})]})]})}),l.jsx(p8,{component:"div",count:y,page:w,onPageChange:(ie,Pe)=>C(Pe),rowsPerPage:P,onRowsPerPageChange:ie=>{k(parseInt(ie.target.value,10)),C(0)},rowsPerPageOptions:[10,25,50,100],sx:{borderTop:1,borderColor:"var(--theme-border)"}})]}),f===1&&a.bans&&l.jsx(Qa,{children:l.jsxs(Xa,{children:[l.jsx(Ya,{children:l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Email"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Reason"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Banned At"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Expires"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Banned By"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},align:"right",children:"Actions"})]})}),l.jsxs(Ka,{children:[L.map(ie=>l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:l.jsx(vt,{variant:"body1",content:ie.email,fontWeight:"500"})}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)",maxWidth:200},children:l.jsx(vt,{variant:"body2",content:ie.reason,noWrap:!0})}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:Re(ie.banned_at)}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:l.jsx(qt,{size:"small",label:ie.expires_at?Re(ie.expires_at):"Permanent",sx:{bgcolor:ie.expires_at?"var(--theme-warning)20":"var(--theme-error)20",color:ie.expires_at?"var(--theme-warning)":"var(--theme-error)"}})}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:ie.banned_by}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},align:"right",children:l.jsx(Nr,{buttonSize:"small",variant:"text",color:"success",icon:"check_circle",label:"Unban",onClick:()=>ze(ie.email)})})]},ie.id)),L.length===0&&!$&&l.jsx(Ur,{children:l.jsx(Ve,{colSpan:6,align:"center",sx:{py:4,color:"var(--theme-text-secondary)"},children:"No users are currently banned"})})]})]})})]})]}),a.bans&&l.jsxs(Nu,{open:K,onClose:()=>Y(!1),maxWidth:"sm",fullWidth:!0,children:[l.jsx($u,{children:"Ban User"}),l.jsx(Bu,{children:l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[l.jsx(Rt,{label:"Email",fullWidth:!0,value:Z.email,onChange:ie=>Q({...Z,email:ie.target.value}),placeholder:"Enter user email"}),l.jsx(Rt,{label:"Reason",fullWidth:!0,multiline:!0,rows:3,value:Z.reason,onChange:ie=>Q({...Z,reason:ie.target.value}),placeholder:"Enter reason for ban"}),l.jsx(Rt,{label:"Expiration (Optional)",type:"datetime-local",fullWidth:!0,value:Z.expiresAt,onChange:ie=>Q({...Z,expiresAt:ie.target.value}),InputLabelProps:{shrink:!0},helperText:"Leave empty for permanent ban"})]})}),l.jsxs(zu,{children:[l.jsx(Nr,{variant:"text",label:"Cancel",onClick:()=>{Y(!1),Q({email:"",reason:"",expiresAt:""})}}),l.jsx(Nr,{variant:"primary",color:"error",label:"Ban User",onClick:ft,disabled:!Z.email||!Z.reason})]})]}),a.entitlements&&l.jsxs(Nu,{open:X,onClose:()=>re(!1),maxWidth:"md",fullWidth:!0,children:[l.jsx($u,{children:"User Entitlements"}),l.jsx(Bu,{children:l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[l.jsxs(ne,{sx:{display:"flex",gap:1},children:[l.jsx(Rt,{label:"Email",fullWidth:!0,value:de,onChange:ie=>J(ie.target.value),placeholder:"Enter user email",onKeyDown:ie=>ie.key==="Enter"&&Nt()}),l.jsx(Nr,{variant:"primary",icon:"search",label:"Lookup",onClick:Nt,disabled:oe})]}),oe&&l.jsx(ne,{sx:{display:"flex",justifyContent:"center",py:4},children:l.jsx(cr,{})}),Fe&&l.jsx(Kt,{severity:"error",children:Fe}),ye&&l.jsxs(ne,{children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[l.jsxs(ne,{children:[l.jsx(vt,{variant:"h6",content:ye.identifier,customColor:"var(--theme-text-primary)"}),l.jsx(vt,{variant:"body2",content:`Source: ${ye.source}`,customColor:"var(--theme-text-secondary)"})]}),l.jsx(Nr,{variant:"outlined",icon:"refresh",label:he?"Refreshing...":"Refresh",onClick:ht,disabled:he,buttonSize:"small"})]}),!a.entitlementsReadonly&&qe.length>0&&l.jsxs(ne,{sx:{display:"flex",gap:1,mb:2,p:2,bgcolor:"var(--theme-background)",borderRadius:1},children:[l.jsx(d_,{size:"small",options:qe,getOptionLabel:ie=>ie.name,value:qe.find(ie=>ie.name===Me)||null,onChange:(ie,Pe)=>Xe((Pe==null?void 0:Pe.name)||""),renderInput:ie=>l.jsx(Rt,{...ie,label:"Grant Entitlement",placeholder:"Select entitlement"}),sx:{flex:1}}),l.jsx(Nr,{variant:"primary",icon:"add",label:"Grant",onClick:fe,disabled:!Me||dt,buttonSize:"small"})]}),l.jsx(vt,{variant:"subtitle2",content:"Current Entitlements",customColor:"var(--theme-text-secondary)",style:{marginBottom:"8px"}}),ye.entitlements.length===0?l.jsx(vt,{variant:"body2",content:"No entitlements found",customColor:"var(--theme-text-secondary)"}):l.jsx(ne,{sx:{display:"flex",flexWrap:"wrap",gap:1},children:ye.entitlements.map((ie,Pe)=>l.jsx(qt,{icon:l.jsx(Di,{sx:{fontSize:16}}),label:ie,onDelete:a.entitlementsReadonly?void 0:()=>we(ie),deleteIcon:l.jsx(Lh,{sx:{fontSize:16}}),sx:{bgcolor:"var(--theme-success)20",color:"var(--theme-success)","& .MuiChip-deleteIcon":{color:"var(--theme-error)","&:hover":{color:"var(--theme-error)"}}}},Pe))}),l.jsxs(ne,{sx:{mt:2,pt:2,borderTop:1,borderColor:"var(--theme-border)"},children:[l.jsx(vt,{variant:"caption",content:`Data from: ${ye.source==="cache"?"Cache":"Source"}`,customColor:"var(--theme-text-secondary)"}),ye.cachedAt&&l.jsx(vt,{variant:"caption",content:` | Cached: ${Re(ye.cachedAt)}`,customColor:"var(--theme-text-secondary)"}),a.entitlementsReadonly&&l.jsx(vt,{variant:"caption",content:" | Read-only mode (modifications disabled)",customColor:"var(--theme-warning)"})]})]})]})}),l.jsx(zu,{children:l.jsx(Nr,{variant:"text",label:"Close",onClick:()=>re(!1)})})]})]}):l.jsx(ne,{sx:{display:"flex",justifyContent:"center",py:8},children:l.jsx(cr,{})})}function ZU({title:e="Entitlements",subtitle:t="Manage available entitlements",headerActions:r}){var de;const[n,o]=b.useState(null),[a,c]=b.useState(!0),[u,d]=b.useState([]),[f,h]=b.useState([]),[v,m]=b.useState(!0),[y,x]=b.useState(null),[w,C]=b.useState(null),[P,k]=b.useState(""),[I,T]=b.useState(!1),[M,R]=b.useState(!1),[L,A]=b.useState(!1),[H,G]=b.useState(null),[$,j]=b.useState({name:"",category:"",description:""}),[q,V]=b.useState(!1);b.useEffect(()=>{At.getEntitlementsStatus().then(o).catch(J=>x(J instanceof Error?J.message:"Failed to get status")).finally(()=>c(!1))},[]);const O=b.useCallback(async()=>{m(!0);try{const J=await At.getAvailableEntitlements();d(J),x(null)}catch(J){x(J instanceof Error?J.message:"Failed to fetch entitlements")}finally{m(!1)}},[]);b.useEffect(()=>{O()},[O]),b.useEffect(()=>{if(!P.trim())h(u);else{const J=P.toLowerCase();h(u.filter(oe=>{var ee,he;return oe.name.toLowerCase().includes(J)||((ee=oe.category)==null?void 0:ee.toLowerCase().includes(J))||((he=oe.description)==null?void 0:he.toLowerCase().includes(J))}))}},[u,P]);const U=[...new Set(u.map(J=>J.category||"Uncategorized"))],K=async()=>{if(!$.name.trim()){x("Name is required");return}V(!0);try{C(`Entitlement "${$.name}" created`),T(!1),j({name:"",category:"",description:""}),O()}catch(J){x(J instanceof Error?J.message:"Failed to create entitlement")}finally{V(!1)}},Y=async()=>{if(H){V(!0);try{C(`Entitlement "${H.name}" updated`),R(!1),G(null),O()}catch(J){x(J instanceof Error?J.message:"Failed to update entitlement")}finally{V(!1)}}},Z=async()=>{if(H){V(!0);try{C(`Entitlement "${H.name}" deleted`),A(!1),G(null),O()}catch(J){x(J instanceof Error?J.message:"Failed to delete entitlement")}finally{V(!1)}}},Q=J=>{G(J),R(!0)},X=J=>{G(J),A(!0)},re=(n==null?void 0:n.readonly)??!0;return a?l.jsx(ne,{sx:{display:"flex",justifyContent:"center",py:8},children:l.jsx(cr,{})}):l.jsxs(ne,{children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[l.jsxs(ne,{children:[l.jsx(vt,{variant:"h4",content:e,customColor:"var(--theme-text-primary)"}),l.jsx(vt,{variant:"body2",content:t,customColor:"var(--theme-text-secondary)"})]}),l.jsxs(ne,{sx:{display:"flex",gap:1},children:[r,!re&&l.jsx(Nr,{variant:"primary",icon:"add",label:"Add Entitlement",onClick:()=>T(!0)})]})]}),v&&l.jsx(Sd,{sx:{mb:2}}),y&&l.jsx(Kt,{severity:"error",onClose:()=>x(null),sx:{mb:2},children:y}),w&&l.jsx(Kt,{severity:"success",onClose:()=>C(null),sx:{mb:2},children:w}),l.jsxs(kc,{columns:3,spacing:"medium",sx:{mb:3},equalHeight:!0,children:[l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[l.jsx(ql,{sx:{fontSize:40,color:"var(--theme-primary)"}}),l.jsxs(ne,{children:[l.jsx(vt,{variant:"h4",content:u.length.toString(),customColor:"var(--theme-text-primary)"}),l.jsx(vt,{variant:"body2",content:"Total Entitlements",customColor:"var(--theme-text-secondary)"})]})]})})}),l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[l.jsx(ne,{sx:{width:40,height:40,borderRadius:1,bgcolor:"var(--theme-primary)20",display:"flex",alignItems:"center",justifyContent:"center"},children:l.jsx(vt,{variant:"h6",content:U.length.toString(),customColor:"var(--theme-primary)"})}),l.jsxs(ne,{children:[l.jsx(vt,{variant:"body1",fontWeight:"500",content:"Categories",customColor:"var(--theme-text-primary)"}),l.jsx(vt,{variant:"body2",content:U.slice(0,3).join(", "),customColor:"var(--theme-text-secondary)"})]})]})})}),l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[re?l.jsx(Xy,{sx:{fontSize:40,color:"var(--theme-warning)"}}):l.jsx(Ff,{sx:{fontSize:40,color:"var(--theme-success)"}}),l.jsxs(ne,{children:[l.jsx(vt,{variant:"body1",fontWeight:"500",content:re?"Read-only":"Editable",customColor:re?"var(--theme-warning)":"var(--theme-success)"}),l.jsx(vt,{variant:"body2",content:`Source: ${((de=n==null?void 0:n.sources[0])==null?void 0:de.name)||"Unknown"}`,customColor:"var(--theme-text-secondary)"})]})]})})})]}),l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{sx:{p:0},children:[l.jsx(ne,{sx:{p:2,borderBottom:1,borderColor:"var(--theme-border)"},children:l.jsx(Rt,{size:"small",placeholder:"Search entitlements...",value:P,onChange:J=>k(J.target.value),InputProps:{startAdornment:l.jsx(Bf,{position:"start",children:l.jsx(Oh,{sx:{color:"var(--theme-text-secondary)"}})})},sx:{minWidth:300}})}),l.jsx(Qa,{children:l.jsxs(Xa,{children:[l.jsx(Ya,{children:l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Name"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Category"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Description"}),!re&&l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},align:"right",children:"Actions"})]})}),l.jsxs(Ka,{children:[f.map(J=>l.jsxs(Ur,{hover:!0,children:[l.jsx(Ve,{sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(ql,{sx:{fontSize:18,color:"var(--theme-primary)"}}),l.jsx(vt,{variant:"body1",content:J.name,fontWeight:"500"})]})}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:J.category?l.jsx(qt,{size:"small",label:J.category,sx:{bgcolor:"var(--theme-primary)20",color:"var(--theme-primary)"}}):l.jsx(vt,{variant:"body2",content:"--",customColor:"var(--theme-text-secondary)"})}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)",maxWidth:300},children:J.description||"--"}),!re&&l.jsxs(Ve,{sx:{borderColor:"var(--theme-border)"},align:"right",children:[l.jsx(fr,{title:"Edit",children:l.jsx(Qt,{size:"small",onClick:()=>Q(J),children:l.jsx(Ff,{fontSize:"small"})})}),l.jsx(fr,{title:"Delete",children:l.jsx(Qt,{size:"small",onClick:()=>X(J),sx:{color:"var(--theme-error)"},children:l.jsx(Lh,{fontSize:"small"})})})]})]},J.id)),f.length===0&&!v&&l.jsx(Ur,{children:l.jsx(Ve,{colSpan:re?3:4,align:"center",sx:{py:4,color:"var(--theme-text-secondary)"},children:P?"No entitlements match your search":"No entitlements defined"})})]})]})})]})}),n&&n.sources.length>0&&l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mt:3},children:l.jsxs(gt,{children:[l.jsx(vt,{variant:"subtitle2",content:"Entitlement Sources",customColor:"var(--theme-text-secondary)",style:{marginBottom:"12px"}}),l.jsx(ne,{sx:{display:"flex",flexDirection:"column",gap:1},children:n.sources.map((J,oe)=>l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[l.jsx(qt,{size:"small",label:J.primary?"Primary":"Additional",sx:{bgcolor:J.primary?"var(--theme-primary)20":"var(--theme-text-secondary)20",color:J.primary?"var(--theme-primary)":"var(--theme-text-secondary)"}}),l.jsx(vt,{variant:"body1",content:J.name,fontWeight:"500",customColor:"var(--theme-text-primary)"}),J.description&&l.jsx(vt,{variant:"body2",content:`- ${J.description}`,customColor:"var(--theme-text-secondary)"}),J.readonly&&l.jsx(qt,{size:"small",icon:l.jsx(Xy,{sx:{fontSize:14}}),label:"Read-only",sx:{bgcolor:"var(--theme-warning)20",color:"var(--theme-warning)"}})]},oe))}),n.cacheEnabled&&l.jsx(ne,{sx:{mt:2,pt:2,borderTop:1,borderColor:"var(--theme-border)"},children:l.jsx(vt,{variant:"caption",content:`Caching: Enabled (TTL: ${n.cacheTtl}s)`,customColor:"var(--theme-text-secondary)"})})]})}),!re&&l.jsxs(Nu,{open:I,onClose:()=>T(!1),maxWidth:"sm",fullWidth:!0,children:[l.jsx($u,{children:"Add Entitlement"}),l.jsx(Bu,{children:l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[l.jsx(Rt,{label:"Name",fullWidth:!0,value:$.name,onChange:J=>j({...$,name:J.target.value}),placeholder:"e.g., premium, pro, feature:analytics",required:!0}),l.jsx(Rt,{label:"Category (Optional)",fullWidth:!0,value:$.category,onChange:J=>j({...$,category:J.target.value}),placeholder:"e.g., subscription, feature, access"}),l.jsx(Rt,{label:"Description (Optional)",fullWidth:!0,multiline:!0,rows:2,value:$.description,onChange:J=>j({...$,description:J.target.value}),placeholder:"Describe what this entitlement grants access to"})]})}),l.jsxs(zu,{children:[l.jsx(Nr,{variant:"text",label:"Cancel",onClick:()=>T(!1)}),l.jsx(Nr,{variant:"primary",label:"Create",onClick:K,disabled:!$.name.trim()||q})]})]}),!re&&H&&l.jsxs(Nu,{open:M,onClose:()=>R(!1),maxWidth:"sm",fullWidth:!0,children:[l.jsx($u,{children:"Edit Entitlement"}),l.jsx(Bu,{children:l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[l.jsx(Rt,{label:"Name",fullWidth:!0,value:H.name,disabled:!0,helperText:"Name cannot be changed"}),l.jsx(Rt,{label:"Category",fullWidth:!0,value:H.category||"",onChange:J=>G({...H,category:J.target.value})}),l.jsx(Rt,{label:"Description",fullWidth:!0,multiline:!0,rows:2,value:H.description||"",onChange:J=>G({...H,description:J.target.value})})]})}),l.jsxs(zu,{children:[l.jsx(Nr,{variant:"text",label:"Cancel",onClick:()=>R(!1)}),l.jsx(Nr,{variant:"primary",label:"Save",onClick:Y,disabled:q})]})]}),!re&&H&&l.jsxs(Nu,{open:L,onClose:()=>A(!1),maxWidth:"sm",fullWidth:!0,children:[l.jsx($u,{children:"Delete Entitlement"}),l.jsxs(Bu,{children:[l.jsx(vt,{variant:"body1",content:`Are you sure you want to delete the entitlement "${H.name}"?`,customColor:"var(--theme-text-primary)"}),l.jsx(Kt,{severity:"warning",sx:{mt:2},children:"This will remove the entitlement from all users who currently have it."})]}),l.jsxs(zu,{children:[l.jsx(Nr,{variant:"text",label:"Cancel",onClick:()=>A(!1)}),l.jsx(Nr,{variant:"primary",color:"error",label:"Delete",onClick:Z,disabled:q})]})]})]})}function nC(e){switch(e){case"enabled":return"var(--theme-success)";case"error":return"var(--theme-error)";case"disabled":default:return"var(--theme-text-secondary)"}}function eW(e){switch(e){case"enabled":return l.jsx(Di,{sx:{color:"var(--theme-success)"}});case"error":return l.jsx(Wo,{sx:{color:"var(--theme-error)"}});case"disabled":default:return l.jsx(_h,{sx:{color:"var(--theme-text-secondary)"}})}}const oC={domain:"",clientId:"",clientSecret:"",baseUrl:"",secret:"",audience:"",scopes:["openid","profile","email"],allowedRoles:[],allowedDomains:[]},iC={url:"",anonKey:""},aC={username:"",password:"",realm:"Protected Area"},sC={connectionUri:"",apiKey:"",appName:"",apiDomain:"",websiteDomain:"",apiBasePath:"/auth",websiteBasePath:"/auth",enableEmailPassword:!0,socialProviders:{}};function tW(){var Me,Xe,dt;const[e,t]=b.useState(null),[r,n]=b.useState(!0),[o,a]=b.useState(null),[c,u]=b.useState(null),[d,f]=b.useState(!1),[h,v]=b.useState(!1),[m,y]=b.useState(!1),[x,w]=b.useState(null),[C,P]=b.useState(""),[k,I]=b.useState(oC),[T,M]=b.useState(iC),[R,L]=b.useState(aC),[A,H]=b.useState(sC),[G,$]=b.useState(!0),[j,q]=b.useState(""),[V,O]=b.useState({enabled:!1,clientId:"",clientSecret:""}),[U,K]=b.useState({enabled:!1,clientId:"",clientSecret:""}),[Y,Z]=b.useState({enabled:!1,clientId:"",clientSecret:"",keyId:"",teamId:""}),[Q,X]=b.useState(!1),[re,de]=b.useState(!1),J=b.useCallback(async()=>{var le,Ye,We,ft;n(!0),a(null);try{const ze=await At.getAuthConfig();if(t(ze),ze.runtimeConfig){const Nt=ze.runtimeConfig;if(P(Nt.adapter||""),$(Nt.settings.authRequired??!0),q(((le=Nt.settings.excludePaths)==null?void 0:le.join(", "))||""),Nt.config.auth0&&I({...oC,...Nt.config.auth0}),Nt.config.supabase&&M({...iC,...Nt.config.supabase}),Nt.config.basic&&L({...aC,...Nt.config.basic}),Nt.config.supertokens){const ht=Nt.config.supertokens;H({...sC,...ht}),(Ye=ht.socialProviders)!=null&&Ye.google&&O({enabled:!0,clientId:ht.socialProviders.google.clientId,clientSecret:ht.socialProviders.google.clientSecret}),(We=ht.socialProviders)!=null&&We.github&&K({enabled:!0,clientId:ht.socialProviders.github.clientId,clientSecret:ht.socialProviders.github.clientSecret}),(ft=ht.socialProviders)!=null&&ft.apple&&Z({enabled:!0,clientId:ht.socialProviders.apple.clientId,clientSecret:ht.socialProviders.apple.clientSecret,keyId:ht.socialProviders.apple.keyId,teamId:ht.socialProviders.apple.teamId})}}else ze.adapter&&P(ze.adapter)}catch(ze){a(ze instanceof Error?ze.message:"Failed to fetch auth status")}finally{n(!1)}},[]);b.useEffect(()=>{J()},[J]);const oe=(le,Ye)=>{navigator.clipboard.writeText(Ye),u(le),setTimeout(()=>u(null),2e3)},ee=()=>{f(!0),w(null)},he=()=>{f(!1),w(null),J()},Ce=le=>JSON.parse(JSON.stringify(le)),ye=()=>{switch(C){case"auth0":return Ce(k);case"supabase":return Ce(T);case"basic":return Ce(R);case"supertokens":{const le={...A},Ye={};return V.enabled&&(Ye.google={clientId:V.clientId,clientSecret:V.clientSecret}),U.enabled&&(Ye.github={clientId:U.clientId,clientSecret:U.clientSecret}),Y.enabled&&(Ye.apple={clientId:Y.clientId,clientSecret:Y.clientSecret,keyId:Y.keyId||"",teamId:Y.teamId||""}),Object.keys(Ye).length>0&&(le.socialProviders=Ye),Ce(le)}default:return{}}},ce=async()=>{if(C){y(!0),w(null);try{const le=await At.testAuthProvider({adapter:C,config:ye()});w(le)}catch(le){w({success:!1,message:le instanceof Error?le.message:"Test failed"})}finally{y(!1)}}},Fe=async()=>{if(e!=null&&e.adapter){y(!0),w(null);try{const le=await At.testCurrentAuthProvider();w(le)}catch(le){w({success:!1,message:le instanceof Error?le.message:"Test failed"})}finally{y(!1)}}},Le=async()=>{if(C){v(!0),a(null);try{const le={adapter:C,config:ye(),settings:{authRequired:G,excludePaths:j.split(",").map(Ye=>Ye.trim()).filter(Boolean)}};await At.updateAuthConfig(le),f(!1),await J()}catch(le){a(le instanceof Error?le.message:"Failed to save configuration")}finally{v(!1)}}},Ne=async()=>{v(!0),a(null);try{await At.deleteAuthConfig(),de(!1),f(!1),await J()}catch(le){a(le instanceof Error?le.message:"Failed to delete configuration")}finally{v(!1)}};if(r)return l.jsx(ne,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:"50vh"},children:l.jsx(cr,{})});const $e=e!=null&&e.config?Object.entries(e.config):[];return l.jsxs(ne,{children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1},children:[l.jsx(pe,{variant:"h4",sx:{color:"var(--theme-text-primary)"},children:"Authentication"}),l.jsx(ne,{sx:{display:"flex",gap:1},children:!d&&l.jsxs(l.Fragment,{children:[l.jsx(fr,{title:"Edit Configuration",children:l.jsx(Qt,{onClick:ee,sx:{color:"var(--theme-primary)"},children:l.jsx(Ff,{})})}),l.jsx(fr,{title:"Refresh",children:l.jsx(Qt,{onClick:J,sx:{color:"var(--theme-text-secondary)"},children:l.jsx(Ys,{})})})]})})]}),l.jsx(pe,{variant:"body2",sx:{mb:4,color:"var(--theme-text-secondary)"},children:d?"Configure authentication provider":"Auth plugin configuration status"}),o&&l.jsx(Kt,{severity:"error",sx:{mb:2},onClose:()=>a(null),children:o}),d?l.jsxs(ne,{children:[l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:2},children:"Provider Selection"}),l.jsxs(_i,{fullWidth:!0,sx:{mb:2},children:[l.jsx(Ga,{sx:{color:"var(--theme-text-secondary)"},children:"Auth Provider"}),l.jsxs(aa,{value:C,onChange:le=>P(le.target.value),label:"Auth Provider",sx:{color:"var(--theme-text-primary)"},children:[l.jsx(Sr,{value:"",children:l.jsx("em",{children:"None (Disabled)"})}),l.jsx(Sr,{value:"supertokens",children:"SuperTokens"}),l.jsx(Sr,{value:"auth0",children:"Auth0"}),l.jsx(Sr,{value:"supabase",children:"Supabase"}),l.jsx(Sr,{value:"basic",children:"Basic Auth"})]})]}),l.jsxs(ne,{sx:{display:"flex",gap:2,alignItems:"center"},children:[l.jsx(Ba,{control:l.jsx(_s,{checked:G,onChange:le=>$(le.target.checked),sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"var(--theme-primary)"}}}),label:"Auth Required",sx:{color:"var(--theme-text-primary)"}}),l.jsx(Rt,{label:"Exclude Paths (comma-separated)",value:j,onChange:le=>q(le.target.value),size:"small",sx:{flex:1,"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}},placeholder:"/api/health, /api/public/*"})]})]})}),C==="auth0"&&l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:2},children:"Auth0 Configuration"}),l.jsxs(ne,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",md:"1fr 1fr"},gap:2},children:[l.jsx(Rt,{label:"Domain",value:k.domain,onChange:le=>I({...k,domain:le.target.value}),required:!0,placeholder:"your-tenant.auth0.com",sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Client ID",value:k.clientId,onChange:le=>I({...k,clientId:le.target.value}),required:!0,sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Client Secret",type:"password",value:k.clientSecret,onChange:le=>I({...k,clientSecret:le.target.value}),required:!0,sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Base URL",value:k.baseUrl,onChange:le=>I({...k,baseUrl:le.target.value}),required:!0,placeholder:"https://your-app.com",sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Session Secret",type:"password",value:k.secret,onChange:le=>I({...k,secret:le.target.value}),required:!0,sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"API Audience (optional)",value:k.audience||"",onChange:le=>I({...k,audience:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}})]})]})}),C==="supabase"&&l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:2},children:"Supabase Configuration"}),l.jsxs(ne,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",md:"1fr 1fr"},gap:2},children:[l.jsx(Rt,{label:"Project URL",value:T.url,onChange:le=>M({...T,url:le.target.value}),required:!0,placeholder:"https://your-project.supabase.co",sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Anon Key",type:"password",value:T.anonKey,onChange:le=>M({...T,anonKey:le.target.value}),required:!0,sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}})]})]})}),C==="basic"&&l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:2},children:"Basic Auth Configuration"}),l.jsxs(ne,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",md:"1fr 1fr 1fr"},gap:2},children:[l.jsx(Rt,{label:"Username",value:R.username,onChange:le=>L({...R,username:le.target.value}),required:!0,sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Password",type:"password",value:R.password,onChange:le=>L({...R,password:le.target.value}),required:!0,sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Realm (optional)",value:R.realm||"",onChange:le=>L({...R,realm:le.target.value}),placeholder:"Protected Area",sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}})]})]})}),C==="supertokens"&&l.jsxs(l.Fragment,{children:[l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:2},children:"SuperTokens Configuration"}),l.jsxs(ne,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",md:"1fr 1fr"},gap:2},children:[l.jsx(Rt,{label:"Connection URI",value:A.connectionUri,onChange:le=>H({...A,connectionUri:le.target.value}),required:!0,placeholder:"http://localhost:3567",sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"API Key (optional)",type:"password",value:A.apiKey||"",onChange:le=>H({...A,apiKey:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"App Name",value:A.appName,onChange:le=>H({...A,appName:le.target.value}),required:!0,sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"API Domain",value:A.apiDomain,onChange:le=>H({...A,apiDomain:le.target.value}),required:!0,placeholder:"http://localhost:3000",sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Website Domain",value:A.websiteDomain,onChange:le=>H({...A,websiteDomain:le.target.value}),required:!0,placeholder:"http://localhost:3000",sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"API Base Path",value:A.apiBasePath||"/auth",onChange:le=>H({...A,apiBasePath:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}})]}),l.jsx(ne,{sx:{mt:2},children:l.jsx(Ba,{control:l.jsx(_s,{checked:A.enableEmailPassword??!0,onChange:le=>H({...A,enableEmailPassword:le.target.checked}),sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"var(--theme-primary)"}}}),label:"Enable Email/Password Auth",sx:{color:"var(--theme-text-primary)"}})})]})}),l.jsxs(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:[l.jsx(gt,{sx:{pb:Q?2:0},children:l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer"},onClick:()=>X(!Q),children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)"},children:"Social Login Providers"}),Q?l.jsx(D7,{}):l.jsx(F7,{})]})}),l.jsx(Xu,{in:Q,children:l.jsxs(gt,{sx:{pt:0},children:[l.jsx(_y,{sx:{mb:2}}),l.jsxs(ne,{sx:{mb:3},children:[l.jsx(Ba,{control:l.jsx(_s,{checked:V.enabled,onChange:le=>O({...V,enabled:le.target.checked}),sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"var(--theme-primary)"}}}),label:"Google",sx:{color:"var(--theme-text-primary)",mb:1}}),V.enabled&&l.jsxs(ne,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",md:"1fr 1fr"},gap:2,ml:4},children:[l.jsx(Rt,{label:"Client ID",size:"small",value:V.clientId,onChange:le=>O({...V,clientId:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Client Secret",size:"small",type:"password",value:V.clientSecret,onChange:le=>O({...V,clientSecret:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}})]})]}),l.jsxs(ne,{sx:{mb:3},children:[l.jsx(Ba,{control:l.jsx(_s,{checked:U.enabled,onChange:le=>K({...U,enabled:le.target.checked}),sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"var(--theme-primary)"}}}),label:"GitHub",sx:{color:"var(--theme-text-primary)",mb:1}}),U.enabled&&l.jsxs(ne,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",md:"1fr 1fr"},gap:2,ml:4},children:[l.jsx(Rt,{label:"Client ID",size:"small",value:U.clientId,onChange:le=>K({...U,clientId:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Client Secret",size:"small",type:"password",value:U.clientSecret,onChange:le=>K({...U,clientSecret:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}})]})]}),l.jsxs(ne,{children:[l.jsx(Ba,{control:l.jsx(_s,{checked:Y.enabled,onChange:le=>Z({...Y,enabled:le.target.checked}),sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"var(--theme-primary)"}}}),label:"Apple",sx:{color:"var(--theme-text-primary)",mb:1}}),Y.enabled&&l.jsxs(ne,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",md:"1fr 1fr"},gap:2,ml:4},children:[l.jsx(Rt,{label:"Client ID",size:"small",value:Y.clientId,onChange:le=>Z({...Y,clientId:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Client Secret",size:"small",type:"password",value:Y.clientSecret,onChange:le=>Z({...Y,clientSecret:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Key ID",size:"small",value:Y.keyId||"",onChange:le=>Z({...Y,keyId:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Team ID",size:"small",value:Y.teamId||"",onChange:le=>Z({...Y,teamId:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}})]})]})]})})]})]}),x&&l.jsxs(Kt,{severity:x.success?"success":"error",sx:{mb:3},children:[l.jsx(pe,{variant:"body2",sx:{fontWeight:600},children:x.success?"Connection Successful":"Connection Failed"}),l.jsx(pe,{variant:"body2",children:x.message}),((Me=x.details)==null?void 0:Me.latency)&&l.jsxs(pe,{variant:"caption",sx:{display:"block",mt:.5},children:["Latency: ",x.details.latency,"ms"]})]}),l.jsxs(ne,{sx:{display:"flex",gap:2,justifyContent:"space-between"},children:[l.jsxs(ne,{sx:{display:"flex",gap:2},children:[l.jsx(sn,{variant:"outlined",startIcon:l.jsx(_7,{}),onClick:he,disabled:h,sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Cancel"}),(e==null?void 0:e.runtimeConfig)&&l.jsx(sn,{variant:"outlined",color:"error",startIcon:l.jsx(Lh,{}),onClick:()=>de(!0),disabled:h,children:"Reset to Env Vars"})]}),l.jsxs(ne,{sx:{display:"flex",gap:2},children:[l.jsx(sn,{variant:"outlined",startIcon:m?l.jsx(cr,{size:16}):l.jsx(sc,{}),onClick:ce,disabled:!C||m||h,sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:"Test Connection"}),l.jsx(sn,{variant:"contained",startIcon:h?l.jsx(cr,{size:16,sx:{color:"white"}}):l.jsx(d0,{}),onClick:Le,disabled:h,sx:{bgcolor:"var(--theme-primary)","&:hover":{bgcolor:"var(--theme-primary-dark)"}},children:"Save Configuration"})]})]})]}):l.jsxs(l.Fragment,{children:[l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:l.jsxs(gt,{children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2,mb:2},children:[eW((e==null?void 0:e.state)||"disabled"),l.jsxs(ne,{sx:{flex:1},children:[l.jsxs(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)"},children:["Status:"," ",l.jsx(qt,{label:((Xe=e==null?void 0:e.state)==null?void 0:Xe.toUpperCase())||"UNKNOWN",size:"small",sx:{bgcolor:`${nC((e==null?void 0:e.state)||"disabled")}20`,color:nC((e==null?void 0:e.state)||"disabled"),fontWeight:600}})]}),(e==null?void 0:e.adapter)&&l.jsxs(pe,{variant:"body2",sx:{color:"var(--theme-text-secondary)",mt:.5},children:["Adapter: ",l.jsx("strong",{children:e.adapter})]})]}),(e==null?void 0:e.state)==="enabled"&&(e==null?void 0:e.adapter)&&l.jsx(sn,{variant:"outlined",size:"small",startIcon:m?l.jsx(cr,{size:14}):l.jsx(sc,{}),onClick:Fe,disabled:m,sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:"Test Connection"})]}),x&&!d&&l.jsxs(Kt,{severity:x.success?"success":"error",sx:{mb:2},children:[l.jsx(pe,{variant:"body2",sx:{fontWeight:600},children:x.success?"Connection Successful":"Connection Failed"}),l.jsx(pe,{variant:"body2",children:x.message}),((dt=x.details)==null?void 0:dt.latency)&&l.jsxs(pe,{variant:"caption",sx:{display:"block",mt:.5},children:["Latency: ",x.details.latency,"ms"]})]}),(e==null?void 0:e.state)==="enabled"&&!(e!=null&&e.runtimeConfig)&&l.jsxs(Kt,{severity:"success",sx:{mb:2},children:[l.jsx(pe,{variant:"body2",sx:{fontWeight:600},children:"Configured via Environment Variables"}),l.jsx(pe,{variant:"body2",children:'Authentication is configured using environment variables. Click "Edit" to override with runtime configuration (requires PostgreSQL).'})]}),(e==null?void 0:e.runtimeConfig)&&l.jsx(qt,{label:"Runtime Configuration Active",size:"small",sx:{bgcolor:"var(--theme-primary)",color:"white",mb:2}}),(e==null?void 0:e.state)==="error"&&e.error&&l.jsx(Kt,{severity:"error",sx:{mb:2},children:e.error}),(e==null?void 0:e.missingVars)&&e.missingVars.length>0&&l.jsxs(Kt,{severity:"warning",sx:{mb:2},children:[l.jsx(pe,{variant:"body2",sx:{fontWeight:600,mb:1},children:"Missing environment variables:"}),l.jsx(ne,{component:"ul",sx:{m:0,pl:2},children:e.missingVars.map(le=>l.jsx("li",{children:l.jsx("code",{children:le})},le))})]}),(e==null?void 0:e.state)==="disabled"&&l.jsxs(Kt,{severity:"info",children:[l.jsxs(pe,{variant:"body2",children:["Authentication is disabled. Click the edit button to configure a provider, or set the"," ",l.jsx("code",{children:"AUTH_ADAPTER"})," environment variable."]}),l.jsxs(pe,{variant:"body2",sx:{mt:1},children:["Valid options: ",l.jsx("code",{children:"supertokens"}),", ",l.jsx("code",{children:"auth0"}),", ",l.jsx("code",{children:"supabase"}),","," ",l.jsx("code",{children:"basic"})]})]})]})}),$e.length>0&&l.jsxs(yt,{sx:{bgcolor:"var(--theme-surface)"},children:[l.jsx(gt,{sx:{pb:0},children:l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:2},children:"Current Configuration"})}),l.jsx(Qa,{children:l.jsxs(Xa,{size:"small",children:[l.jsx(Ya,{children:l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Variable"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Value"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)",width:60},children:"Actions"})]})}),l.jsx(Ka,{children:$e.map(([le,Ye])=>l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:l.jsx(pe,{sx:{color:"var(--theme-text-primary)",fontFamily:"monospace",fontSize:13},children:le})}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:l.jsx(pe,{sx:{color:Ye.includes("*")?"var(--theme-text-secondary)":"var(--theme-text-primary)",fontFamily:"monospace",fontSize:13},children:Ye})}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:l.jsx(fr,{title:c===le?"Copied!":"Copy value",children:l.jsx(Qt,{size:"small",onClick:()=>oe(le,Ye),sx:{color:c===le?"var(--theme-success)":"var(--theme-text-secondary)"},children:l.jsx(u0,{fontSize:"small"})})})})]},le))})]})})]}),(e==null?void 0:e.state)==="enabled"&&$e.length===0&&l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsx(pe,{sx:{color:"var(--theme-text-secondary)",textAlign:"center"},children:"No configuration details available"})})})]}),l.jsxs(Jv,{open:re,onClose:()=>de(!1),children:[l.jsx(t0,{children:"Reset to Environment Variables?"}),l.jsx(e0,{children:l.jsx(pe,{children:"This will delete the runtime configuration from the database. The auth plugin will fall back to environment variables on the next request."})}),l.jsxs(Zv,{children:[l.jsx(sn,{onClick:()=>de(!1),children:"Cancel"}),l.jsx(sn,{onClick:Ne,color:"error",disabled:h,children:h?l.jsx(cr,{size:20}):"Reset"})]})]})]})}function ly(e){return e<1e3?`${e}ms`:e<6e4?`${e/1e3}s`:e<36e5?`${e/6e4}m`:`${e/36e5}h`}function rW(){const[e,t]=b.useState(null),[r,n]=b.useState(!0),[o,a]=b.useState(!1),[c,u]=b.useState(null),[d,f]=b.useState(null),[h,v]=b.useState(6e4),[m,y]=b.useState(100),[x,w]=b.useState("sliding-window"),[C,P]=b.useState(!0),[k,I]=b.useState(3e5),T=async()=>{n(!0),u(null);try{const L=await At.getRateLimitConfig();t(L),v(L.windowMs),y(L.maxRequests),w(L.strategy),P(L.cleanupEnabled),I(L.cleanupIntervalMs)}catch(L){u(L instanceof Error?L.message:"Failed to fetch config")}finally{n(!1)}};b.useEffect(()=>{T()},[]);const M=async()=>{a(!0),u(null),f(null);try{const L=await At.updateRateLimitConfig({windowMs:h,maxRequests:m,strategy:x,cleanupEnabled:C,cleanupIntervalMs:k});t(L.config),f("Configuration saved successfully"),setTimeout(()=>f(null),3e3)}catch(L){u(L instanceof Error?L.message:"Failed to save config")}finally{a(!1)}},R=e&&(h!==e.windowMs||m!==e.maxRequests||x!==e.strategy||C!==e.cleanupEnabled||k!==e.cleanupIntervalMs);return r?l.jsx(ne,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:"50vh"},children:l.jsx(cr,{})}):c&&!e?l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",border:"1px solid var(--theme-error)"},children:l.jsx(gt,{children:l.jsx(pe,{color:"error",children:c})})}):l.jsxs(ne,{children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(bT,{sx:{color:"var(--theme-primary)",fontSize:32}}),l.jsx(pe,{variant:"h4",sx:{color:"var(--theme-text-primary)"},children:"Rate Limits"})]}),l.jsxs(ne,{sx:{display:"flex",gap:1},children:[l.jsx(fr,{title:"Refresh",children:l.jsx(Qt,{onClick:T,sx:{color:"var(--theme-text-secondary)"},children:l.jsx(Ys,{})})}),l.jsx(sn,{variant:"contained",startIcon:o?l.jsx(cr,{size:16,color:"inherit"}):l.jsx(d0,{}),onClick:M,disabled:o||!R,sx:{minWidth:100},children:o?"Saving...":"Save"})]})]}),l.jsx(pe,{variant:"body2",sx:{mb:4,color:"var(--theme-text-secondary)"},children:"Configure rate limiting defaults for your API"}),d&&l.jsx(Kt,{severity:"success",sx:{mb:3},children:d}),c&&e&&l.jsx(Kt,{severity:"error",sx:{mb:3},children:c}),l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:2},children:"System Status"}),l.jsxs(ne,{sx:{display:"flex",gap:3,flexWrap:"wrap"},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(f0,{sx:{color:"var(--theme-text-secondary)"}}),l.jsxs(ne,{children:[l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:"Store"}),l.jsx(pe,{sx:{color:"var(--theme-text-primary)"},children:e==null?void 0:e.store})]})]}),l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(A7,{sx:{color:e!=null&&e.cacheAvailable?"var(--theme-success)":"var(--theme-warning)"}}),l.jsxs(ne,{children:[l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:"Cache"}),l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(pe,{sx:{color:"var(--theme-text-primary)"},children:e==null?void 0:e.cache}),l.jsx(qt,{label:e!=null&&e.cacheAvailable?"Available":"Unavailable",size:"small",sx:{bgcolor:e!=null&&e.cacheAvailable?"var(--theme-success)20":"var(--theme-warning)20",color:e!=null&&e.cacheAvailable?"var(--theme-success)":"var(--theme-warning)"}})]})]})]})]})]})}),l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:3},children:"Default Rate Limit Settings"}),l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",gap:3},children:[l.jsxs(_i,{fullWidth:!0,children:[l.jsx(Ga,{sx:{color:"var(--theme-text-secondary)"},children:"Strategy"}),l.jsxs(aa,{value:x,label:"Strategy",onChange:L=>w(L.target.value),sx:{color:"var(--theme-text-primary)","& .MuiOutlinedInput-notchedOutline":{borderColor:"var(--theme-border)"}},children:[l.jsx(Sr,{value:"sliding-window",children:"Sliding Window - Smooth rate limiting with weighted overlap"}),l.jsx(Sr,{value:"fixed-window",children:"Fixed Window - Simple discrete time windows"}),l.jsx(Sr,{value:"token-bucket",children:"Token Bucket - Allows bursts while maintaining average rate"})]})]}),l.jsxs(ne,{sx:{display:"flex",gap:3,flexWrap:"wrap"},children:[l.jsx(Rt,{label:"Window (ms)",type:"number",value:h,onChange:L=>v(Math.max(1e3,parseInt(L.target.value)||6e4)),helperText:`= ${ly(h)}`,sx:{flex:1,minWidth:200},InputProps:{inputProps:{min:1e3,step:1e3}}}),l.jsx(Rt,{label:"Max Requests",type:"number",value:m,onChange:L=>y(Math.max(1,parseInt(L.target.value)||100)),helperText:"Per window per key",sx:{flex:1,minWidth:200},InputProps:{inputProps:{min:1}}})]}),l.jsx(Kt,{severity:"info",sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(pe,{variant:"body2",children:[l.jsx("strong",{children:"Current limit:"})," ",m," requests per ",ly(h)," using ",x," strategy"]})})]})]})}),l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:3},children:"Cleanup Job"}),l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",gap:3},children:[l.jsx(Ba,{control:l.jsx(_s,{checked:C,onChange:L=>P(L.target.checked),color:"primary"}),label:"Enable automatic cleanup of expired rate limits",sx:{color:"var(--theme-text-primary)"}}),C&&l.jsx(Rt,{label:"Cleanup Interval (ms)",type:"number",value:k,onChange:L=>I(Math.max(6e4,parseInt(L.target.value)||3e5)),helperText:`= ${ly(k)}`,sx:{maxWidth:300},InputProps:{inputProps:{min:6e4,step:6e4}}})]})]})})]})}function nW(){const[e,t]=b.useState(null),[r,n]=b.useState([]),[o,a]=b.useState(!0),[c,u]=b.useState(null),[d,f]=b.useState(null),[h,v]=b.useState(null),[m,y]=b.useState(!1),[x,w]=b.useState(null),C=b.useRef(!0),P=b.useCallback(async()=>{try{const[R,L]=await Promise.all([At.getNotificationsStats(),At.getNotificationsClients()]);C.current&&(t(R),n(L.clients),u(null))}catch(R){C.current&&(R instanceof Error&&R.message.includes("404")?u("Notifications plugin not enabled"):u(R instanceof Error?R.message:"Failed to fetch data"))}finally{C.current&&a(!1)}},[]);b.useEffect(()=>{C.current=!0,P();const R=setInterval(P,5e3);return()=>{C.current=!1,clearInterval(R)}},[P]);const k=async R=>{v(R.id),w(null);try{await At.disconnectNotificationsClient(R.id),C.current&&(f(`Client ${$l(R.id)} disconnected`),setTimeout(()=>{C.current&&f(null)},3e3),await P())}catch(L){C.current&&u(L instanceof Error?L.message:"Failed to disconnect client")}finally{C.current&&v(null)}},I=async()=>{y(!0);try{const R=await At.forceNotificationsReconnect();C.current&&(f(R.message),setTimeout(()=>{C.current&&f(null)},3e3),await P())}catch(R){C.current&&u(R instanceof Error?R.message:"Failed to force reconnect")}finally{C.current&&y(!1)}};if(o)return l.jsx(ne,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:"50vh"},children:l.jsx(cr,{})});if(c&&!e)return l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",border:"1px solid var(--theme-border)"},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(Hf,{sx:{color:"var(--theme-text-secondary)"}}),l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:c})]})})});const T=(e==null?void 0:e.connectionHealth.isHealthy)??!1,M=T?"var(--theme-success)":"var(--theme-warning)";return l.jsxs(ne,{children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(xT,{sx:{color:"var(--theme-primary)",fontSize:32}}),l.jsx(pe,{variant:"h4",sx:{color:"var(--theme-text-primary)"},children:"Notifications"})]}),l.jsxs(ne,{sx:{display:"flex",gap:1},children:[l.jsx(fr,{title:"Refresh",children:l.jsx(Qt,{onClick:P,sx:{color:"var(--theme-text-secondary)"},children:l.jsx(Ys,{})})}),l.jsx(sn,{variant:"outlined",startIcon:m?l.jsx(cr,{size:16}):l.jsx(yB,{}),onClick:I,disabled:m,sx:{borderColor:"var(--theme-border)"},children:m?"Reconnecting...":"Force Reconnect"})]})]}),l.jsx(pe,{variant:"body2",sx:{mb:4,color:"var(--theme-text-secondary)"},children:"Manage realtime notification connections and SSE clients"}),d&&l.jsx(Kt,{severity:"success",sx:{mb:3},children:d}),c&&e&&l.jsx(Kt,{severity:"error",sx:{mb:3},children:c}),l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:l.jsx(gt,{sx:{py:1.5,"&:last-child":{pb:1.5}},children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[T?l.jsx(ST,{sx:{color:M,fontSize:20}}):l.jsx(Hf,{sx:{color:M,fontSize:20}}),l.jsx(pe,{sx:{color:M,fontWeight:500},children:T?"Connected":"Reconnecting..."}),(e==null?void 0:e.connectionHealth.isReconnecting)&&l.jsx(qt,{label:`Attempt ${e.connectionHealth.reconnectAttempts}`,size:"small",sx:{bgcolor:"var(--theme-warning)20",color:"var(--theme-warning)",fontSize:"0.7rem",height:18}})]}),l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[l.jsxs(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:[e==null?void 0:e.channels.length," channel",(e==null?void 0:e.channels.length)!==1?"s":""]}),(e==null?void 0:e.lastEventAt)&&l.jsxs(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:["Last event: ",xv(e.connectionHealth.timeSinceLastEvent)," ago"]})]})]})})}),l.jsxs(kc,{columns:4,spacing:"small",equalHeight:!0,children:[l.jsx(Ha,{icon:l.jsx(Wy,{sx:{fontSize:28}}),label:"Active Clients",value:(e==null?void 0:e.currentConnections)??0,subValue:`${(e==null?void 0:e.totalConnections)??0} total`,color:"var(--theme-primary)"}),l.jsx(Ha,{icon:l.jsx(ac,{sx:{fontSize:28}}),label:"By Device",value:(e==null?void 0:e.clientsByType.device)??0,subValue:`${(e==null?void 0:e.clientsByType.user)??0} by user`,color:"var(--theme-info)"}),l.jsx(Ha,{icon:l.jsx(p0,{sx:{fontSize:28}}),label:"Events Routed",value:Kl((e==null?void 0:e.eventsRouted)??0),subValue:`${Kl((e==null?void 0:e.eventsProcessed)??0)} processed`,color:"var(--theme-success)"}),l.jsx(Ha,{icon:l.jsx(Wo,{sx:{fontSize:28}}),label:"Dropped",value:Kl((e==null?void 0:e.eventsDroppedNoClients)??0),subValue:`${(e==null?void 0:e.eventsParseFailed)??0} parse errors`,color:((e==null?void 0:e.eventsDroppedNoClients)??0)>0?"var(--theme-warning)":"var(--theme-text-secondary)"})]}),l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mt:3},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:2},children:"Connected Clients"}),r.length===0?l.jsx(pe,{sx:{color:"var(--theme-text-secondary)",py:4,textAlign:"center"},children:"No clients currently connected"}):l.jsx(Qa,{component:_r,sx:{bgcolor:"transparent",boxShadow:"none"},children:l.jsxs(Xa,{size:"small",children:[l.jsx(Ya,{children:l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Client ID"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Device ID"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"User ID"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Connected"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Duration"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},align:"right",children:"Actions"})]})}),l.jsx(Ka,{children:r.map(R=>l.jsxs(Ur,{hover:!0,children:[l.jsx(Ve,{sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:l.jsx(fr,{title:R.id,children:l.jsx("code",{style:{fontSize:"0.85em"},children:$l(R.id)})})}),l.jsx(Ve,{sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:R.deviceId?l.jsx(fr,{title:R.deviceId,children:l.jsx(qt,{size:"small",icon:l.jsx(Wy,{sx:{fontSize:14}}),label:$l(R.deviceId),sx:{bgcolor:"var(--theme-primary)20",color:"var(--theme-primary)"}})}):l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:"—"})}),l.jsx(Ve,{sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:R.userId?l.jsx(fr,{title:R.userId,children:l.jsx(qt,{size:"small",icon:l.jsx(ac,{sx:{fontSize:14}}),label:$l(R.userId),sx:{bgcolor:"var(--theme-info)20",color:"var(--theme-info)"}})}):l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:"—"})}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:new Date(R.connectedAt).toLocaleTimeString()}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:xv(R.durationMs)}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},align:"right",children:l.jsx(fr,{title:"Disconnect client",children:l.jsx(Qt,{size:"small",onClick:()=>w(R),disabled:h===R.id,sx:{color:"var(--theme-error)"},children:h===R.id?l.jsx(cr,{size:18}):l.jsx(oB,{fontSize:"small"})})})})]},R.id))})]})})]})}),l.jsxs(Jv,{open:!!x,onClose:()=>w(null),"aria-labelledby":"disconnect-dialog-title",children:[l.jsx(t0,{id:"disconnect-dialog-title",children:"Disconnect Client?"}),l.jsx(e0,{children:l.jsxs(WL,{children:["Are you sure you want to disconnect this client?",(x==null?void 0:x.deviceId)&&l.jsxs(l.Fragment,{children:[l.jsx("br",{}),l.jsx("strong",{children:"Device:"})," ",$l(x.deviceId)]}),(x==null?void 0:x.userId)&&l.jsxs(l.Fragment,{children:[l.jsx("br",{}),l.jsx("strong",{children:"User:"})," ",$l(x.userId)]}),l.jsx("br",{}),l.jsx("br",{}),"The client will receive a disconnect event and the connection will be closed. The client may automatically reconnect."]})}),l.jsxs(Zv,{children:[l.jsx(sn,{onClick:()=>w(null),children:"Cancel"}),l.jsx(sn,{onClick:()=>x&&k(x),color:"error",autoFocus:!0,children:"Disconnect"})]})]})]})}function oW(){const[e,t]=b.useState(null),[r,n]=b.useState(!0),[o,a]=b.useState(null),[c,u]=b.useState(null),[d,f]=b.useState({}),h=b.useCallback(async()=>{n(!0),a(null);try{const m=await At.fetch("/ai-proxy/config");t(m)}catch(m){a(m instanceof Error?m.message:"Failed to fetch integrations config")}finally{n(!1)}},[]);b.useEffect(()=>{h()},[h]);const v=async m=>{u(m),f(y=>({...y,[m]:{success:!1,message:"Testing..."}}));try{const y=await At.fetch(`/ai-proxy/test/${m}`,{method:"POST"});f(x=>({...x,[m]:y}))}catch(y){f(x=>({...x,[m]:{success:!1,message:y instanceof Error?y.message:"Test failed"}}))}finally{u(null)}};return r?l.jsx(ne,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:"50vh"},children:l.jsx(cr,{})}):l.jsxs(ne,{children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1},children:[l.jsx(pe,{variant:"h4",sx:{color:"var(--theme-text-primary)"},children:"AI Integrations"}),l.jsx(fr,{title:"Refresh",children:l.jsx(Qt,{onClick:h,sx:{color:"var(--theme-text-secondary)"},children:l.jsx(Ys,{})})})]}),l.jsx(pe,{variant:"body2",sx:{mb:4,color:"var(--theme-text-secondary)"},children:"Manage AI service connections for QwickBot"}),o&&l.jsx(Kt,{severity:"error",sx:{mb:3},onClose:()=>a(null),children:o}),e&&l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:3},children:[l.jsxs(ne,{children:[l.jsx(pe,{variant:"h3",sx:{color:"var(--theme-primary)",fontWeight:600},children:e.stats.totalRequests}),l.jsx(pe,{variant:"body2",sx:{color:"var(--theme-text-secondary)"},children:"Total API Requests"})]}),l.jsxs(ne,{sx:{borderLeft:"1px solid var(--theme-border)",pl:3},children:[l.jsx(pe,{variant:"h3",sx:{color:"var(--theme-success)",fontWeight:600},children:e.integrations.filter(m=>m.configured).length}),l.jsx(pe,{variant:"body2",sx:{color:"var(--theme-text-secondary)"},children:"Configured Services"})]})]})})}),l.jsx(ne,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",md:"1fr 1fr"},gap:3},children:e==null?void 0:e.integrations.map(m=>{const y=d[m.id],x=c===m.id;return l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",mb:2},children:[l.jsxs(ne,{children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)"},children:m.name}),l.jsx(qt,{label:m.configured?"Configured":"Not Configured",size:"small",sx:{bgcolor:m.configured?"var(--theme-success)20":"var(--theme-error)20",color:m.configured?"var(--theme-success)":"var(--theme-error)",fontWeight:500}})]}),l.jsx(pe,{variant:"body2",sx:{color:"var(--theme-text-secondary)"},children:m.description})]}),m.configured?l.jsx(Di,{sx:{color:"var(--theme-success)"}}):l.jsx(Wo,{sx:{color:"var(--theme-error)"}})]}),l.jsxs(ne,{sx:{mb:2,p:1.5,bgcolor:"var(--theme-background)",borderRadius:1},children:[l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)",display:"block",mb:.5},children:"API Key"}),l.jsx(pe,{sx:{fontFamily:"monospace",fontSize:13,color:m.configured?"var(--theme-text-primary)":"var(--theme-text-secondary)"},children:m.apiKey})]}),y&&l.jsx(ne,{sx:{mb:2},children:x?l.jsx(Sd,{sx:{height:4,borderRadius:2}}):l.jsxs(Kt,{severity:y.success?"success":"error",sx:{py:.5,"& .MuiAlert-message":{fontSize:13}},children:[y.message,y.latency!==void 0&&l.jsxs(pe,{variant:"caption",sx:{display:"block",mt:.5},children:["Latency: ",y.latency,"ms"]})]})}),l.jsxs(ne,{sx:{display:"flex",gap:1,justifyContent:"flex-end"},children:[l.jsx(sn,{size:"small",startIcon:l.jsx(uB,{}),href:m.docsUrl,target:"_blank",sx:{color:"var(--theme-text-secondary)","&:hover":{color:"var(--theme-primary)"}},children:"Docs"}),l.jsx(sn,{size:"small",variant:"outlined",startIcon:x?l.jsx(cr,{size:14}):l.jsx(sc,{}),onClick:()=>v(m.id),disabled:!m.configured||x,sx:{borderColor:"var(--theme-border)",color:"var(--theme-text-primary)","&:hover":{borderColor:"var(--theme-primary)"}},children:"Test Connection"})]})]})},m.id)})}),e&&e.integrations.some(m=>!m.configured)&&l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mt:3},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:2},children:"Setup Instructions"}),l.jsx(pe,{variant:"body2",sx:{color:"var(--theme-text-secondary)",mb:2},children:"Add the following environment variables to configure the AI services:"}),l.jsx(ne,{component:"pre",sx:{p:2,bgcolor:"var(--theme-background)",borderRadius:1,overflow:"auto",fontFamily:"monospace",fontSize:13,color:"var(--theme-text-primary)"},children:`# Groq - for chat (https://console.groq.com)
|
|
464
|
+
`)}`);const r=this.applyDefaults();return new V0(r)}validate(){const t=[],r=[];if(this.config.app.name||r.push("App name is required"),this.config.app.id||r.push("App ID is required"),this.config.copyright.year&&this.config.copyright.year!=="auto"&&(!Number.isInteger(this.config.copyright.year)||this.config.copyright.year<1900)&&t.push('Copyright year should be "auto" or a valid year >= 1900'),this.config.app.logo&&!this.options.skipValidation&&ju&&Pu){const n=Pu.resolve(this.options.baseDir||process.cwd(),this.config.app.logo);ju.existsSync(n)||t.push(`Logo file not found: ${this.config.app.logo} (will use default)`)}return this.config.build.port!==void 0&&(!Number.isInteger(this.config.build.port)||this.config.build.port<1||this.config.build.port>65535)&&r.push("Port must be a valid integer between 1 and 65535"),this.config.build.previewPort!==void 0&&(!Number.isInteger(this.config.build.previewPort)||this.config.build.previewPort<1||this.config.build.previewPort>65535)&&r.push("Preview port must be a valid integer between 1 and 65535"),this.config.pwa.themeColor&&!this.isValidColor(this.config.pwa.themeColor)&&t.push(`Theme color may not be valid: ${this.config.pwa.themeColor}`),this.config.pwa.backgroundColor&&!this.isValidColor(this.config.pwa.backgroundColor)&&t.push(`Background color may not be valid: ${this.config.pwa.backgroundColor}`),{warnings:t,errors:r,isValid:r.length===0}}applyDefaults(){const t={id:this.config.app.id,name:this.config.app.name,shortName:this.config.app.shortName||this.config.app.name,description:this.config.app.description||this.config.app.name,version:this.config.app.version||"1.0.0",logo:this.config.app.logo||"/favicon.ico",author:this.config.app.author,homepage:this.config.app.homepage},r={port:this.config.build.port||3e3,previewPort:this.config.build.previewPort||4173,outputDir:this.config.build.outputDir||"dist",publicPath:this.config.build.publicPath||"/",base:this.config.build.base||"/"},n={themeColor:this.config.pwa.themeColor||"#000000",backgroundColor:this.config.pwa.backgroundColor||"#ffffff",startUrl:this.config.pwa.startUrl||"/",scope:this.config.pwa.scope||"/",display:this.config.pwa.display||"standalone",orientation:this.config.pwa.orientation},o={defaultTheme:this.config.ui.defaultTheme||"light",defaultPalette:this.config.ui.defaultPalette||"default",enableScaffolding:this.config.ui.enableScaffolding??!0,showThemeSwitcher:this.config.ui.showThemeSwitcher??!1,showPaletteSwitcher:this.config.ui.showPaletteSwitcher??!1},a={year:this.config.copyright.year||"auto",author:this.config.copyright.author||t.author||t.name,text:this.config.copyright.text};return{app:t,build:r,pwa:n,ui:o,copyright:a}}isValidColor(t){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(t)||/^(black|white|red|green|blue|yellow|orange|purple|pink|gray|grey)$/i.test(t)||/^rgba?\([^)]+\)$/i.test(t)}}let ua=class extends xt{};_([z(),D({field_type:B.TEXT,label:"Field Label",description:"Label/title for the choice input field",placeholder:"Options"}),W(),ae(),F("design:type",String)],ua.prototype,"label",void 0);_([z(),D({field_type:B.TEXTAREA,label:"Options",description:"Array of option values (HTML content supported) - JSON array format"}),W(),dn(),ae({each:!0}),F("design:type",Array)],ua.prototype,"options",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Disabled",description:"Whether the input fields are disabled"}),W(),Bt(),F("design:type",Boolean)],ua.prototype,"disabled",void 0);_([z(),D({field_type:B.TEXT,label:"Placeholder Text",description:"Placeholder text for option inputs",placeholder:"Enter option text. HTML formatting supported."}),W(),ae(),F("design:type",String)],ua.prototype,"placeholder",void 0);_([z(),D({field_type:B.TEXT,label:"Option Label Prefix",description:'Prefix for each option label (e.g., "Option", "Choice")',placeholder:"Option"}),W(),ae(),F("design:type",String)],ua.prototype,"optionLabelPrefix",void 0);_([z({defaultValue:2}),D({field_type:B.NUMBER,label:"Input Rows",description:"Number of rows for each option input field"}),W(),Pr(),F("design:type",Number)],ua.prototype,"rows",void 0);_([z(),D({field_type:B.TEXT,label:"Add Button Text",description:"Text for the add option button",placeholder:"Add Option"}),W(),ae(),F("design:type",String)],ua.prototype,"addButtonText",void 0);ua=_([Ft("ChoiceInputField","1.0.0")],ua);let da=class extends AT{};_([z(),D({field_type:B.TEXTAREA,label:"Content",description:"Raw code text. If provided, React children are ignored in serialization.",placeholder:"Enter code content..."}),W(),ae(),F("design:type",String)],da.prototype,"content",void 0);_([z(),D({field_type:B.TEXT,label:"Language",description:"Programming language for syntax highlighting (e.g., typescript, javascript, python)",placeholder:"javascript"}),W(),ae(),F("design:type",String)],da.prototype,"language",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Show Copy Button",description:"Display a copy-to-clipboard button"}),W(),Bt(),F("design:type",Boolean)],da.prototype,"showCopy",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Show Line Numbers",description:"Display line numbers alongside the code"}),W(),Bt(),F("design:type",Boolean)],da.prototype,"showLineNumbers",void 0);_([z(),D({field_type:B.TEXT,label:"Title",description:"Optional title or filename to display above the code",placeholder:"File name or title"}),W(),ae(),F("design:type",String)],da.prototype,"title",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Wrap Long Lines",description:"Allow long lines to wrap instead of scrolling horizontally"}),W(),Bt(),F("design:type",Boolean)],da.prototype,"wrapLines",void 0);_([z(),D({field_type:B.TEXT,label:"Background Color",description:"Custom background color override",placeholder:"#f5f5f5"}),W(),ae(),F("design:type",String)],da.prototype,"codeBackground",void 0);da=_([Ft("Code","1.0.0")],da);let ro=class extends sa{};_([z(),D({field_type:B.NUMBER,label:"Span",description:"Number of columns to span (1-12)",placeholder:"12"}),W(),Pr(),Ue([1,2,3,4,5,6,7,8,9,10,11,12]),F("design:type",Number)],ro.prototype,"span",void 0);_([z(),D({field_type:B.NUMBER,label:"XS (Mobile)",description:"Columns on extra small screens (1-12)",placeholder:"12"}),W(),Pr(),Ue([1,2,3,4,5,6,7,8,9,10,11,12]),F("design:type",Number)],ro.prototype,"xs",void 0);_([z(),D({field_type:B.NUMBER,label:"SM (Tablet)",description:"Columns on small screens (1-12)",placeholder:"6"}),W(),Pr(),Ue([1,2,3,4,5,6,7,8,9,10,11,12]),F("design:type",Number)],ro.prototype,"sm",void 0);_([z(),D({field_type:B.NUMBER,label:"MD (Desktop)",description:"Columns on medium screens (1-12)",placeholder:"4"}),W(),Pr(),Ue([1,2,3,4,5,6,7,8,9,10,11,12]),F("design:type",Number)],ro.prototype,"md",void 0);_([z(),D({field_type:B.NUMBER,label:"LG (Large Desktop)",description:"Columns on large screens (1-12)",placeholder:"3"}),W(),Pr(),Ue([1,2,3,4,5,6,7,8,9,10,11,12]),F("design:type",Number)],ro.prototype,"lg",void 0);_([z(),D({field_type:B.NUMBER,label:"XL (Extra Large)",description:"Columns on extra large screens (1-12)",placeholder:"2"}),W(),Pr(),Ue([1,2,3,4,5,6,7,8,9,10,11,12]),F("design:type",Number)],ro.prototype,"xl",void 0);_([z(),D({field_type:B.TEXT,label:"Background",description:'Background color or theme color (e.g., "primary.main", "#ffffff")',placeholder:"transparent"}),W(),ae(),F("design:type",String)],ro.prototype,"background",void 0);_([z(),D({field_type:B.TEXT,label:"Padding",description:'Internal spacing (e.g., "medium", "16px", "1rem")',placeholder:"medium"}),W(),ae(),F("design:type",String)],ro.prototype,"padding",void 0);_([z(),D({field_type:B.TEXT,label:"Margin",description:'External spacing (e.g., "small", "8px", "0.5rem")',placeholder:"0"}),W(),ae(),F("design:type",String)],ro.prototype,"margin",void 0);_([z(),D({field_type:B.TEXT,label:"Height",description:'Cell height (e.g., "200px", "medium")',placeholder:"auto"}),W(),ae(),F("design:type",String)],ro.prototype,"height",void 0);_([z(),D({field_type:B.TEXT,label:"Width",description:'Cell width (e.g., "100%", "300px")',placeholder:"100%"}),W(),ae(),F("design:type",String)],ro.prototype,"width",void 0);_([z(),D({field_type:B.TEXT,label:"CSS Class",description:"Additional CSS class names",placeholder:"custom-cell-class"}),W(),ae(),F("design:type",String)],ro.prototype,"className",void 0);ro=_([Ft("GridCell","1.0.0")],ro);let Fo=class extends sa{};_([z(),D({field_type:B.NUMBER,label:"Columns",description:"Number of equal-width columns for auto-distribution"}),W(),Pr(),io(1),F("design:type",Number)],Fo.prototype,"columns",void 0);_([z({defaultValue:"small"}),D({field_type:B.SELECT,label:"Spacing",description:"Spacing between grid items"}),W(),ae(),Ue(["tiny","small","medium","large","huge"]),F("design:type",String)],Fo.prototype,"spacing",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Equal Height",description:"Make all grid items the same height"}),W(),Bt(),F("design:type",Boolean)],Fo.prototype,"equalHeight",void 0);_([z(),D({field_type:B.TEXT,label:"Height",description:'Grid container height (e.g., "400px", "50vh", "medium")',placeholder:"auto"}),W(),ae(),F("design:type",String)],Fo.prototype,"height",void 0);_([z(),D({field_type:B.TEXT,label:"Width",description:'Grid container width (e.g., "100%", "800px", "large")',placeholder:"100%"}),W(),ae(),F("design:type",String)],Fo.prototype,"width",void 0);_([z(),D({field_type:B.TEXT,label:"Min Height",description:"Minimum grid container height",placeholder:"auto"}),W(),ae(),F("design:type",String)],Fo.prototype,"minHeight",void 0);_([z(),D({field_type:B.TEXT,label:"Min Width",description:"Minimum grid container width",placeholder:"auto"}),W(),ae(),F("design:type",String)],Fo.prototype,"minWidth",void 0);_([z(),D({field_type:B.TEXT,label:"Max Height",description:"Maximum grid container height",placeholder:"none"}),W(),ae(),F("design:type",String)],Fo.prototype,"maxHeight",void 0);_([z(),D({field_type:B.TEXT,label:"Max Width",description:"Maximum grid container width",placeholder:"none"}),W(),ae(),F("design:type",String)],Fo.prototype,"maxWidth",void 0);_([z(),D({field_type:B.TEXT,label:"CSS Class",description:"Additional CSS class names",placeholder:"custom-grid-class"}),W(),ae(),F("design:type",String)],Fo.prototype,"className",void 0);Fo=_([Ft("GridLayout","1.0.0")],Fo);let Ho=class extends sa{};_([z(),D({field_type:B.TEXT,label:"Title",description:"Main headline text",placeholder:"Enter hero title..."}),ae(),F("design:type",String)],Ho.prototype,"title",void 0);_([z(),D({field_type:B.TEXT,label:"Subtitle",description:"Subtitle or description text",placeholder:"Enter subtitle..."}),W(),ae(),F("design:type",String)],Ho.prototype,"subtitle",void 0);_([z(),D({field_type:B.IMAGE,label:"Background Image",description:"Background image URL",placeholder:"https://..."}),W(),Ah(),F("design:type",String)],Ho.prototype,"backgroundImage",void 0);_([z(),D({field_type:B.TEXT,label:"Background Gradient",description:"Background gradient CSS value",placeholder:"linear-gradient(...)"}),W(),ae(),F("design:type",String)],Ho.prototype,"backgroundGradient",void 0);_([z({defaultValue:"default"}),D({field_type:B.SELECT,label:"Background Color",description:"Background color theme variant",validation:{options:[{label:"Default",value:"default"},{label:"Primary",value:"primary"},{label:"Secondary",value:"secondary"},{label:"Surface",value:"surface"}]}}),W(),Ue(["default","primary","secondary","surface"]),F("design:type",String)],Ho.prototype,"backgroundColor",void 0);_([z({type:ut.ARRAY}),D({field_type:B.REPEATER,label:"Actions",description:"Action buttons for the hero section"}),W(),dn(),oo({each:!0}),ao(()=>eo),F("design:type",Array)],Ho.prototype,"actions",void 0);_([z({defaultValue:"center"}),D({field_type:B.SELECT,label:"Text Alignment",description:"Text alignment",validation:{options:[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}]}}),W(),Ue(["left","center","right"]),F("design:type",String)],Ho.prototype,"textAlign",void 0);_([z({defaultValue:"medium"}),D({field_type:B.SELECT,label:"Block Height",description:"Block height preset",validation:{options:[{label:"Small",value:"small"},{label:"Medium",value:"medium"},{label:"Large",value:"large"},{label:"Viewport",value:"viewport"}]}}),W(),Ue(["small","medium","large","viewport"]),F("design:type",String)],Ho.prototype,"blockHeight",void 0);_([z(),D({field_type:B.NUMBER,label:"Overlay Opacity",description:"Custom overlay opacity (0-1) when using background images",validation:{min:0,max:1}}),W(),Pr(),io(0),Qs(1),F("design:type",Number)],Ho.prototype,"overlayOpacity",void 0);_([z(),D({field_type:B.TEXT,label:"CSS Class",description:"Additional CSS class name",placeholder:"custom-hero-class"}),W(),ae(),F("design:type",String)],Ho.prototype,"className",void 0);Ho=_([Ft("HeroBlock","1.0.0")],Ho);let tn=class extends xt{};_([z({dataType:ut.STRING}),D({field_type:B.IMAGE,label:"Image Source",description:"Image source URL or path",placeholder:"https://example.com/image.jpg"}),W(),ae(),F("design:type",String)],tn.prototype,"src",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXT,label:"Alt Text",description:"Alternative text for accessibility (required for images with src)",placeholder:"Describe the image for screen readers"}),W(),ae(),F("design:type",String)],tn.prototype,"alt",void 0);_([z({dataType:ut.NUMBER}),D({field_type:B.NUMBER,label:"Width",description:"Image width in pixels (optional)",placeholder:"300"}),W(),Pr(),F("design:type",Number)],tn.prototype,"width",void 0);_([z({dataType:ut.NUMBER}),D({field_type:B.NUMBER,label:"Height",description:"Image height in pixels (optional)",placeholder:"200"}),W(),Pr(),F("design:type",Number)],tn.prototype,"height",void 0);_([z({defaultValue:"cover",dataType:ut.STRING}),D({field_type:B.SELECT,label:"Object Fit",description:"How the image should be resized to fit its container",validation:{options:[{label:"Fill",value:"fill"},{label:"Contain",value:"contain"},{label:"Cover",value:"cover"},{label:"None",value:"none"},{label:"Scale Down",value:"scale-down"}]}}),W(),ae(),Ue(["fill","contain","cover","none","scale-down"]),F("design:type",String)],tn.prototype,"objectFit",void 0);_([z({defaultValue:"center",dataType:ut.STRING}),D({field_type:B.SELECT,label:"Object Position",description:"Position of the image within its container",validation:{options:[{label:"Center",value:"center"},{label:"Top",value:"top"},{label:"Bottom",value:"bottom"},{label:"Left",value:"left"},{label:"Right",value:"right"},{label:"Top Left",value:"top-left"},{label:"Top Right",value:"top-right"},{label:"Bottom Left",value:"bottom-left"},{label:"Bottom Right",value:"bottom-right"}]}}),W(),ae(),Ue(["center","top","bottom","left","right","top-left","top-right","bottom-left","bottom-right"]),F("design:type",String)],tn.prototype,"objectPosition",void 0);_([z({defaultValue:"lazy",dataType:ut.STRING}),D({field_type:B.SELECT,label:"Loading",description:"Image loading behavior",validation:{options:[{label:"Lazy (load when visible)",value:"lazy"},{label:"Eager (load immediately)",value:"eager"}]}}),W(),ae(),Ue(["lazy","eager"]),F("design:type",String)],tn.prototype,"loading",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXT,label:"Title",description:"Image title (tooltip text)",placeholder:"Tooltip text on hover"}),W(),ae(),F("design:type",String)],tn.prototype,"title",void 0);_([z({defaultValue:!1,dataType:ut.BOOLEAN}),D({field_type:B.BOOLEAN,label:"Draggable",description:"Allow the image to be dragged"}),W(),Bt(),F("design:type",Boolean)],tn.prototype,"draggable",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXT,label:"Border Radius",description:'CSS border radius (e.g., "8px", "50%", "1rem")',placeholder:"8px"}),W(),ae(),F("design:type",String)],tn.prototype,"borderRadius",void 0);_([z({defaultValue:!1,dataType:ut.BOOLEAN}),D({field_type:B.BOOLEAN,label:"Show Loading State",description:"Display a loading placeholder while the image loads"}),W(),Bt(),F("design:type",Boolean)],tn.prototype,"showLoading",void 0);_([z({defaultValue:!1,dataType:ut.BOOLEAN}),D({field_type:B.BOOLEAN,label:"Show Error State",description:"Display an error message if the image fails to load"}),W(),Bt(),F("design:type",Boolean)],tn.prototype,"showError",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXT,label:"Fallback Image",description:"Fallback image URL to use if the main image fails to load",placeholder:"https://example.com/fallback.jpg"}),W(),ae(),F("design:type",String)],tn.prototype,"fallbackSrc",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXTAREA,label:"Responsive Sizes",description:"Responsive image sizes attribute for optimized loading",placeholder:"(max-width: 768px) 100vw, 50vw"}),W(),ae(),F("design:type",String)],tn.prototype,"sizes",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXTAREA,label:"Source Set",description:"Source set for responsive images (comma-separated)",placeholder:"image-320w.jpg 320w, image-640w.jpg 640w, image-1280w.jpg 1280w"}),W(),ae(),F("design:type",String)],tn.prototype,"srcSet",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXTAREA,label:"Loading Placeholder",description:"Custom loading placeholder content (for advanced use)",placeholder:"Custom loading content..."}),W(),F("design:type",Object)],tn.prototype,"loadingPlaceholder",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXTAREA,label:"Error Placeholder",description:"Custom error placeholder content (for advanced use)",placeholder:"Custom error content..."}),W(),F("design:type",Object)],tn.prototype,"errorPlaceholder",void 0);tn=_([Ft("Image","1.0.0")],tn);let Gs=class extends sa{};_([z(),D({field_type:B.TEXT,label:"Background Color",description:"Background color (CSS color, theme path, or palette color)",placeholder:"#ffffff or primary.main"}),W(),ae(),F("design:type",String)],Gs.prototype,"background",void 0);_([z(),D({field_type:B.TEXT,label:"Text Color",description:"Text color (CSS color, theme path, or palette color)",placeholder:"#000000 or text.primary"}),W(),ae(),F("design:type",String)],Gs.prototype,"color",void 0);_([z(),D({field_type:B.SELECT,label:"Section Padding",description:"Vertical padding/spacing for the section",validation:{options:[{value:"none",label:"None"},{value:"tiny",label:"Tiny (8px)"},{value:"small",label:"Small (16px)"},{value:"medium",label:"Medium (32px)"},{value:"large",label:"Large (64px)"},{value:"extra-large",label:"Extra Large (96px)"}]}}),W(),Ue(["none","tiny","small","medium","large","extra-large"]),F("design:type",String)],Gs.prototype,"padding",void 0);_([z(),D({field_type:B.SELECT,label:"Content Max Width",description:"Maximum width for the content container",validation:{options:[{value:"xs",label:"Extra Small (444px)"},{value:"sm",label:"Small (600px)"},{value:"md",label:"Medium (900px)"},{value:"lg",label:"Large (1200px)"},{value:"xl",label:"Extra Large (1536px)"},{value:"false",label:"Full Width"}]}}),W(),Ue(["xs","sm","md","lg","xl","false"]),F("design:type",String)],Gs.prototype,"contentMaxWidth",void 0);_([z(),D({field_type:B.SELECT,label:"HTML Element",description:"HTML element type to use for the section",validation:{options:[{value:"section",label:"Section"},{value:"div",label:"Div"},{value:"article",label:"Article"},{value:"main",label:"Main"}]}}),W(),Ue(["section","div","article","main"]),F("design:type",String)],Gs.prototype,"component",void 0);Gs=_([Ft("Section","1.0.0")],Gs);let Eo=class extends xt{};_([z(),D({field_type:B.TEXT,label:"Field Label",description:"The label displayed for the text input field",placeholder:"Enter field label..."}),ae(),F("design:type",String)],Eo.prototype,"label",void 0);_([z(),D({field_type:B.TEXT,label:"Value",description:"Current field value",placeholder:"Enter value..."}),W(),ae(),F("design:type",String)],Eo.prototype,"value",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Required",description:"Whether the field is required"}),W(),Bt(),F("design:type",Boolean)],Eo.prototype,"required",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Disabled",description:"Whether the field is disabled"}),W(),Bt(),F("design:type",Boolean)],Eo.prototype,"disabled",void 0);_([z(),D({field_type:B.TEXT,label:"Error Message",description:"Error message to display if validation fails",placeholder:"Enter error message..."}),W(),ae(),F("design:type",String)],Eo.prototype,"error",void 0);_([z(),D({field_type:B.TEXT,label:"Helper Text",description:"Helper text to guide the user",placeholder:"Enter helper text..."}),W(),ae(),F("design:type",String)],Eo.prototype,"helperText",void 0);_([z(),D({field_type:B.TEXT,label:"Placeholder",description:"Placeholder text shown when field is empty",placeholder:"Enter placeholder text..."}),W(),ae(),F("design:type",String)],Eo.prototype,"placeholder",void 0);_([z(),D({field_type:B.TEXT,label:"Input Type",description:"HTML input type (text, email, number, password, etc.)",placeholder:"text"}),W(),ae(),F("design:type",String)],Eo.prototype,"type",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Multiline",description:"Whether the field supports multiple lines (textarea)"}),W(),Bt(),F("design:type",Boolean)],Eo.prototype,"multiline",void 0);_([z(),D({field_type:B.NUMBER,label:"Rows",description:"Number of rows for multiline fields"}),W(),Pr(),F("design:type",Number)],Eo.prototype,"rows",void 0);_([z(),D({field_type:B.NUMBER,label:"Max Rows",description:"Maximum number of rows for multiline fields"}),W(),Pr(),F("design:type",Number)],Eo.prototype,"maxRows",void 0);Eo=_([Ft("TextInputField","1.0.0")],Eo);let qr=class extends mr{};_([z({dataType:ut.STRING}),D({field_type:B.TEXTAREA,label:"Text Content",description:"The text content to display",placeholder:"Enter your text content here..."}),W(),ae(),F("design:type",String)],qr.prototype,"content",void 0);_([z({defaultValue:"body1",dataType:ut.STRING}),D({field_type:B.SELECT,label:"Typography Variant",description:"Typography variant that determines font size, weight, and line height",validation:{options:[{label:"Heading 1",value:"h1"},{label:"Heading 2",value:"h2"},{label:"Heading 3",value:"h3"},{label:"Heading 4",value:"h4"},{label:"Heading 5",value:"h5"},{label:"Heading 6",value:"h6"},{label:"Subtitle 1",value:"subtitle1"},{label:"Subtitle 2",value:"subtitle2"},{label:"Body 1",value:"body1"},{label:"Body 2",value:"body2"},{label:"Button",value:"button"},{label:"Caption",value:"caption"},{label:"Overline",value:"overline"}]}}),W(),ae(),Ue(["h1","h2","h3","h4","h5","h6","subtitle1","subtitle2","body1","body2","button","caption","overline"]),F("design:type",String)],qr.prototype,"variant",void 0);_([z({defaultValue:"inherit",dataType:ut.STRING}),D({field_type:B.SELECT,label:"Text Color",description:"Color variant for the text",validation:{options:[{label:"Primary",value:"primary"},{label:"Secondary",value:"secondary"},{label:"Text Primary",value:"textPrimary"},{label:"Text Secondary",value:"textSecondary"},{label:"Error",value:"error"},{label:"Warning",value:"warning"},{label:"Info",value:"info"},{label:"Success",value:"success"},{label:"Inherit",value:"inherit"}]}}),W(),ae(),Ue(["primary","secondary","textPrimary","textSecondary","error","warning","info","success","inherit"]),F("design:type",String)],qr.prototype,"color",void 0);_([z({defaultValue:"inherit",dataType:ut.STRING}),D({field_type:B.SELECT,label:"Text Alignment",description:"How to align the text horizontally",validation:{options:[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"},{label:"Justify",value:"justify"},{label:"Inherit",value:"inherit"}]}}),W(),ae(),Ue(["left","center","right","justify","inherit"]),F("design:type",String)],qr.prototype,"align",void 0);_([z({defaultValue:"p",dataType:ut.STRING}),D({field_type:B.SELECT,label:"HTML Element",description:"The HTML element to render (affects semantics and accessibility)",validation:{options:[{label:"Paragraph (p)",value:"p"},{label:"Span",value:"span"},{label:"Div",value:"div"},{label:"Heading 1 (h1)",value:"h1"},{label:"Heading 2 (h2)",value:"h2"},{label:"Heading 3 (h3)",value:"h3"},{label:"Heading 4 (h4)",value:"h4"},{label:"Heading 5 (h5)",value:"h5"},{label:"Heading 6 (h6)",value:"h6"},{label:"Label",value:"label"},{label:"Legend",value:"legend"}]}}),W(),ae(),Ue(["p","span","div","h1","h2","h3","h4","h5","h6","label","legend"]),F("design:type",String)],qr.prototype,"component",void 0);_([z({defaultValue:"inherit",dataType:ut.STRING}),D({field_type:B.SELECT,label:"Font Weight",description:"The weight (thickness) of the font",validation:{options:[{label:"Inherit",value:"inherit"},{label:"Lighter",value:"lighter"},{label:"Normal",value:"normal"},{label:"Bold",value:"bold"},{label:"Bolder",value:"bolder"},{label:"100",value:"100"},{label:"200",value:"200"},{label:"300",value:"300"},{label:"400",value:"400"},{label:"500",value:"500"},{label:"600",value:"600"},{label:"700",value:"700"},{label:"800",value:"800"},{label:"900",value:"900"}]}}),W(),ae(),Ue(["inherit","lighter","normal","bold","bolder","100","200","300","400","500","600","700","800","900"]),F("design:type",String)],qr.prototype,"fontWeight",void 0);_([z({defaultValue:"none",dataType:ut.STRING}),D({field_type:B.SELECT,label:"Text Decoration",description:"Text decoration style",validation:{options:[{label:"None",value:"none"},{label:"Underline",value:"underline"},{label:"Overline",value:"overline"},{label:"Line Through",value:"line-through"}]}}),W(),ae(),Ue(["none","underline","overline","line-through"]),F("design:type",String)],qr.prototype,"textDecoration",void 0);_([z({defaultValue:"none",dataType:ut.STRING}),D({field_type:B.SELECT,label:"Text Transform",description:"How to transform the text case",validation:{options:[{label:"None",value:"none"},{label:"Capitalize",value:"capitalize"},{label:"Uppercase",value:"uppercase"},{label:"Lowercase",value:"lowercase"},{label:"Inherit",value:"inherit"}]}}),W(),ae(),Ue(["none","capitalize","uppercase","lowercase","inherit"]),F("design:type",String)],qr.prototype,"textTransform",void 0);_([z({defaultValue:!1,dataType:ut.BOOLEAN}),D({field_type:B.BOOLEAN,label:"No Wrap",description:"Prevent text from wrapping to multiple lines"}),W(),Bt(),F("design:type",Boolean)],qr.prototype,"noWrap",void 0);_([z({defaultValue:!1,dataType:ut.BOOLEAN}),D({field_type:B.BOOLEAN,label:"Paragraph Mode",description:"Apply paragraph spacing and formatting"}),W(),Bt(),F("design:type",Boolean)],qr.prototype,"paragraph",void 0);_([z({defaultValue:!1,dataType:ut.BOOLEAN}),D({field_type:B.BOOLEAN,label:"Gutter Bottom",description:"Add margin bottom for spacing (useful for headings)"}),W(),Bt(),F("design:type",Boolean)],qr.prototype,"gutterBottom",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXT,label:"Font Size",description:'Custom font size (overrides variant sizing, e.g., "16px", "1.2rem")',placeholder:"16px"}),W(),ae(),F("design:type",String)],qr.prototype,"fontSize",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXT,label:"Line Height",description:'Custom line height (e.g., "1.5", "24px", "150%")',placeholder:"1.5"}),W(),ae(),F("design:type",String)],qr.prototype,"lineHeight",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXT,label:"Letter Spacing",description:'Custom letter spacing (e.g., "0.1em", "1px")',placeholder:"0.1em"}),W(),ae(),F("design:type",String)],qr.prototype,"letterSpacing",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXT,label:"Font Family",description:'Custom font family (e.g., "Arial, sans-serif")',placeholder:"Arial, sans-serif"}),W(),ae(),F("design:type",String)],qr.prototype,"fontFamily",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXTAREA,label:"Custom Color",description:"Custom text color (CSS color value, overrides color variant)",placeholder:"#333333 or rgb(51, 51, 51)"}),W(),ae(),F("design:type",String)],qr.prototype,"customColor",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXTAREA,label:"Max Width",description:'Maximum width for the text (e.g., "300px", "50%")',placeholder:"300px"}),W(),ae(),F("design:type",String)],qr.prototype,"maxWidth",void 0);_([z({dataType:ut.STRING}),D({field_type:B.TEXTAREA,label:"Rich Content",description:"Rich text content with React elements (for advanced use)",placeholder:"Rich content..."}),W(),F("design:type",Object)],qr.prototype,"children",void 0);qr=_([Ft("Text","1.0.0")],qr);let Gr=class extends mr{};_([z({defaultValue:"light"}),D({field_type:B.SELECT,label:"Print Theme",description:"Theme mode to use when printing",validation:{options:[{label:"Light",value:"light"},{label:"Dark",value:"dark"}]}}),W(),Ue(["light","dark"]),F("design:type",String)],Gr.prototype,"theme",void 0);_([z({defaultValue:"default"}),D({field_type:B.SELECT,label:"Print Palette",description:"Color palette to use for print output",validation:{options:[{label:"Default",value:"default"},{label:"Autumn",value:"autumn"},{label:"Cosmic",value:"cosmic"},{label:"Ocean",value:"ocean"},{label:"Spring",value:"spring"},{label:"Winter",value:"winter"}]}}),W(),ae(),F("design:type",String)],Gr.prototype,"palette",void 0);_([z({defaultValue:!0}),D({field_type:B.BOOLEAN,label:"Hide Scaffolding",description:"Hide app scaffolding (navigation, headers) when printing"}),W(),Bt(),F("design:type",Boolean)],Gr.prototype,"hideScaffolding",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Hide Interactive Elements",description:"Hide buttons and interactive elements when printing"}),W(),Bt(),F("design:type",Boolean)],Gr.prototype,"hideInteractiveElements",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Optimize For Monochrome",description:"Optimize design for black and white printing"}),W(),Bt(),F("design:type",Boolean)],Gr.prototype,"optimizeForMonochrome",void 0);_([z(),D({field_type:B.TEXT,label:"Print Title",description:"Custom title to show when printing (optional)",placeholder:"Document Title"}),W(),ae(),F("design:type",String)],Gr.prototype,"printTitle",void 0);_([z({defaultValue:!0}),D({field_type:B.BOOLEAN,label:"Show Print Date",description:"Include print date and time in printed output"}),W(),Bt(),F("design:type",Boolean)],Gr.prototype,"showPrintDate",void 0);_([z(),D({field_type:B.TEXT,label:"Print Header",description:"Custom header content for printed pages (HTML string or React component)",placeholder:"<div>Custom header content...</div>"}),W(),F("design:type",Object)],Gr.prototype,"printHeader",void 0);_([z(),D({field_type:B.TEXT,label:"Print Header (First Page)",description:"Different header for the first page only (overrides main header on page 1)",placeholder:"<div>First page header...</div>"}),W(),F("design:type",Object)],Gr.prototype,"printHeaderFirstPage",void 0);_([z(),D({field_type:B.TEXT,label:"Print Footer",description:"Custom footer content for printed pages (HTML string or React component)",placeholder:"<div>Custom footer content...</div>"}),W(),F("design:type",Object)],Gr.prototype,"printFooter",void 0);_([z(),D({field_type:B.TEXT,label:"Print Footer (First Page)",description:"Different footer for the first page only (overrides main footer on page 1)",placeholder:"<div>First page footer...</div>"}),W(),F("design:type",Object)],Gr.prototype,"printFooterFirstPage",void 0);_([z({defaultValue:"12mm"}),D({field_type:B.SELECT,label:"Page Margins",description:"Print page margins",validation:{options:[{label:"Compact (6mm)",value:"6mm"},{label:"Standard (12mm)",value:"12mm"},{label:"Large (20mm)",value:"20mm"},{label:"Formal (25mm)",value:"25mm"}]}}),W(),ae(),F("design:type",String)],Gr.prototype,"pageMargins",void 0);_([z({defaultValue:"60px"}),D({field_type:B.TEXT,label:"Print Header Height",description:"Height allocated for print header (CSS units: px, mm, etc.)",placeholder:"60px"}),W(),ae(),F("design:type",String)],Gr.prototype,"printHeaderHeight",void 0);_([z({defaultValue:"40px"}),D({field_type:B.TEXT,label:"Print Footer Height",description:"Height allocated for print footer (CSS units: px, mm, etc.)",placeholder:"40px"}),W(),ae(),F("design:type",String)],Gr.prototype,"printFooterHeight",void 0);_([z(),D({field_type:B.TEXT,label:"Print Background",description:"CSS background for all printed pages (color, gradient, or image)",placeholder:"linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%)"}),W(),ae(),F("design:type",String)],Gr.prototype,"printBackground",void 0);_([z(),D({field_type:B.TEXT,label:"Print Background (First Page)",description:"Different background for the first page only",placeholder:"url(/logo-watermark.png) no-repeat center, #ffffff"}),W(),ae(),F("design:type",String)],Gr.prototype,"printBackgroundFirstPage",void 0);Gr=_([Ft("PrintConfig","1.0.0")],Gr);let un=class extends xt{};_([z(),D({field_type:B.TEXT,label:"Page Slug",description:'URL-friendly page identifier (e.g., "about-us")',placeholder:"page-slug"}),W(),ae(),F("design:type",String)],un.prototype,"slug",void 0);_([z(),D({field_type:B.TEXT,label:"Page Name",description:"Human-readable page name",placeholder:"About Us"}),W(),ae(),F("design:type",String)],un.prototype,"name",void 0);_([z(),D({field_type:B.TEXTAREA,label:"Page Description",description:"Description of the page content (used for SEO)",placeholder:"Brief description of this page..."}),W(),ae(),F("design:type",String)],un.prototype,"description",void 0);_([z(),D({field_type:B.TEXT,label:"Page Title",description:"HTML title tag content (defaults to name if not provided)",placeholder:"Page Title | Site Name"}),W(),ae(),F("design:type",String)],un.prototype,"title",void 0);_([z(),D({field_type:B.TEXTAREA,label:"Meta Keywords",description:"SEO keywords (comma-separated)",placeholder:"keyword1, keyword2, keyword3"}),W(),ae(),F("design:type",String)],un.prototype,"metaKeywords",void 0);_([z(),D({field_type:B.TEXT,label:"Meta Author",description:"Page author information",placeholder:"Author Name"}),W(),ae(),F("design:type",String)],un.prototype,"metaAuthor",void 0);_([z(),D({field_type:B.URL,label:"Canonical URL",description:"Canonical URL for SEO (optional)",placeholder:"https://example.com/page"}),W(),ae(),F("design:type",String)],un.prototype,"canonicalUrl",void 0);_([z(),D({field_type:B.TEXTAREA,label:"Page Content",description:"Main page content - can include React components and HTML"}),W(),F("design:type",Object)],un.prototype,"children",void 0);_([z(),D({field_type:B.FORM,label:"Print Configuration",description:"Configuration for print mode behavior"}),W(),oo(),ao(()=>Gr),F("design:type",Gr)],un.prototype,"printConfig",void 0);_([z(),D({field_type:B.TEXT,label:"Layout Template",description:"Layout template identifier to use for this page",placeholder:"default, fullwidth, sidebar, etc."}),W(),ae(),F("design:type",String)],un.prototype,"layout",void 0);_([z(),D({field_type:B.TEXT,label:"Page Icon",description:"Icon identifier for page (used in navigation)",placeholder:"home, about, contact"}),W(),ae(),F("design:type",String)],un.prototype,"icon",void 0);_([z({defaultValue:!1}),D({field_type:B.BOOLEAN,label:"Requires Authentication",description:"Whether this page requires user authentication"}),W(),F("design:type",Boolean)],un.prototype,"requiresAuth",void 0);_([z(),D({field_type:B.TEXT,label:"Required Roles",description:"Comma-separated list of roles required to access this page",placeholder:"admin, user, moderator"}),W(),ae(),F("design:type",String)],un.prototype,"requiredRoles",void 0);_([z({defaultValue:!0}),D({field_type:B.BOOLEAN,label:"Show in Navigation",description:"Whether to include this page in navigation menus"}),W(),F("design:type",Boolean)],un.prototype,"showInNavigation",void 0);_([z({defaultValue:0}),D({field_type:B.NUMBER,label:"Navigation Priority",description:"Priority in navigation (lower numbers appear first)"}),W(),F("design:type",Number)],un.prototype,"navigationPriority",void 0);_([z({defaultValue:!0}),D({field_type:B.BOOLEAN,label:"Indexable",description:"Whether search engines should index this page"}),W(),F("design:type",Boolean)],un.prototype,"indexable",void 0);un=_([Ft("PageTemplate","1.0.0")],un);const TU=U0.create().withName("Control Panel").withId("com.qwickapps.control-panel").withVersion("1.0.0").withDefaultTheme("dark").withDefaultPalette("cosmic").withThemeSwitcher(!0).withPaletteSwitcher(!0).withDisplay("standalone").build(),lj=b.createContext(null);function kU({initialWidgets:e=[],children:t}){const[r,n]=b.useState(e.map(d=>({...d,visible:d.visible!==!1,priority:d.priority??100}))),o=b.useCallback(d=>{n(f=>f.some(v=>v.id===d.id)?f.map(v=>v.id===d.id?{...d,visible:d.visible!==!1,priority:d.priority??100}:v):[...f,{...d,visible:d.visible!==!1,priority:d.priority??100}])},[]),a=b.useCallback(d=>{n(f=>f.filter(h=>h.id!==d))},[]),c=b.useCallback((d,f)=>{n(h=>h.map(v=>v.id===d?{...v,visible:f??!v.visible}:v))},[]),u=b.useCallback(()=>r.filter(d=>d.visible!==!1).sort((d,f)=>(d.priority??100)-(f.priority??100)),[r]);return l.jsx(lj.Provider,{value:{widgets:r,registerWidget:o,unregisterWidget:a,toggleWidget:c,getVisibleWidgets:u},children:t})}function jU(){const e=b.useContext(lj);if(!e)throw new Error("useDashboardWidgets must be used within a DashboardWidgetProvider");return e}function PU(){const{getVisibleWidgets:e}=jU(),t=e();return t.length===0?null:l.jsx(l.Fragment,{children:t.map(r=>l.jsxs(ne,{sx:{mt:4},children:[r.title&&l.jsx(pe,{variant:"h6",sx:{mb:2,color:"var(--theme-text-primary)"},children:r.title}),r.component]},r.id))})}const cj=b.createContext(null);function IU({initialComponents:e=[],children:t}){const[r,n]=b.useState(()=>{const h=new Map;for(const v of e)h.set(v.name,v.component);return h}),o=b.useCallback((h,v)=>{n(m=>{const y=new Map(m);return y.set(h,v),y})},[]),a=b.useCallback(h=>{n(v=>{const m=new Map(v);for(const y of h)m.set(y.name,y.component);return m})},[]),c=b.useCallback(h=>r.get(h)??null,[r]),u=b.useCallback(h=>r.has(h),[r]),d=b.useCallback(()=>Array.from(r.keys()),[r]),f=b.useMemo(()=>({registerComponent:o,registerComponents:a,getComponent:c,hasComponent:u,getRegisteredNames:d}),[o,a,c,u,d]);return l.jsx(cj.Provider,{value:f,children:t})}function MU(){const e=b.useContext(cj);if(!e)throw new Error("useWidgetComponentRegistry must be used within a WidgetComponentRegistryProvider");return e}class RU{constructor(t=""){ks(this,"baseUrl");this.baseUrl=t}setBaseUrl(t){this.baseUrl=t}getBaseUrl(){return this.baseUrl}async _fetch(t,r){return fetch(t,{...r,credentials:"same-origin"})}async fetch(t,r){const n=`${this.baseUrl}/api${t.startsWith("/")?t:`/${t}`}`,o=await this._fetch(n,{...r,headers:{"Content-Type":"application/json",...r==null?void 0:r.headers}});if(!o.ok){const a=await o.json().catch(()=>({}));throw new Error(a.error||a.message||`Request failed: ${o.statusText}`)}return o.json()}async detectFeatures(){const[t,r,n]=await Promise.all([this.checkEndpoint("/api/users"),this.checkEndpoint("/api/bans"),this.checkEndpoint("/api/entitlements/available")]);let o=!0;if(n)try{o=(await this.getEntitlementsStatus()).readonly}catch{}return{users:t,bans:r,entitlements:n,entitlementsReadonly:o}}async checkEndpoint(t){try{return(await this._fetch(`${this.baseUrl}${t}`,{method:"HEAD"})).status!==404}catch{return!1}}async getUsers(t={}){const r=new URLSearchParams;t.limit&&r.set("limit",t.limit.toString()),t.page&&r.set("page",t.page.toString()),t.search&&r.set("q",t.search);const n=await this._fetch(`${this.baseUrl}/api/users?${r}`);if(!n.ok)throw new Error(`Users request failed: ${n.statusText}`);return n.json()}async getUserById(t){const r=await this._fetch(`${this.baseUrl}/api/users/${t}`);if(!r.ok)throw new Error(`User request failed: ${r.statusText}`);return r.json()}async getBans(){const t=await this._fetch(`${this.baseUrl}/api/bans`);if(!t.ok)throw new Error(`Bans request failed: ${t.statusText}`);return t.json()}async banUser(t,r,n){let o;if(n){const c=new Date(n),u=new Date;o=Math.max(0,Math.floor((c.getTime()-u.getTime())/1e3))}const a=await this._fetch(`${this.baseUrl}/api/bans/email/${encodeURIComponent(t)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({reason:r,duration:o})});if(!a.ok){const c=await a.json().catch(()=>({}));throw new Error(c.error||`Ban request failed: ${a.statusText}`)}}async unbanUser(t){const r=await this._fetch(`${this.baseUrl}/api/bans/email/${encodeURIComponent(t)}`,{method:"DELETE"});if(!r.ok)throw new Error(`Unban request failed: ${r.statusText}`)}async checkBan(t){const r=await this._fetch(`${this.baseUrl}/api/bans/email/${encodeURIComponent(t)}`);if(!r.ok)throw new Error(`Ban check failed: ${r.statusText}`);return{banned:(await r.json()).isBanned}}async getEntitlements(t){const r=await this._fetch(`${this.baseUrl}/api/entitlements/${encodeURIComponent(t)}`);if(!r.ok)throw new Error(`Entitlements request failed: ${r.statusText}`);return r.json()}async refreshEntitlements(t){const r=await this._fetch(`${this.baseUrl}/api/entitlements/${encodeURIComponent(t)}/refresh`,{method:"POST"});if(!r.ok)throw new Error(`Entitlements refresh failed: ${r.statusText}`);return r.json()}async checkEntitlement(t,r){const n=await this._fetch(`${this.baseUrl}/api/entitlements/${encodeURIComponent(t)}/check/${encodeURIComponent(r)}`);if(!n.ok)throw new Error(`Entitlement check failed: ${n.statusText}`);return n.json()}async getAvailableEntitlements(){const t=await this._fetch(`${this.baseUrl}/api/entitlements/available`);if(!t.ok)throw new Error(`Available entitlements request failed: ${t.statusText}`);return(await t.json()).entitlements}async grantEntitlement(t,r){const n=await this._fetch(`${this.baseUrl}/api/entitlements/${encodeURIComponent(t)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({entitlement:r})});if(!n.ok){const o=await n.json().catch(()=>({}));throw new Error(o.error||`Grant entitlement failed: ${n.statusText}`)}}async revokeEntitlement(t,r){const n=await this._fetch(`${this.baseUrl}/api/entitlements/${encodeURIComponent(t)}/${encodeURIComponent(r)}`,{method:"DELETE"});if(!n.ok)throw new Error(`Revoke entitlement failed: ${n.statusText}`)}async invalidateEntitlementCache(t){const r=await this._fetch(`${this.baseUrl}/api/entitlements/cache/${encodeURIComponent(t)}`,{method:"DELETE"});if(!r.ok)throw new Error(`Cache invalidation failed: ${r.statusText}`)}async getEntitlementsStatus(){const t=await this._fetch(`${this.baseUrl}/api/entitlements/status`);if(!t.ok)throw new Error(`Entitlements status request failed: ${t.statusText}`);return t.json()}async getHealth(){const t=await this._fetch(`${this.baseUrl}/api/health`);if(!t.ok)throw new Error(`Health check failed: ${t.statusText}`);return t.json()}async getInfo(){const t=await this._fetch(`${this.baseUrl}/api/info`);if(!t.ok)throw new Error(`Info request failed: ${t.statusText}`);return t.json()}async getDiagnostics(){const t=await this._fetch(`${this.baseUrl}/api/diagnostics`);if(!t.ok)throw new Error(`Diagnostics request failed: ${t.statusText}`);return t.json()}async getConfig(){const t=await this._fetch(`${this.baseUrl}/api/config`);if(!t.ok)throw new Error(`Config request failed: ${t.statusText}`);return t.json()}async getLogs(t={}){const r=new URLSearchParams;t.source&&r.set("source",t.source),t.level&&r.set("level",t.level),t.search&&r.set("search",t.search),t.limit&&r.set("limit",t.limit.toString()),t.page&&r.set("page",t.page.toString());const n=await this._fetch(`${this.baseUrl}/api/logs?${r}`);if(!n.ok)throw new Error(`Logs request failed: ${n.statusText}`);return n.json()}async getLogSources(){const t=await this._fetch(`${this.baseUrl}/api/logs/sources`);if(!t.ok)throw new Error(`Log sources request failed: ${t.statusText}`);return(await t.json()).sources}async getPlugins(){const t=await this._fetch(`${this.baseUrl}/api/plugins`);if(!t.ok)throw new Error(`Plugins request failed: ${t.statusText}`);return t.json()}async getPluginDetail(t){const r=await this._fetch(`${this.baseUrl}/api/plugins/${encodeURIComponent(t)}`);if(!r.ok)throw r.status===404?new Error(`Plugin not found: ${t}`):new Error(`Plugin detail request failed: ${r.statusText}`);return r.json()}async getUiContributions(){const t=await this._fetch(`${this.baseUrl}/api/ui-contributions`);if(!t.ok)throw new Error(`UI contributions request failed: ${t.statusText}`);return t.json()}async getAuthConfigStatus(){const t=await this._fetch(`${this.baseUrl}/api/auth/config/status`);if(!t.ok){if(t.status===404)return{state:"disabled",adapter:null};throw new Error(`Auth config status request failed: ${t.statusText}`)}return t.json()}async getAuthConfig(){const t=await this._fetch(`${this.baseUrl}/api/auth/config`);if(!t.ok){if(t.status===404)return{state:"disabled",adapter:null};throw new Error(`Auth config request failed: ${t.statusText}`)}return t.json()}async updateAuthConfig(t){const r=await this._fetch(`${this.baseUrl}/api/auth/config`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const n=await r.json().catch(()=>({}));throw new Error(n.error||`Auth config update failed: ${r.statusText}`)}return r.json()}async deleteAuthConfig(){const t=await this._fetch(`${this.baseUrl}/api/auth/config`,{method:"DELETE"});if(!t.ok){const r=await t.json().catch(()=>({}));throw new Error(r.error||`Auth config delete failed: ${t.statusText}`)}return t.json()}async testAuthProvider(t){const r=await this._fetch(`${this.baseUrl}/api/auth/test-provider`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const n=await r.json().catch(()=>({}));throw new Error(n.error||`Provider test failed: ${r.statusText}`)}return r.json()}async testCurrentAuthProvider(){const t=await this._fetch(`${this.baseUrl}/api/auth/test-current`,{method:"POST",headers:{"Content-Type":"application/json"}});if(!t.ok){const r=await t.json().catch(()=>({}));throw new Error(r.error||`Provider test failed: ${t.statusText}`)}return t.json()}async getRateLimitConfig(){const t=await this._fetch(`${this.baseUrl}/api/rate-limit/config`);if(!t.ok)throw new Error(`Rate limit config request failed: ${t.statusText}`);return t.json()}async updateRateLimitConfig(t){const r=await this._fetch(`${this.baseUrl}/api/rate-limit/config`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const n=await r.json().catch(()=>({}));throw new Error(n.error||`Rate limit config update failed: ${r.statusText}`)}return r.json()}async getNotificationsStats(){const t=await this._fetch(`${this.baseUrl}/api/notifications/stats`);if(!t.ok)throw new Error(`Notifications stats request failed: ${t.statusText}`);return t.json()}async getNotificationsClients(){const t=await this._fetch(`${this.baseUrl}/api/notifications/clients`);if(!t.ok)throw new Error(`Notifications clients request failed: ${t.statusText}`);return t.json()}async disconnectNotificationsClient(t){const r=await this._fetch(`${this.baseUrl}/api/notifications/clients/${encodeURIComponent(t)}`,{method:"DELETE"});if(!r.ok){const n=await r.json().catch(()=>({}));throw new Error(n.error||`Disconnect client failed: ${r.statusText}`)}return r.json()}async forceNotificationsReconnect(){const t=await this._fetch(`${this.baseUrl}/api/notifications/reconnect`,{method:"POST"});if(!t.ok){const r=await t.json().catch(()=>({}));throw new Error(r.error||`Force reconnect failed: ${t.statusText}`)}return t.json()}}const At=new RU;function AU({defaultOnly:e=!0,additionalWidgetIds:t=[]}){const[r,n]=b.useState([]),[o,a]=b.useState(!0),[c,u]=b.useState(null),{getComponent:d,hasComponent:f}=MU();if(b.useEffect(()=>{(async()=>{try{const m=await At.getUiContributions();n(m.widgets||[]),u(null)}catch(m){u(m instanceof Error?m.message:"Failed to fetch widgets")}finally{a(!1)}})()},[]),o)return l.jsx(ne,{sx:{display:"flex",justifyContent:"center",py:4},children:l.jsx(cr,{size:24})});if(c)return l.jsx(Kt,{severity:"error",sx:{mt:2},children:c});const h=r.filter(v=>e?v.showByDefault||t.includes(v.id):!0).filter(v=>f(v.component)?!0:(console.warn(`Widget "${v.id}" references unregistered component "${v.component}"`),!1)).sort((v,m)=>(v.priority??100)-(m.priority??100));return h.length===0?null:l.jsx(l.Fragment,{children:h.map(v=>{const m=d(v.component);return l.jsxs(ne,{sx:{mt:4},children:[v.title&&l.jsx(pe,{variant:"h6",sx:{mb:2,color:"var(--theme-text-primary)"},children:v.title}),m&&l.jsx(m,{})]},v.id)})})}function _U(e){switch(e){case"healthy":return l.jsx(Di,{sx:{fontSize:24,color:"var(--theme-success)"}});case"degraded":return l.jsx(ed,{sx:{fontSize:24,color:"var(--theme-warning)"}});case"unhealthy":return l.jsx(Wo,{sx:{fontSize:24,color:"var(--theme-error)"}});default:return l.jsx(ed,{sx:{fontSize:24,color:"var(--theme-text-secondary)"}})}}function eC(e){switch(e){case"healthy":return"var(--theme-success)";case"degraded":return"var(--theme-warning)";case"unhealthy":return"var(--theme-error)";default:return"var(--theme-text-secondary)"}}function LU(e){return e<=1?1:e===2?2:e===3?3:4}function OU(){const[e,t]=b.useState(null),[r,n]=b.useState(null);if(b.useEffect(()=>{const c=async()=>{try{const d=await At.getHealth();t(d),n(null)}catch(d){n(d instanceof Error?d.message:"Failed to fetch health")}};c();const u=setInterval(c,1e4);return()=>clearInterval(u)},[]),r)return l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",border:"1px solid var(--theme-error)"},children:l.jsx(gt,{children:l.jsx(vt,{variant:"body2",customColor:"var(--theme-error)",content:r})})});const o=e?Object.entries(e.checks):[];if(o.length===0)return l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsx(vt,{variant:"body2",customColor:"var(--theme-text-secondary)",content:"No health checks configured"})})});const a=LU(o.length);return l.jsx(kc,{columns:a,spacing:"medium",equalHeight:!0,children:o.map(([c,u])=>l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[_U(u.status),l.jsxs(ne,{sx:{flex:1,minWidth:0},children:[l.jsx(vt,{variant:"body1",fontWeight:"500",content:c.charAt(0).toUpperCase()+c.slice(1),customColor:"var(--theme-text-primary)"}),l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1,mt:.5},children:[l.jsx(qt,{label:u.status,size:"small",sx:{bgcolor:eC(u.status)+"20",color:eC(u.status),fontSize:"0.75rem",height:20}}),u.latency!==void 0&&l.jsx(vt,{variant:"caption",content:`${u.latency}ms`,customColor:"var(--theme-text-secondary)"})]})]})]})})},c))})}function NU(){const[e,t]=b.useState(null),[r,n]=b.useState(!0),[o,a]=b.useState(null);if(b.useEffect(()=>{(async()=>{try{const f=await At.fetch("/ai-proxy/config");t(f)}catch(f){a(f instanceof Error?f.message:"Failed to fetch integrations")}finally{n(!1)}})()},[]),r)return l.jsx(ne,{sx:{display:"flex",justifyContent:"center",py:2},children:l.jsx(cr,{size:20})});if(o)return l.jsx(Kt,{severity:"warning",sx:{py:.5,fontSize:13},children:"Unable to load integrations"});if(!e)return null;const c=e.integrations.filter(d=>d.configured).length,u=e.integrations.length;return l.jsxs(ne,{sx:{bgcolor:"var(--theme-surface)",borderRadius:2,p:2,border:"1px solid var(--theme-border)"},children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[l.jsxs(pe,{variant:"subtitle2",sx:{color:"var(--theme-text-secondary)"},children:[c," of ",u," configured"]}),l.jsxs(pe,{variant:"subtitle2",sx:{color:"var(--theme-text-secondary)"},children:[e.stats.totalRequests," requests"]})]}),l.jsx(ne,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:e.integrations.map(d=>l.jsxs(ne,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",p:1.5,bgcolor:"var(--theme-background)",borderRadius:1},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[d.configured?l.jsx(Di,{sx:{color:"var(--theme-success)",fontSize:18}}):l.jsx(Wo,{sx:{color:"var(--theme-text-secondary)",fontSize:18}}),l.jsxs(ne,{children:[l.jsx(pe,{variant:"body2",sx:{color:"var(--theme-text-primary)",fontWeight:500},children:d.name}),l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:d.description})]})]}),l.jsx(qt,{label:d.configured?"Connected":"Not Configured",size:"small",sx:{bgcolor:d.configured?"var(--theme-success)20":"transparent",color:d.configured?"var(--theme-success)":"var(--theme-text-secondary)",border:d.configured?"none":"1px solid var(--theme-border)",fontWeight:500,fontSize:11}})]},d.id))})]})}const $U={supertokens:"SuperTokens",auth0:"Auth0",supabase:"Supabase",basic:"Basic Auth"};function BU(){const[e,t]=b.useState(null),[r,n]=b.useState(!0),[o,a]=b.useState(null);if(b.useEffect(()=>{(async()=>{try{const f=await At.fetch("/auth/config/status");t(f)}catch(f){a(f instanceof Error?f.message:"Failed to fetch auth status")}finally{n(!1)}})()},[]),r)return l.jsx(ne,{sx:{display:"flex",justifyContent:"center",py:2},children:l.jsx(cr,{size:20})});if(o)return l.jsx(Kt,{severity:"warning",sx:{py:.5,fontSize:13},children:"Unable to load auth status"});if(!e)return null;const c=()=>{switch(e.state){case"enabled":return l.jsx(Di,{sx:{color:"var(--theme-success)",fontSize:32}});case"error":return l.jsx(Wo,{sx:{color:"var(--theme-error)",fontSize:32}});case"disabled":default:return l.jsx(_h,{sx:{color:"var(--theme-text-secondary)",fontSize:32}})}},u=()=>{switch(e.state){case"enabled":return"var(--theme-success)";case"error":return"var(--theme-error)";case"disabled":default:return"var(--theme-text-secondary)"}};return l.jsxs(ne,{sx:{bgcolor:"var(--theme-surface)",borderRadius:2,p:2,border:"1px solid var(--theme-border)"},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[c(),l.jsxs(ne,{sx:{flex:1},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[l.jsx(pe,{variant:"subtitle1",sx:{color:"var(--theme-text-primary)",fontWeight:600},children:e.state==="enabled"&&e.adapter?$U[e.adapter]||e.adapter:e.state==="disabled"?"Not Configured":"Configuration Error"}),l.jsx(qt,{label:e.state.toUpperCase(),size:"small",sx:{bgcolor:`${u()}20`,color:u(),fontWeight:600,fontSize:10,height:20}})]}),l.jsx(pe,{variant:"body2",sx:{color:"var(--theme-text-secondary)"},children:e.state==="enabled"?"Authentication is active":e.state==="disabled"?"Set AUTH_ADAPTER environment variable":e.error||"Check configuration"})]})]}),e.missingVars&&e.missingVars.length>0&&l.jsxs(Kt,{severity:"warning",sx:{mt:2,py:.5,"& .MuiAlert-message":{fontSize:12}},children:["Missing: ",e.missingVars.join(", ")]})]})}function Ha({icon:e,label:t,value:r,subValue:n,color:o="var(--theme-primary)"}){return l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",height:"100%"},children:l.jsx(gt,{sx:{py:1.5,"&:last-child":{pb:1.5}},children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1.5},children:[l.jsx(ne,{sx:{color:o},children:e}),l.jsxs(ne,{sx:{flex:1,minWidth:0},children:[l.jsx(vt,{variant:"h4",content:String(r),customColor:"var(--theme-text-primary)",fontWeight:"600"}),l.jsx(vt,{variant:"caption",content:t,customColor:"var(--theme-text-secondary)"}),n&&l.jsx(vt,{variant:"caption",content:n,customColor:"var(--theme-text-secondary)",sx:{display:"block",mt:.25}})]})]})})})}function Kl(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString()}function xv(e){return e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(0)}s`:e<36e5?`${(e/6e4).toFixed(0)}m`:`${(e/36e5).toFixed(1)}h`}function $l(e,t=12){return e.length>t?`${e.substring(0,t)}...`:e}function zU(){const[e,t]=b.useState(null),[r,n]=b.useState(null),[o,a]=b.useState(!0);if(b.useEffect(()=>{const d=async()=>{try{const h=await At.getNotificationsStats();t(h),n(null)}catch(h){h instanceof Error&&h.message.includes("404")?n("Notifications plugin not enabled"):n(h instanceof Error?h.message:"Failed to fetch stats")}finally{a(!1)}};d();const f=setInterval(d,5e3);return()=>clearInterval(f)},[]),o)return l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsx(Sd,{})})});if(r)return l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",border:"1px solid var(--theme-border)"},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(Hf,{sx:{color:"var(--theme-text-secondary)"}}),l.jsx(vt,{variant:"body2",customColor:"var(--theme-text-secondary)",content:r})]})})});if(!e)return null;const c=e.connectionHealth.isHealthy,u=c?"var(--theme-success)":"var(--theme-warning)";return l.jsxs(ne,{children:[l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:2},children:l.jsx(gt,{sx:{py:1,"&:last-child":{pb:1}},children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[c?l.jsx(ST,{sx:{color:u,fontSize:20}}):l.jsx(Hf,{sx:{color:u,fontSize:20}}),l.jsx(vt,{variant:"body2",content:c?"Connected":"Reconnecting...",customColor:u,fontWeight:"500"}),e.connectionHealth.isReconnecting&&l.jsx(qt,{label:`Attempt ${e.connectionHealth.reconnectAttempts}`,size:"small",sx:{bgcolor:"var(--theme-warning)20",color:"var(--theme-warning)",fontSize:"0.7rem",height:18}})]}),l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[l.jsx(vt,{variant:"caption",content:`${e.channels.length} channel${e.channels.length!==1?"s":""}`,customColor:"var(--theme-text-secondary)"}),e.lastEventAt&&l.jsx(vt,{variant:"caption",content:`Last event: ${xv(e.connectionHealth.timeSinceLastEvent)} ago`,customColor:"var(--theme-text-secondary)"})]})]})})}),l.jsxs(kc,{columns:4,spacing:"small",equalHeight:!0,children:[l.jsx(Ha,{icon:l.jsx(Wy,{sx:{fontSize:28}}),label:"Active Clients",value:e.currentConnections,subValue:`${e.totalConnections} total`,color:"var(--theme-primary)"}),l.jsx(Ha,{icon:l.jsx(ac,{sx:{fontSize:28}}),label:"By Device",value:e.clientsByType.device,subValue:`${e.clientsByType.user} by user`,color:"var(--theme-info)"}),l.jsx(Ha,{icon:l.jsx(p0,{sx:{fontSize:28}}),label:"Events Routed",value:Kl(e.eventsRouted),subValue:`${Kl(e.eventsProcessed)} processed`,color:"var(--theme-success)"}),l.jsx(Ha,{icon:l.jsx(Wo,{sx:{fontSize:28}}),label:"Dropped",value:Kl(e.eventsDroppedNoClients),subValue:`${e.eventsParseFailed} parse errors`,color:e.eventsDroppedNoClients>0?"var(--theme-warning)":"var(--theme-text-secondary)"})]})]})}function DU(){return[{name:"ServiceHealthWidget",component:OU},{name:"IntegrationStatusWidget",component:NU},{name:"AuthStatusWidget",component:BU},{name:"NotificationsStatsWidget",component:zU}]}function FU(e){switch(e){case"healthy":return l.jsx(Di,{sx:{color:"var(--theme-success)"}});case"degraded":return l.jsx(ed,{sx:{color:"var(--theme-warning)"}});case"unhealthy":return l.jsx(Wo,{sx:{color:"var(--theme-error)"}});default:return l.jsx(cr,{size:20})}}function ay(e){switch(e){case"healthy":return"var(--theme-success)";case"degraded":return"var(--theme-warning)";case"unhealthy":return"var(--theme-error)";default:return"var(--theme-text-secondary)"}}function HU(){var m,y;const e=Ev(),[t,r]=b.useState(null),[n,o]=b.useState(null),[a,c]=b.useState(!0),[u,d]=b.useState(null);if(b.useEffect(()=>{const x=async()=>{try{const[C,P]=await Promise.all([At.getHealth(),At.getInfo()]);r(C),o(P),d(null)}catch(C){d(C instanceof Error?C.message:"Failed to fetch data")}finally{c(!1)}};x();const w=setInterval(x,1e4);return()=>clearInterval(w)},[]),a)return l.jsx(ne,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:"50vh"},children:l.jsx(cr,{})});if(u)return l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",border:"1px solid var(--theme-error)"},children:l.jsx(gt,{children:l.jsx(pe,{color:"error",children:u})})});const f=t?Object.entries(t.checks):[],h=f.filter(([,x])=>x.status==="healthy").length,v=f.length;return l.jsxs(ne,{children:[l.jsx(pe,{variant:"h4",sx:{mb:1,color:"var(--theme-text-primary)"},children:"Dashboard"}),l.jsxs(pe,{variant:"body2",sx:{mb:4,color:"var(--theme-text-secondary)"},children:["Real-time overview of ",(n==null?void 0:n.product)||"your service"]}),l.jsx(yt,{sx:{mb:4,bgcolor:"var(--theme-surface)",border:`2px solid ${ay((t==null?void 0:t.status)||"unknown")}`},children:l.jsx(V_,{onClick:()=>e("/health"),children:l.jsxs(gt,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[FU((t==null?void 0:t.status)||"unknown"),l.jsxs(ne,{children:[l.jsxs(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)"},children:["Service Status: ",(m=t==null?void 0:t.status)==null?void 0:m.charAt(0).toUpperCase(),(y=t==null?void 0:t.status)==null?void 0:y.slice(1)]}),l.jsx(pe,{variant:"body2",sx:{color:"var(--theme-text-secondary)"},children:"Click to view detailed health information"})]})]}),l.jsx(qt,{label:`${h}/${v} checks passing`,sx:{bgcolor:ay((t==null?void 0:t.status)||"unknown")+"20",color:ay((t==null?void 0:t.status)||"unknown")}})]})})}),l.jsx(AU,{}),l.jsx(PU,{})]})}function tC(e){switch(e.toLowerCase()){case"error":return"var(--theme-error)";case"warn":case"warning":return"var(--theme-warning)";case"info":return"var(--theme-info)";case"debug":return"var(--theme-text-secondary)";default:return"var(--theme-text-primary)"}}function VU(){const[e,t]=b.useState([]),[r,n]=b.useState([]),[o,a]=b.useState(!0),[c,u]=b.useState(null),[d,f]=b.useState(""),[h,v]=b.useState(""),[m,y]=b.useState(""),[x,w]=b.useState(1),[C,P]=b.useState(0),k=50,[I,T]=b.useState(!1),[M,R]=b.useState("desc"),L=b.useRef(null),A={total:C,errors:e.filter(V=>V.level.toLowerCase()==="error").length,warnings:e.filter(V=>["warn","warning"].includes(V.level.toLowerCase())).length,info:e.filter(V=>V.level.toLowerCase()==="info").length,debug:e.filter(V=>V.level.toLowerCase()==="debug").length},H=b.useCallback(async()=>{a(!0);try{const V=await At.getLogs({source:d||void 0,level:h||void 0,search:m||void 0,limit:k,page:x}),O=[...V.logs].sort((U,K)=>{const Y=new Date(U.timestamp).getTime(),Z=new Date(K.timestamp).getTime();return M==="desc"?Z-Y:Y-Z});t(O),P(V.total),u(null)}catch(V){u(V instanceof Error?V.message:"Failed to fetch logs")}finally{a(!1)}},[d,h,m,x,M]),G=async()=>{try{const V=await At.getLogSources();n(V)}catch{}};b.useEffect(()=>{G()},[]),b.useEffect(()=>{H()},[H]),b.useEffect(()=>(I?L.current=setInterval(H,5e3):L.current&&(clearInterval(L.current),L.current=null),()=>{L.current&&clearInterval(L.current)}),[I,H]);const $=()=>{w(1),H()},j=(V,O)=>{O!==null&&R(O)},q=Math.ceil(C/k);return l.jsxs(ne,{children:[l.jsx(pe,{variant:"h4",sx:{mb:1,color:"var(--theme-text-primary)"},children:"Logs"}),l.jsx(pe,{variant:"body2",sx:{mb:4,color:"var(--theme-text-secondary)"},children:"View and search application logs"}),l.jsxs($n,{container:!0,spacing:2,sx:{mb:3},children:[l.jsx($n,{size:{xs:6,sm:3,md:2.4},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{sx:{py:1.5,px:2,"&:last-child":{pb:1.5}},children:[l.jsx(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:l.jsx(pe,{variant:"h5",sx:{color:"var(--theme-text-primary)",fontWeight:600},children:A.total.toLocaleString()})}),l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:"Total Logs"})]})})}),l.jsx($n,{size:{xs:6,sm:3,md:2.4},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{sx:{py:1.5,px:2,"&:last-child":{pb:1.5}},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(Wo,{sx:{color:"var(--theme-error)",fontSize:20}}),l.jsx(pe,{variant:"h5",sx:{color:"var(--theme-error)",fontWeight:600},children:A.errors})]}),l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:"Errors"})]})})}),l.jsx($n,{size:{xs:6,sm:3,md:2.4},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{sx:{py:1.5,px:2,"&:last-child":{pb:1.5}},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(ed,{sx:{color:"var(--theme-warning)",fontSize:20}}),l.jsx(pe,{variant:"h5",sx:{color:"var(--theme-warning)",fontWeight:600},children:A.warnings})]}),l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:"Warnings"})]})})}),l.jsx($n,{size:{xs:6,sm:3,md:2.4},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{sx:{py:1.5,px:2,"&:last-child":{pb:1.5}},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(Gy,{sx:{color:"var(--theme-info)",fontSize:20}}),l.jsx(pe,{variant:"h5",sx:{color:"var(--theme-info)",fontWeight:600},children:A.info})]}),l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:"Info"})]})})}),l.jsx($n,{size:{xs:6,sm:3,md:2.4},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{sx:{py:1.5,px:2,"&:last-child":{pb:1.5}},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(R7,{sx:{color:"var(--theme-text-secondary)",fontSize:20}}),l.jsx(pe,{variant:"h5",sx:{color:"var(--theme-text-primary)",fontWeight:600},children:A.debug})]}),l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:"Debug"})]})})})]}),l.jsx(yt,{sx:{mb:3,bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",gap:2,flexWrap:"wrap",alignItems:"center"},children:[r.length>0&&l.jsxs(_i,{size:"small",sx:{minWidth:150},children:[l.jsx(Ga,{sx:{color:"var(--theme-text-secondary)"},children:"Source"}),l.jsxs(aa,{value:d,label:"Source",onChange:V=>f(V.target.value),sx:{color:"var(--theme-text-primary)"},children:[l.jsx(Sr,{value:"",children:"All Sources"}),r.map(V=>l.jsx(Sr,{value:V.name,children:V.name},V.name))]})]}),l.jsxs(_i,{size:"small",sx:{minWidth:120},children:[l.jsx(Ga,{sx:{color:"var(--theme-text-secondary)"},children:"Level"}),l.jsxs(aa,{value:h,label:"Level",onChange:V=>v(V.target.value),sx:{color:"var(--theme-text-primary)"},children:[l.jsx(Sr,{value:"",children:"All Levels"}),l.jsx(Sr,{value:"error",children:"Error"}),l.jsx(Sr,{value:"warn",children:"Warning"}),l.jsx(Sr,{value:"info",children:"Info"}),l.jsx(Sr,{value:"debug",children:"Debug"})]})]}),l.jsx(Rt,{size:"small",placeholder:"Search logs...",value:m,onChange:V=>y(V.target.value),onKeyPress:V=>V.key==="Enter"&&$(),sx:{flex:1,minWidth:200,"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}},InputProps:{startAdornment:l.jsx(Oh,{sx:{mr:1,color:"var(--theme-text-secondary)"}})}}),l.jsxs(U8,{value:M,exclusive:!0,onChange:j,size:"small","aria-label":"sort order",children:[l.jsx(bS,{value:"desc","aria-label":"newest first",children:l.jsx(fr,{title:"Newest First",children:l.jsx(P7,{fontSize:"small"})})}),l.jsx(bS,{value:"asc","aria-label":"oldest first",children:l.jsx(fr,{title:"Oldest First",children:l.jsx(I7,{fontSize:"small"})})})]}),l.jsx(fr,{title:I?"Pause auto-refresh":"Enable auto-refresh (5s)",children:l.jsx(Qt,{onClick:()=>T(!I),sx:{color:I?"var(--theme-success)":"var(--theme-text-secondary)",bgcolor:I?"var(--theme-success)20":"transparent"},children:I?l.jsx(pB,{}):l.jsx(sc,{})})}),l.jsx(fr,{title:"Refresh",children:l.jsx(Qt,{onClick:H,sx:{color:"var(--theme-primary)"},children:l.jsx(Ys,{})})})]})})}),c&&l.jsx(yt,{sx:{mb:3,bgcolor:"var(--theme-surface)",border:"1px solid var(--theme-error)"},children:l.jsx(gt,{children:l.jsx(pe,{color:"error",children:c})})}),l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:o?l.jsx(ne,{sx:{display:"flex",justifyContent:"center",p:4},children:l.jsx(cr,{})}):e.length===0?l.jsx(gt,{children:l.jsx(pe,{sx:{color:"var(--theme-text-secondary)",textAlign:"center"},children:"No logs found"})}):l.jsxs(l.Fragment,{children:[l.jsx(Qa,{children:l.jsxs(Xa,{size:"small",children:[l.jsx(Ya,{children:l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)",width:180},children:"Timestamp"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)",width:100},children:"Level"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)",width:120},children:"Component"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Message"})]})}),l.jsx(Ka,{children:e.map((V,O)=>l.jsxs(Ur,{hover:!0,children:[l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)",fontFamily:"monospace",fontSize:"0.75rem"},children:new Date(V.timestamp).toLocaleString()}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:l.jsx(qt,{label:V.level.toUpperCase(),size:"small",sx:{bgcolor:tC(V.level)+"20",color:tC(V.level),fontSize:"0.65rem",height:20}})}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)",fontSize:"0.75rem"},children:V.namespace||"-"}),l.jsx(Ve,{sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)",fontFamily:"monospace",fontSize:"0.8rem",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:V.message})]},O))})]})}),q>1&&l.jsx(ne,{sx:{display:"flex",justifyContent:"center",p:2},children:l.jsx(DN,{count:q,page:x,onChange:(V,O)=>w(O),sx:{"& .MuiPaginationItem-root":{color:"var(--theme-text-primary)"}}})})]})})]})}function sy(e){if(e===0)return"0 B";const t=1024,r=["B","KB","MB","GB"],n=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/Math.pow(t,n)).toFixed(2))+" "+r[n]}function UU(e){const t=Math.floor(e/1e3),r=Math.floor(t/60),n=Math.floor(r/60),o=Math.floor(n/24);return o>0?`${o}d ${n%24}h ${r%60}m`:n>0?`${n}h ${r%60}m ${t%60}s`:r>0?`${r}m ${t%60}s`:`${t}s`}function WU(e,t=20){switch(e){case"healthy":return l.jsx(Di,{sx:{color:"var(--theme-success)",fontSize:t}});case"degraded":return l.jsx(ed,{sx:{color:"var(--theme-warning)",fontSize:t}});case"unhealthy":return l.jsx(Wo,{sx:{color:"var(--theme-error)",fontSize:t}});default:return l.jsx(cr,{size:t})}}function wu(e){switch(e){case"healthy":return"var(--theme-success)";case"degraded":return"var(--theme-warning)";case"unhealthy":return"var(--theme-error)";default:return"var(--theme-text-secondary)"}}function qU(e){return e===void 0?"-":e<1e3?`${e}ms`:`${(e/1e3).toFixed(2)}s`}function GU(){const[e,t]=b.useState(null),[r,n]=b.useState(null),[o,a]=b.useState(!0),[c,u]=b.useState(null),[d,f]=b.useState({open:!1,message:""}),h=async()=>{a(!0);try{const[y,x]=await Promise.all([At.getDiagnostics(),At.getHealth().catch(()=>null)]);t(y),n(x),u(null)}catch(y){u(y instanceof Error?y.message:"Failed to fetch diagnostics")}finally{a(!1)}};b.useEffect(()=>{h();const y=setInterval(h,3e4);return()=>clearInterval(y)},[]);const v=()=>{navigator.clipboard.writeText(JSON.stringify(e,null,2)),f({open:!0,message:"Diagnostics copied to clipboard"})};if(o&&!e)return l.jsx(ne,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:"50vh"},children:l.jsx(cr,{})});if(c)return l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",border:"1px solid var(--theme-error)"},children:l.jsx(gt,{children:l.jsx(pe,{color:"error",children:c})})});const m=e?e.system.memory.used/e.system.memory.total*100:0;return l.jsxs(ne,{children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1},children:[l.jsx(pe,{variant:"h4",sx:{color:"var(--theme-text-primary)"},children:"System"}),l.jsxs(ne,{sx:{display:"flex",gap:1},children:[l.jsx(fr,{title:"Copy diagnostics JSON",children:l.jsx(Qt,{onClick:v,sx:{color:"var(--theme-primary)"},children:l.jsx(u0,{})})}),l.jsx(fr,{title:"Refresh",children:l.jsx(Qt,{onClick:h,sx:{color:"var(--theme-primary)"},children:l.jsx(Ys,{})})})]})]}),l.jsx(pe,{variant:"body2",sx:{mb:4,color:"var(--theme-text-secondary)"},children:"System information and diagnostics"}),l.jsxs($n,{container:!0,spacing:3,children:[l.jsx($n,{size:{xs:12,md:6},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",height:"100%"},children:l.jsxs(gt,{children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1,mb:3},children:[l.jsx(mT,{sx:{color:"var(--theme-primary)"}}),l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)"},children:"System Information"})]}),l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",gap:2},children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between"},children:[l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"QwickApps Server"}),l.jsx(qt,{label:e!=null&&e.frameworkVersion?`v${e.frameworkVersion}`:"N/A",size:"small",sx:{bgcolor:"var(--theme-primary)20",color:"var(--theme-primary)"}})]}),l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between"},children:[l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"Node.js"}),l.jsx(qt,{label:e==null?void 0:e.system.nodeVersion,size:"small",sx:{bgcolor:"var(--theme-background)",color:"var(--theme-text-primary)"}})]}),l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between"},children:[l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"Platform"}),l.jsx(qt,{label:e==null?void 0:e.system.platform,size:"small",sx:{bgcolor:"var(--theme-background)",color:"var(--theme-text-primary)"}})]}),l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between"},children:[l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"Architecture"}),l.jsx(qt,{label:e==null?void 0:e.system.arch,size:"small",sx:{bgcolor:"var(--theme-background)",color:"var(--theme-text-primary)"}})]})]})]})})}),l.jsx($n,{size:{xs:12,md:6},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",height:"100%"},children:l.jsxs(gt,{children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1,mb:3},children:[l.jsx(vT,{sx:{color:"var(--theme-warning)"}}),l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)"},children:"Memory Usage"})]}),l.jsxs(ne,{sx:{mb:2},children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",mb:1},children:[l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"Heap Used"}),l.jsx(pe,{sx:{color:"var(--theme-text-primary)"},children:sy((e==null?void 0:e.system.memory.used)||0)})]}),l.jsx(Sd,{variant:"determinate",value:m,sx:{height:8,borderRadius:4,bgcolor:"var(--theme-background)","& .MuiLinearProgress-bar":{bgcolor:m>80?"var(--theme-error)":"var(--theme-warning)",borderRadius:4}}})]}),l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",gap:2},children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between"},children:[l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"Heap Total"}),l.jsx(pe,{sx:{color:"var(--theme-text-primary)"},children:sy((e==null?void 0:e.system.memory.total)||0)})]}),l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between"},children:[l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"Heap Free"}),l.jsx(pe,{sx:{color:"var(--theme-text-primary)"},children:sy((e==null?void 0:e.system.memory.free)||0)})]})]})]})})}),l.jsx($n,{size:{xs:12,md:6},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",height:"100%"},children:l.jsxs(gt,{children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1,mb:3},children:[l.jsx(f0,{sx:{color:"var(--theme-info)"}}),l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)"},children:"Service Info"})]}),l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",gap:2},children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between"},children:[l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"Product"}),l.jsx(pe,{sx:{color:"var(--theme-text-primary)"},children:e==null?void 0:e.product})]}),l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between"},children:[l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"Version"}),l.jsx(qt,{label:(e==null?void 0:e.version)||"N/A",size:"small",sx:{bgcolor:"var(--theme-primary)20",color:"var(--theme-primary)"}})]}),l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between"},children:[l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"Timestamp"}),l.jsx(pe,{sx:{color:"var(--theme-text-primary)",fontSize:"0.875rem"},children:e!=null&&e.timestamp?new Date(e.timestamp).toLocaleString():"N/A"})]})]})]})})}),l.jsx($n,{size:{xs:12,md:6},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",height:"100%"},children:l.jsxs(gt,{children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1,mb:3},children:[l.jsx(T7,{sx:{color:"var(--theme-success)"}}),l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)"},children:"Uptime"})]}),l.jsx(pe,{variant:"h3",sx:{color:"var(--theme-success)",mb:1},children:UU((e==null?void 0:e.uptime)||0)}),l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"Service has been running without interruption"})]})})}),r&&l.jsx($n,{size:{xs:12},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1,mb:3},children:[l.jsx(qy,{sx:{color:wu(r.status)}}),l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)"},children:"Health Checks"}),l.jsx(qt,{label:r.status,size:"small",sx:{bgcolor:wu(r.status)+"20",color:wu(r.status),textTransform:"capitalize",ml:"auto"}})]}),l.jsx(Qa,{children:l.jsxs(Xa,{size:"small",children:[l.jsx(Ya,{children:l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Check"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Status"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Latency"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Last Checked"})]})}),l.jsx(Ka,{children:Object.entries(r.checks).map(([y,x])=>l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[WU(x.status),l.jsx(pe,{fontWeight:500,children:y})]})}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:l.jsx(qt,{label:x.status,size:"small",sx:{bgcolor:wu(x.status)+"20",color:wu(x.status),textTransform:"capitalize"}})}),l.jsx(Ve,{sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:qU(x.latency)}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:new Date(x.lastChecked).toLocaleTimeString()})]},y))})]})})]})})}),l.jsx($n,{size:{xs:12},children:l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:2},children:"Raw Diagnostics JSON (for AI agents)"}),l.jsx(ne,{component:"pre",sx:{bgcolor:"var(--theme-background)",p:2,borderRadius:1,overflow:"auto",maxHeight:300,color:"var(--theme-text-primary)",fontFamily:"monospace",fontSize:"0.75rem"},children:JSON.stringify(e,null,2)})]})})})]}),l.jsx(XE,{open:d.open,autoHideDuration:2e3,onClose:()=>f({...d,open:!1}),anchorOrigin:{vertical:"bottom",horizontal:"center"},children:l.jsx(Kt,{severity:"success",variant:"filled",children:d.message})})]})}function XU(e){switch(e){case"active":return l.jsx(Di,{sx:{color:"var(--theme-success)",fontSize:20}});case"error":return l.jsx(Wo,{sx:{color:"var(--theme-error)",fontSize:20}});case"starting":return l.jsx(K7,{sx:{color:"var(--theme-warning)",fontSize:20}});case"stopped":return l.jsx(kB,{sx:{color:"var(--theme-text-secondary)",fontSize:20}});default:return null}}function rC(e){switch(e){case"active":return"var(--theme-success)";case"error":return"var(--theme-error)";case"starting":return"var(--theme-warning)";case"stopped":return"var(--theme-text-secondary)";default:return"var(--theme-text-secondary)"}}function KU({counts:e}){const t=[];return e.routes>0&&t.push(`${e.routes} route${e.routes>1?"s":""}`),e.menuItems>0&&t.push(`${e.menuItems} menu item${e.menuItems>1?"s":""}`),e.pages>0&&t.push(`${e.pages} page${e.pages>1?"s":""}`),e.widgets>0&&t.push(`${e.widgets} widget${e.widgets>1?"s":""}`),t.length===0?l.jsx(pe,{sx:{color:"var(--theme-text-secondary)",fontSize:"0.875rem"},children:"No contributions"}):l.jsx(pe,{sx:{color:"var(--theme-text-secondary)",fontSize:"0.875rem"},children:t.join(", ")})}function QU({plugin:e}){const[t,r]=b.useState(!1),[n,o]=b.useState(null),[a,c]=b.useState(!1),[u,d]=b.useState(null),f=async()=>{if(!t&&!n&&!u){c(!0),d(null);try{const v=await At.getPluginDetail(e.id);o(v.contributions)}catch(v){console.error("Failed to load plugin details:",v),d(v instanceof Error?v.message:"Failed to load details")}finally{c(!1)}}r(!t)},h=e.contributionCounts.routes>0||e.contributionCounts.menuItems>0||e.contributionCounts.pages>0||e.contributionCounts.widgets>0;return l.jsxs(l.Fragment,{children:[l.jsxs(Ur,{sx:{"& > *":{borderBottom:t?"none":void 0},cursor:h?"pointer":"default","&:hover":{bgcolor:h?"var(--theme-background)":void 0}},onClick:h?f:void 0,children:[l.jsx(Ve,{sx:{width:50,borderColor:"var(--theme-border)"},children:h&&l.jsx(Qt,{size:"small",sx:{color:"var(--theme-text-secondary)"},children:t?l.jsx(tB,{}):l.jsx(eB,{})})}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[XU(e.status),l.jsx(pe,{sx:{color:"var(--theme-text-primary)",fontWeight:500},children:e.name})]})}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:l.jsx(pe,{sx:{color:"var(--theme-text-secondary)",fontFamily:"monospace",fontSize:"0.875rem"},children:e.id})}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:e.version?l.jsx(qt,{label:`v${e.version}`,size:"small",sx:{bgcolor:"var(--theme-background)",color:"var(--theme-text-primary)"}}):l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:"-"})}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:l.jsx(qt,{label:e.status,size:"small",sx:{bgcolor:rC(e.status)+"20",color:rC(e.status),textTransform:"capitalize"}})}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:l.jsx(KU,{counts:e.contributionCounts})})]}),l.jsx(Ur,{children:l.jsx(Ve,{style:{paddingBottom:0,paddingTop:0},colSpan:6,sx:{borderColor:"var(--theme-border)"},children:l.jsx(Xu,{in:t,timeout:"auto",unmountOnExit:!0,children:l.jsx(ne,{sx:{py:2,px:4},children:a?l.jsx(ne,{sx:{display:"flex",justifyContent:"center",py:2},children:l.jsx(cr,{size:24})}):u?l.jsx(Kt,{severity:"error",sx:{mb:1},children:u}):n?l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",gap:2},children:[e.status==="error"&&e.error&&l.jsx(Kt,{severity:"error",sx:{mb:1},children:e.error}),n.routes.length>0&&l.jsxs(ne,{children:[l.jsxs(pe,{variant:"subtitle2",sx:{color:"var(--theme-text-primary)",mb:1},children:["Routes (",n.routes.length,")"]}),l.jsx(ne,{sx:{display:"flex",flexWrap:"wrap",gap:1},children:n.routes.map((v,m)=>l.jsx(qt,{label:`${v.method.toUpperCase()} ${v.path}`,size:"small",sx:{bgcolor:"var(--theme-background)",color:"var(--theme-text-primary)",fontFamily:"monospace",fontSize:"0.75rem"}},m))})]}),n.menuItems.length>0&&l.jsxs(ne,{children:[l.jsxs(pe,{variant:"subtitle2",sx:{color:"var(--theme-text-primary)",mb:1},children:["Menu Items (",n.menuItems.length,")"]}),l.jsx(ne,{sx:{display:"flex",flexWrap:"wrap",gap:1},children:n.menuItems.map(v=>l.jsx(qt,{label:`${v.label} (${v.route})`,size:"small",sx:{bgcolor:"var(--theme-background)",color:"var(--theme-text-primary)"}},v.id))})]}),n.pages.length>0&&l.jsxs(ne,{children:[l.jsxs(pe,{variant:"subtitle2",sx:{color:"var(--theme-text-primary)",mb:1},children:["Pages (",n.pages.length,")"]}),l.jsx(ne,{sx:{display:"flex",flexWrap:"wrap",gap:1},children:n.pages.map(v=>l.jsx(qt,{label:`${v.title||v.id} (${v.route})`,size:"small",sx:{bgcolor:"var(--theme-background)",color:"var(--theme-text-primary)"}},v.id))})]}),n.widgets.length>0&&l.jsxs(ne,{children:[l.jsxs(pe,{variant:"subtitle2",sx:{color:"var(--theme-text-primary)",mb:1},children:["Widgets (",n.widgets.length,")"]}),l.jsx(ne,{sx:{display:"flex",flexWrap:"wrap",gap:1},children:n.widgets.map(v=>l.jsx(qt,{label:v.title,size:"small",sx:{bgcolor:"var(--theme-background)",color:"var(--theme-text-primary)"}},v.id))})]})]}):null})})})})]})}function YU(){const[e,t]=b.useState([]),[r,n]=b.useState(!0),[o,a]=b.useState(null);if(b.useEffect(()=>{(async()=>{try{const f=await At.getPlugins();t(f.plugins),a(null)}catch(f){a(f instanceof Error?f.message:"Failed to fetch plugins")}finally{n(!1)}})()},[]),r)return l.jsx(ne,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:"50vh"},children:l.jsx(cr,{})});if(o)return l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",border:"1px solid var(--theme-error)"},children:l.jsx(gt,{children:l.jsx(pe,{color:"error",children:o})})});const c=e.filter(d=>d.status==="active").length,u=e.filter(d=>d.status==="error").length;return l.jsxs(ne,{children:[l.jsx(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1},children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[l.jsx(pe,{variant:"h4",sx:{color:"var(--theme-text-primary)"},children:"Plugins"}),l.jsx(qt,{icon:l.jsx(V7,{sx:{fontSize:16}}),label:`${c}/${e.length} active`,size:"small",sx:{bgcolor:c===e.length?"var(--theme-success)20":"var(--theme-warning)20",color:c===e.length?"var(--theme-success)":"var(--theme-warning)"}}),u>0&&l.jsx(qt,{icon:l.jsx(Wo,{sx:{fontSize:16}}),label:`${u} error${u>1?"s":""}`,size:"small",sx:{bgcolor:"var(--theme-error)20",color:"var(--theme-error)"}})]})}),l.jsx(pe,{variant:"body2",sx:{mb:4,color:"var(--theme-text-secondary)"},children:"View registered plugins and their contributions to the control panel"}),e.length===0?l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsx(pe,{sx:{color:"var(--theme-text-secondary)",textAlign:"center",py:4},children:"No plugins registered"})})}):l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(Qa,{children:l.jsxs(Xa,{children:[l.jsx(Ya,{children:l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)",width:50}}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Name"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"ID"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Version"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Status"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Contributions"})]})}),l.jsx(Ka,{children:e.map(d=>l.jsx(QU,{plugin:d},d.id))})]})})})]})}function JU({title:e="User Management",subtitle:t="Manage users, bans, and entitlements",features:r,headerActions:n,onUserSelect:o}){const[a,c]=b.useState({users:(r==null?void 0:r.users)??!0,bans:(r==null?void 0:r.bans)??!1,entitlements:(r==null?void 0:r.entitlements)??!1,entitlementsReadonly:(r==null?void 0:r.entitlementsReadonly)??!0}),[u,d]=b.useState(!!r),[f,h]=b.useState(0),[v,m]=b.useState([]),[y,x]=b.useState(0),[w,C]=b.useState(0),[P,k]=b.useState(25),[I,T]=b.useState(""),[M,R]=b.useState({}),[L,A]=b.useState([]),[H,G]=b.useState(0),[$,j]=b.useState(!0),[q,V]=b.useState(null),[O,U]=b.useState(null),[K,Y]=b.useState(!1),[Z,Q]=b.useState({email:"",reason:"",expiresAt:""}),[X,re]=b.useState(!1),[de,J]=b.useState(""),[oe,ee]=b.useState(!1),[he,Ce]=b.useState(!1),[ye,ce]=b.useState(null),[Fe,Le]=b.useState(null),[Ne,$e]=b.useState([]),[Me,Xe]=b.useState(""),[dt,le]=b.useState(!1);b.useEffect(()=>{r||At.detectFeatures().then(ie=>{c(ie),d(!0)}).catch(()=>{d(!0)})},[r]),b.useEffect(()=>{u&&a.entitlements&&!a.entitlementsReadonly&&At.getAvailableEntitlements().then($e).catch(()=>{})},[u,a.entitlements,a.entitlementsReadonly]);const Ye=b.useCallback(async()=>{var ie;if(a.users){j(!0);try{const Pe=await At.getUsers({limit:P,page:w,search:I||void 0});if(m(Pe.users||[]),x(Pe.total),V(null),a.entitlements&&((ie=Pe.users)!=null&&ie.length)){const Be={};await Promise.all(Pe.users.map(async He=>{try{const Et=await At.getEntitlements(He.email);Be[He.email]=Et.entitlements.length}catch{Be[He.email]=0}})),R(He=>({...He,...Be}))}}catch(Pe){V(Pe instanceof Error?Pe.message:"Failed to fetch users")}finally{j(!1)}}},[a.users,a.entitlements,w,P,I]),We=b.useCallback(async()=>{if(a.bans){j(!0);try{const ie=await At.getBans();A(ie.bans||[]),G(ie.total),V(null)}catch(ie){V(ie instanceof Error?ie.message:"Failed to fetch bans")}finally{j(!1)}}},[a.bans]);b.useEffect(()=>{u&&(f===0&&a.users?Ye():f===1&&a.bans&&We())},[f,u,a.users,a.bans,Ye,We]),b.useEffect(()=>{u&&a.bans&&We()},[u,a.bans,We]),b.useEffect(()=>{if(!u)return;const ie=setTimeout(()=>{f===0&&a.users&&(C(0),Ye())},300);return()=>clearTimeout(ie)},[I,f,u,a.users,Ye]);const ft=async()=>{try{await At.banUser(Z.email,Z.reason,Z.expiresAt||void 0),U("User banned successfully"),Y(!1),Q({email:"",reason:"",expiresAt:""}),We()}catch(ie){V(ie instanceof Error?ie.message:"Failed to ban user")}},ze=async ie=>{if(confirm("Unban this user?"))try{await At.unbanUser(ie),U("User unbanned successfully"),We()}catch{V("Failed to unban user")}},Nt=async()=>{if(!de.trim()){Le("Please enter an email address");return}ee(!0),Le(null),ce(null);try{const ie=await At.getEntitlements(de);ce(ie)}catch(ie){Le(ie instanceof Error?ie.message:"Failed to lookup entitlements")}finally{ee(!1)}},ht=async()=>{if(ye){Ce(!0);try{const ie=await At.refreshEntitlements(de);ce(ie)}catch{Le("Failed to refresh entitlements")}finally{Ce(!1)}}},fe=async()=>{if(!(!Me||!ye)){le(!0);try{await At.grantEntitlement(ye.identifier,Me),U(`Entitlement "${Me}" granted`),Xe("");const ie=await At.refreshEntitlements(ye.identifier);ce(ie),R(Pe=>({...Pe,[ye.identifier]:ie.entitlements.length}))}catch(ie){V(ie instanceof Error?ie.message:"Failed to grant entitlement")}finally{le(!1)}}},we=async ie=>{if(ye&&confirm(`Revoke "${ie}" from ${ye.identifier}?`))try{await At.revokeEntitlement(ye.identifier,ie),U(`Entitlement "${ie}" revoked`);const Pe=await At.refreshEntitlements(ye.identifier);ce(Pe),R(Be=>({...Be,[ye.identifier]:Pe.entitlements.length}))}catch(Pe){V(Pe instanceof Error?Pe.message:"Failed to revoke entitlement")}},je=ie=>{ie&&(J(ie),ee(!0),Le(null),ce(null),At.getEntitlements(ie).then(ce).catch(Pe=>Le(Pe instanceof Error?Pe.message:"Failed to lookup entitlements")).finally(()=>ee(!1))),re(!0)},Re=ie=>ie?new Date(ie).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):"Never",qe=Ne.filter(ie=>!(ye!=null&&ye.entitlements.includes(ie.name))),et=[];return a.users&&et.push({label:"Users",count:y}),a.bans&&et.push({label:"Banned",count:H}),u?l.jsxs(ne,{children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[l.jsxs(ne,{children:[l.jsx(vt,{variant:"h4",content:e,customColor:"var(--theme-text-primary)"}),l.jsx(vt,{variant:"body2",content:t,customColor:"var(--theme-text-secondary)"})]}),l.jsxs(ne,{sx:{display:"flex",gap:1},children:[n,a.entitlements&&l.jsx(Nr,{variant:"outlined",icon:"person_search",label:"Lookup Entitlements",onClick:()=>je()}),a.bans&&l.jsx(Nr,{variant:"primary",color:"error",icon:"block",label:"Ban User",onClick:()=>Y(!0)})]})]}),$&&l.jsx(Sd,{sx:{mb:2}}),q&&l.jsx(Kt,{severity:"error",onClose:()=>V(null),sx:{mb:2},children:q}),O&&l.jsx(Kt,{severity:"success",onClose:()=>U(null),sx:{mb:2},children:O}),a.users&&l.jsxs(kc,{columns:a.bans?3:2,spacing:"medium",sx:{mb:3},equalHeight:!0,children:[l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[l.jsx(ac,{sx:{fontSize:40,color:"var(--theme-primary)"}}),l.jsxs(ne,{children:[l.jsx(vt,{variant:"h4",content:y.toLocaleString(),customColor:"var(--theme-text-primary)"}),l.jsx(vt,{variant:"body2",content:"Total Users",customColor:"var(--theme-text-secondary)"})]})]})})}),a.entitlements&&l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[l.jsx(ql,{sx:{fontSize:40,color:"var(--theme-success)"}}),l.jsxs(ne,{children:[l.jsx(vt,{variant:"body1",fontWeight:"500",content:"Entitlements",customColor:"var(--theme-text-primary)"}),l.jsx(vt,{variant:"body2",content:a.entitlementsReadonly?"Read-only Mode":"Plugin Active",customColor:a.entitlementsReadonly?"var(--theme-warning)":"var(--theme-success)"})]})]})})}),a.bans&&l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[l.jsx(_h,{sx:{fontSize:40,color:H>0?"var(--theme-error)":"var(--theme-text-secondary)"}}),l.jsxs(ne,{children:[l.jsx(vt,{variant:"h4",content:H.toString(),customColor:H>0?"var(--theme-error)":"var(--theme-text-primary)"}),l.jsx(vt,{variant:"body2",content:"Banned Users",customColor:"var(--theme-text-secondary)"})]})]})})})]}),l.jsxs(yt,{sx:{bgcolor:"var(--theme-surface)"},children:[et.length>1&&l.jsx(A8,{value:f,onChange:(ie,Pe)=>h(Pe),sx:{borderBottom:1,borderColor:"var(--theme-border)",px:2},children:et.map((ie,Pe)=>l.jsx(P$,{label:`${ie.label}${ie.count!==void 0?` (${ie.count})`:""}`},Pe))}),l.jsxs(gt,{sx:{p:0},children:[l.jsx(ne,{sx:{p:2,borderBottom:1,borderColor:"var(--theme-border)"},children:l.jsx(Rt,{size:"small",placeholder:"Search by email or name...",value:I,onChange:ie=>T(ie.target.value),InputProps:{startAdornment:l.jsx(Bf,{position:"start",children:l.jsx(Oh,{sx:{color:"var(--theme-text-secondary)"}})})},sx:{minWidth:300}})}),f===0&&a.users&&l.jsxs(l.Fragment,{children:[l.jsx(Qa,{children:l.jsxs(Xa,{children:[l.jsx(Ya,{children:l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"ID"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Name"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Email"}),a.entitlements&&l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},align:"center",children:"Entitlements"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Created"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},align:"right",children:"Actions"})]})}),l.jsxs(Ka,{children:[v.map(ie=>l.jsxs(Ur,{hover:!0,sx:{cursor:o?"pointer":"default"},onClick:()=>o==null?void 0:o(ie),children:[l.jsxs(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)",fontFamily:"monospace",fontSize:"0.75rem"},children:[ie.id.substring(0,8),"..."]}),l.jsx(Ve,{sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:l.jsx(vt,{variant:"body1",content:ie.name||"--",fontWeight:"500"})}),l.jsx(Ve,{sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:ie.email}),a.entitlements&&l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},align:"center",children:l.jsx(qt,{size:"small",icon:l.jsx(ql,{sx:{fontSize:14}}),label:M[ie.email]??"...",sx:{bgcolor:"var(--theme-primary)20",color:"var(--theme-primary)"}})}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:Re(ie.created_at)}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},align:"right",children:a.entitlements&&l.jsx(fr,{title:"View entitlements",children:l.jsx(Qt,{size:"small",onClick:Pe=>{Pe.stopPropagation(),je(ie.email)},children:l.jsx(ql,{fontSize:"small"})})})})]},ie.id)),v.length===0&&!$&&l.jsx(Ur,{children:l.jsx(Ve,{colSpan:a.entitlements?6:5,align:"center",sx:{py:4,color:"var(--theme-text-secondary)"},children:I?"No users match your search":"No users found"})})]})]})}),l.jsx(p8,{component:"div",count:y,page:w,onPageChange:(ie,Pe)=>C(Pe),rowsPerPage:P,onRowsPerPageChange:ie=>{k(parseInt(ie.target.value,10)),C(0)},rowsPerPageOptions:[10,25,50,100],sx:{borderTop:1,borderColor:"var(--theme-border)"}})]}),f===1&&a.bans&&l.jsx(Qa,{children:l.jsxs(Xa,{children:[l.jsx(Ya,{children:l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Email"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Reason"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Banned At"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Expires"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Banned By"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},align:"right",children:"Actions"})]})}),l.jsxs(Ka,{children:[L.map(ie=>l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:l.jsx(vt,{variant:"body1",content:ie.email,fontWeight:"500"})}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)",maxWidth:200},children:l.jsx(vt,{variant:"body2",content:ie.reason,noWrap:!0})}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:Re(ie.banned_at)}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:l.jsx(qt,{size:"small",label:ie.expires_at?Re(ie.expires_at):"Permanent",sx:{bgcolor:ie.expires_at?"var(--theme-warning)20":"var(--theme-error)20",color:ie.expires_at?"var(--theme-warning)":"var(--theme-error)"}})}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:ie.banned_by}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},align:"right",children:l.jsx(Nr,{buttonSize:"small",variant:"text",color:"success",icon:"check_circle",label:"Unban",onClick:()=>ze(ie.email)})})]},ie.id)),L.length===0&&!$&&l.jsx(Ur,{children:l.jsx(Ve,{colSpan:6,align:"center",sx:{py:4,color:"var(--theme-text-secondary)"},children:"No users are currently banned"})})]})]})})]})]}),a.bans&&l.jsxs(Nu,{open:K,onClose:()=>Y(!1),maxWidth:"sm",fullWidth:!0,children:[l.jsx($u,{children:"Ban User"}),l.jsx(Bu,{children:l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[l.jsx(Rt,{label:"Email",fullWidth:!0,value:Z.email,onChange:ie=>Q({...Z,email:ie.target.value}),placeholder:"Enter user email"}),l.jsx(Rt,{label:"Reason",fullWidth:!0,multiline:!0,rows:3,value:Z.reason,onChange:ie=>Q({...Z,reason:ie.target.value}),placeholder:"Enter reason for ban"}),l.jsx(Rt,{label:"Expiration (Optional)",type:"datetime-local",fullWidth:!0,value:Z.expiresAt,onChange:ie=>Q({...Z,expiresAt:ie.target.value}),InputLabelProps:{shrink:!0},helperText:"Leave empty for permanent ban"})]})}),l.jsxs(zu,{children:[l.jsx(Nr,{variant:"text",label:"Cancel",onClick:()=>{Y(!1),Q({email:"",reason:"",expiresAt:""})}}),l.jsx(Nr,{variant:"primary",color:"error",label:"Ban User",onClick:ft,disabled:!Z.email||!Z.reason})]})]}),a.entitlements&&l.jsxs(Nu,{open:X,onClose:()=>re(!1),maxWidth:"md",fullWidth:!0,children:[l.jsx($u,{children:"User Entitlements"}),l.jsx(Bu,{children:l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[l.jsxs(ne,{sx:{display:"flex",gap:1},children:[l.jsx(Rt,{label:"Email",fullWidth:!0,value:de,onChange:ie=>J(ie.target.value),placeholder:"Enter user email",onKeyDown:ie=>ie.key==="Enter"&&Nt()}),l.jsx(Nr,{variant:"primary",icon:"search",label:"Lookup",onClick:Nt,disabled:oe})]}),oe&&l.jsx(ne,{sx:{display:"flex",justifyContent:"center",py:4},children:l.jsx(cr,{})}),Fe&&l.jsx(Kt,{severity:"error",children:Fe}),ye&&l.jsxs(ne,{children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2},children:[l.jsxs(ne,{children:[l.jsx(vt,{variant:"h6",content:ye.identifier,customColor:"var(--theme-text-primary)"}),l.jsx(vt,{variant:"body2",content:`Source: ${ye.source}`,customColor:"var(--theme-text-secondary)"})]}),l.jsx(Nr,{variant:"outlined",icon:"refresh",label:he?"Refreshing...":"Refresh",onClick:ht,disabled:he,buttonSize:"small"})]}),!a.entitlementsReadonly&&qe.length>0&&l.jsxs(ne,{sx:{display:"flex",gap:1,mb:2,p:2,bgcolor:"var(--theme-background)",borderRadius:1},children:[l.jsx(d_,{size:"small",options:qe,getOptionLabel:ie=>ie.name,value:qe.find(ie=>ie.name===Me)||null,onChange:(ie,Pe)=>Xe((Pe==null?void 0:Pe.name)||""),renderInput:ie=>l.jsx(Rt,{...ie,label:"Grant Entitlement",placeholder:"Select entitlement"}),sx:{flex:1}}),l.jsx(Nr,{variant:"primary",icon:"add",label:"Grant",onClick:fe,disabled:!Me||dt,buttonSize:"small"})]}),l.jsx(vt,{variant:"subtitle2",content:"Current Entitlements",customColor:"var(--theme-text-secondary)",style:{marginBottom:"8px"}}),ye.entitlements.length===0?l.jsx(vt,{variant:"body2",content:"No entitlements found",customColor:"var(--theme-text-secondary)"}):l.jsx(ne,{sx:{display:"flex",flexWrap:"wrap",gap:1},children:ye.entitlements.map((ie,Pe)=>l.jsx(qt,{icon:l.jsx(Di,{sx:{fontSize:16}}),label:ie,onDelete:a.entitlementsReadonly?void 0:()=>we(ie),deleteIcon:l.jsx(Lh,{sx:{fontSize:16}}),sx:{bgcolor:"var(--theme-success)20",color:"var(--theme-success)","& .MuiChip-deleteIcon":{color:"var(--theme-error)","&:hover":{color:"var(--theme-error)"}}}},Pe))}),l.jsxs(ne,{sx:{mt:2,pt:2,borderTop:1,borderColor:"var(--theme-border)"},children:[l.jsx(vt,{variant:"caption",content:`Data from: ${ye.source==="cache"?"Cache":"Source"}`,customColor:"var(--theme-text-secondary)"}),ye.cachedAt&&l.jsx(vt,{variant:"caption",content:` | Cached: ${Re(ye.cachedAt)}`,customColor:"var(--theme-text-secondary)"}),a.entitlementsReadonly&&l.jsx(vt,{variant:"caption",content:" | Read-only mode (modifications disabled)",customColor:"var(--theme-warning)"})]})]})]})}),l.jsx(zu,{children:l.jsx(Nr,{variant:"text",label:"Close",onClick:()=>re(!1)})})]})]}):l.jsx(ne,{sx:{display:"flex",justifyContent:"center",py:8},children:l.jsx(cr,{})})}function ZU({title:e="Entitlements",subtitle:t="Manage available entitlements",headerActions:r}){var de;const[n,o]=b.useState(null),[a,c]=b.useState(!0),[u,d]=b.useState([]),[f,h]=b.useState([]),[v,m]=b.useState(!0),[y,x]=b.useState(null),[w,C]=b.useState(null),[P,k]=b.useState(""),[I,T]=b.useState(!1),[M,R]=b.useState(!1),[L,A]=b.useState(!1),[H,G]=b.useState(null),[$,j]=b.useState({name:"",category:"",description:""}),[q,V]=b.useState(!1);b.useEffect(()=>{At.getEntitlementsStatus().then(o).catch(J=>x(J instanceof Error?J.message:"Failed to get status")).finally(()=>c(!1))},[]);const O=b.useCallback(async()=>{m(!0);try{const J=await At.getAvailableEntitlements();d(J),x(null)}catch(J){x(J instanceof Error?J.message:"Failed to fetch entitlements")}finally{m(!1)}},[]);b.useEffect(()=>{O()},[O]),b.useEffect(()=>{if(!P.trim())h(u);else{const J=P.toLowerCase();h(u.filter(oe=>{var ee,he;return oe.name.toLowerCase().includes(J)||((ee=oe.category)==null?void 0:ee.toLowerCase().includes(J))||((he=oe.description)==null?void 0:he.toLowerCase().includes(J))}))}},[u,P]);const U=[...new Set(u.map(J=>J.category||"Uncategorized"))],K=async()=>{if(!$.name.trim()){x("Name is required");return}V(!0);try{C(`Entitlement "${$.name}" created`),T(!1),j({name:"",category:"",description:""}),O()}catch(J){x(J instanceof Error?J.message:"Failed to create entitlement")}finally{V(!1)}},Y=async()=>{if(H){V(!0);try{C(`Entitlement "${H.name}" updated`),R(!1),G(null),O()}catch(J){x(J instanceof Error?J.message:"Failed to update entitlement")}finally{V(!1)}}},Z=async()=>{if(H){V(!0);try{C(`Entitlement "${H.name}" deleted`),A(!1),G(null),O()}catch(J){x(J instanceof Error?J.message:"Failed to delete entitlement")}finally{V(!1)}}},Q=J=>{G(J),R(!0)},X=J=>{G(J),A(!0)},re=(n==null?void 0:n.readonly)??!0;return a?l.jsx(ne,{sx:{display:"flex",justifyContent:"center",py:8},children:l.jsx(cr,{})}):l.jsxs(ne,{children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:3},children:[l.jsxs(ne,{children:[l.jsx(vt,{variant:"h4",content:e,customColor:"var(--theme-text-primary)"}),l.jsx(vt,{variant:"body2",content:t,customColor:"var(--theme-text-secondary)"})]}),l.jsxs(ne,{sx:{display:"flex",gap:1},children:[r,!re&&l.jsx(Nr,{variant:"primary",icon:"add",label:"Add Entitlement",onClick:()=>T(!0)})]})]}),v&&l.jsx(Sd,{sx:{mb:2}}),y&&l.jsx(Kt,{severity:"error",onClose:()=>x(null),sx:{mb:2},children:y}),w&&l.jsx(Kt,{severity:"success",onClose:()=>C(null),sx:{mb:2},children:w}),l.jsxs(kc,{columns:3,spacing:"medium",sx:{mb:3},equalHeight:!0,children:[l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[l.jsx(ql,{sx:{fontSize:40,color:"var(--theme-primary)"}}),l.jsxs(ne,{children:[l.jsx(vt,{variant:"h4",content:u.length.toString(),customColor:"var(--theme-text-primary)"}),l.jsx(vt,{variant:"body2",content:"Total Entitlements",customColor:"var(--theme-text-secondary)"})]})]})})}),l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[l.jsx(ne,{sx:{width:40,height:40,borderRadius:1,bgcolor:"var(--theme-primary)20",display:"flex",alignItems:"center",justifyContent:"center"},children:l.jsx(vt,{variant:"h6",content:U.length.toString(),customColor:"var(--theme-primary)"})}),l.jsxs(ne,{children:[l.jsx(vt,{variant:"body1",fontWeight:"500",content:"Categories",customColor:"var(--theme-text-primary)"}),l.jsx(vt,{variant:"body2",content:U.slice(0,3).join(", "),customColor:"var(--theme-text-secondary)"})]})]})})}),l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[re?l.jsx(Xy,{sx:{fontSize:40,color:"var(--theme-warning)"}}):l.jsx(Ff,{sx:{fontSize:40,color:"var(--theme-success)"}}),l.jsxs(ne,{children:[l.jsx(vt,{variant:"body1",fontWeight:"500",content:re?"Read-only":"Editable",customColor:re?"var(--theme-warning)":"var(--theme-success)"}),l.jsx(vt,{variant:"body2",content:`Source: ${((de=n==null?void 0:n.sources[0])==null?void 0:de.name)||"Unknown"}`,customColor:"var(--theme-text-secondary)"})]})]})})})]}),l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{sx:{p:0},children:[l.jsx(ne,{sx:{p:2,borderBottom:1,borderColor:"var(--theme-border)"},children:l.jsx(Rt,{size:"small",placeholder:"Search entitlements...",value:P,onChange:J=>k(J.target.value),InputProps:{startAdornment:l.jsx(Bf,{position:"start",children:l.jsx(Oh,{sx:{color:"var(--theme-text-secondary)"}})})},sx:{minWidth:300}})}),l.jsx(Qa,{children:l.jsxs(Xa,{children:[l.jsx(Ya,{children:l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Name"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Category"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Description"}),!re&&l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},align:"right",children:"Actions"})]})}),l.jsxs(Ka,{children:[f.map(J=>l.jsxs(Ur,{hover:!0,children:[l.jsx(Ve,{sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(ql,{sx:{fontSize:18,color:"var(--theme-primary)"}}),l.jsx(vt,{variant:"body1",content:J.name,fontWeight:"500"})]})}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:J.category?l.jsx(qt,{size:"small",label:J.category,sx:{bgcolor:"var(--theme-primary)20",color:"var(--theme-primary)"}}):l.jsx(vt,{variant:"body2",content:"--",customColor:"var(--theme-text-secondary)"})}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)",maxWidth:300},children:J.description||"--"}),!re&&l.jsxs(Ve,{sx:{borderColor:"var(--theme-border)"},align:"right",children:[l.jsx(fr,{title:"Edit",children:l.jsx(Qt,{size:"small",onClick:()=>Q(J),children:l.jsx(Ff,{fontSize:"small"})})}),l.jsx(fr,{title:"Delete",children:l.jsx(Qt,{size:"small",onClick:()=>X(J),sx:{color:"var(--theme-error)"},children:l.jsx(Lh,{fontSize:"small"})})})]})]},J.id)),f.length===0&&!v&&l.jsx(Ur,{children:l.jsx(Ve,{colSpan:re?3:4,align:"center",sx:{py:4,color:"var(--theme-text-secondary)"},children:P?"No entitlements match your search":"No entitlements defined"})})]})]})})]})}),n&&n.sources.length>0&&l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mt:3},children:l.jsxs(gt,{children:[l.jsx(vt,{variant:"subtitle2",content:"Entitlement Sources",customColor:"var(--theme-text-secondary)",style:{marginBottom:"12px"}}),l.jsx(ne,{sx:{display:"flex",flexDirection:"column",gap:1},children:n.sources.map((J,oe)=>l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[l.jsx(qt,{size:"small",label:J.primary?"Primary":"Additional",sx:{bgcolor:J.primary?"var(--theme-primary)20":"var(--theme-text-secondary)20",color:J.primary?"var(--theme-primary)":"var(--theme-text-secondary)"}}),l.jsx(vt,{variant:"body1",content:J.name,fontWeight:"500",customColor:"var(--theme-text-primary)"}),J.description&&l.jsx(vt,{variant:"body2",content:`- ${J.description}`,customColor:"var(--theme-text-secondary)"}),J.readonly&&l.jsx(qt,{size:"small",icon:l.jsx(Xy,{sx:{fontSize:14}}),label:"Read-only",sx:{bgcolor:"var(--theme-warning)20",color:"var(--theme-warning)"}})]},oe))}),n.cacheEnabled&&l.jsx(ne,{sx:{mt:2,pt:2,borderTop:1,borderColor:"var(--theme-border)"},children:l.jsx(vt,{variant:"caption",content:`Caching: Enabled (TTL: ${n.cacheTtl}s)`,customColor:"var(--theme-text-secondary)"})})]})}),!re&&l.jsxs(Nu,{open:I,onClose:()=>T(!1),maxWidth:"sm",fullWidth:!0,children:[l.jsx($u,{children:"Add Entitlement"}),l.jsx(Bu,{children:l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[l.jsx(Rt,{label:"Name",fullWidth:!0,value:$.name,onChange:J=>j({...$,name:J.target.value}),placeholder:"e.g., premium, pro, feature:analytics",required:!0}),l.jsx(Rt,{label:"Category (Optional)",fullWidth:!0,value:$.category,onChange:J=>j({...$,category:J.target.value}),placeholder:"e.g., subscription, feature, access"}),l.jsx(Rt,{label:"Description (Optional)",fullWidth:!0,multiline:!0,rows:2,value:$.description,onChange:J=>j({...$,description:J.target.value}),placeholder:"Describe what this entitlement grants access to"})]})}),l.jsxs(zu,{children:[l.jsx(Nr,{variant:"text",label:"Cancel",onClick:()=>T(!1)}),l.jsx(Nr,{variant:"primary",label:"Create",onClick:K,disabled:!$.name.trim()||q})]})]}),!re&&H&&l.jsxs(Nu,{open:M,onClose:()=>R(!1),maxWidth:"sm",fullWidth:!0,children:[l.jsx($u,{children:"Edit Entitlement"}),l.jsx(Bu,{children:l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",gap:2,mt:1},children:[l.jsx(Rt,{label:"Name",fullWidth:!0,value:H.name,disabled:!0,helperText:"Name cannot be changed"}),l.jsx(Rt,{label:"Category",fullWidth:!0,value:H.category||"",onChange:J=>G({...H,category:J.target.value})}),l.jsx(Rt,{label:"Description",fullWidth:!0,multiline:!0,rows:2,value:H.description||"",onChange:J=>G({...H,description:J.target.value})})]})}),l.jsxs(zu,{children:[l.jsx(Nr,{variant:"text",label:"Cancel",onClick:()=>R(!1)}),l.jsx(Nr,{variant:"primary",label:"Save",onClick:Y,disabled:q})]})]}),!re&&H&&l.jsxs(Nu,{open:L,onClose:()=>A(!1),maxWidth:"sm",fullWidth:!0,children:[l.jsx($u,{children:"Delete Entitlement"}),l.jsxs(Bu,{children:[l.jsx(vt,{variant:"body1",content:`Are you sure you want to delete the entitlement "${H.name}"?`,customColor:"var(--theme-text-primary)"}),l.jsx(Kt,{severity:"warning",sx:{mt:2},children:"This will remove the entitlement from all users who currently have it."})]}),l.jsxs(zu,{children:[l.jsx(Nr,{variant:"text",label:"Cancel",onClick:()=>A(!1)}),l.jsx(Nr,{variant:"primary",color:"error",label:"Delete",onClick:Z,disabled:q})]})]})]})}function nC(e){switch(e){case"enabled":return"var(--theme-success)";case"error":return"var(--theme-error)";case"disabled":default:return"var(--theme-text-secondary)"}}function eW(e){switch(e){case"enabled":return l.jsx(Di,{sx:{color:"var(--theme-success)"}});case"error":return l.jsx(Wo,{sx:{color:"var(--theme-error)"}});case"disabled":default:return l.jsx(_h,{sx:{color:"var(--theme-text-secondary)"}})}}const oC={domain:"",clientId:"",clientSecret:"",baseUrl:"",secret:"",audience:"",scopes:["openid","profile","email"],allowedRoles:[],allowedDomains:[]},iC={url:"",anonKey:""},aC={username:"",password:"",realm:"Protected Area"},sC={connectionUri:"",apiKey:"",appName:"",apiDomain:"",websiteDomain:"",apiBasePath:"/auth",websiteBasePath:"/auth",enableEmailPassword:!0,socialProviders:{}};function tW(){var Me,Xe,dt;const[e,t]=b.useState(null),[r,n]=b.useState(!0),[o,a]=b.useState(null),[c,u]=b.useState(null),[d,f]=b.useState(!1),[h,v]=b.useState(!1),[m,y]=b.useState(!1),[x,w]=b.useState(null),[C,P]=b.useState(""),[k,I]=b.useState(oC),[T,M]=b.useState(iC),[R,L]=b.useState(aC),[A,H]=b.useState(sC),[G,$]=b.useState(!0),[j,q]=b.useState(""),[V,O]=b.useState({enabled:!1,clientId:"",clientSecret:""}),[U,K]=b.useState({enabled:!1,clientId:"",clientSecret:""}),[Y,Z]=b.useState({enabled:!1,clientId:"",clientSecret:"",keyId:"",teamId:""}),[Q,X]=b.useState(!1),[re,de]=b.useState(!1),J=b.useCallback(async()=>{var le,Ye,We,ft;n(!0),a(null);try{const ze=await At.getAuthConfig();if(t(ze),ze.runtimeConfig){const Nt=ze.runtimeConfig;if(P(Nt.adapter||""),$(Nt.settings.authRequired??!0),q(((le=Nt.settings.excludePaths)==null?void 0:le.join(", "))||""),Nt.config.auth0&&I({...oC,...Nt.config.auth0}),Nt.config.supabase&&M({...iC,...Nt.config.supabase}),Nt.config.basic&&L({...aC,...Nt.config.basic}),Nt.config.supertokens){const ht=Nt.config.supertokens;H({...sC,...ht}),(Ye=ht.socialProviders)!=null&&Ye.google&&O({enabled:!0,clientId:ht.socialProviders.google.clientId,clientSecret:ht.socialProviders.google.clientSecret}),(We=ht.socialProviders)!=null&&We.github&&K({enabled:!0,clientId:ht.socialProviders.github.clientId,clientSecret:ht.socialProviders.github.clientSecret}),(ft=ht.socialProviders)!=null&&ft.apple&&Z({enabled:!0,clientId:ht.socialProviders.apple.clientId,clientSecret:ht.socialProviders.apple.clientSecret,keyId:ht.socialProviders.apple.keyId,teamId:ht.socialProviders.apple.teamId})}}else ze.adapter&&P(ze.adapter)}catch(ze){a(ze instanceof Error?ze.message:"Failed to fetch auth status")}finally{n(!1)}},[]);b.useEffect(()=>{J()},[J]);const oe=(le,Ye)=>{navigator.clipboard.writeText(Ye),u(le),setTimeout(()=>u(null),2e3)},ee=()=>{f(!0),w(null)},he=()=>{f(!1),w(null),J()},Ce=le=>JSON.parse(JSON.stringify(le)),ye=()=>{switch(C){case"auth0":return Ce(k);case"supabase":return Ce(T);case"basic":return Ce(R);case"supertokens":{const le={...A},Ye={};return V.enabled&&(Ye.google={clientId:V.clientId,clientSecret:V.clientSecret}),U.enabled&&(Ye.github={clientId:U.clientId,clientSecret:U.clientSecret}),Y.enabled&&(Ye.apple={clientId:Y.clientId,clientSecret:Y.clientSecret,keyId:Y.keyId||"",teamId:Y.teamId||""}),Object.keys(Ye).length>0&&(le.socialProviders=Ye),Ce(le)}default:return{}}},ce=async()=>{if(C){y(!0),w(null);try{const le=await At.testAuthProvider({adapter:C,config:ye()});w(le)}catch(le){w({success:!1,message:le instanceof Error?le.message:"Test failed"})}finally{y(!1)}}},Fe=async()=>{if(e!=null&&e.adapter){y(!0),w(null);try{const le=await At.testCurrentAuthProvider();w(le)}catch(le){w({success:!1,message:le instanceof Error?le.message:"Test failed"})}finally{y(!1)}}},Le=async()=>{if(C){v(!0),a(null);try{const le={adapter:C,config:ye(),settings:{authRequired:G,excludePaths:j.split(",").map(Ye=>Ye.trim()).filter(Boolean)}};await At.updateAuthConfig(le),f(!1),await J()}catch(le){a(le instanceof Error?le.message:"Failed to save configuration")}finally{v(!1)}}},Ne=async()=>{v(!0),a(null);try{await At.deleteAuthConfig(),de(!1),f(!1),await J()}catch(le){a(le instanceof Error?le.message:"Failed to delete configuration")}finally{v(!1)}};if(r)return l.jsx(ne,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:"50vh"},children:l.jsx(cr,{})});const $e=e!=null&&e.config?Object.entries(e.config):[];return l.jsxs(ne,{children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1},children:[l.jsx(pe,{variant:"h4",sx:{color:"var(--theme-text-primary)"},children:"Authentication"}),l.jsx(ne,{sx:{display:"flex",gap:1},children:!d&&l.jsxs(l.Fragment,{children:[l.jsx(fr,{title:"Edit Configuration",children:l.jsx(Qt,{onClick:ee,sx:{color:"var(--theme-primary)"},children:l.jsx(Ff,{})})}),l.jsx(fr,{title:"Refresh",children:l.jsx(Qt,{onClick:J,sx:{color:"var(--theme-text-secondary)"},children:l.jsx(Ys,{})})})]})})]}),l.jsx(pe,{variant:"body2",sx:{mb:4,color:"var(--theme-text-secondary)"},children:d?"Configure authentication provider":"Auth plugin configuration status"}),o&&l.jsx(Kt,{severity:"error",sx:{mb:2},onClose:()=>a(null),children:o}),d?l.jsxs(ne,{children:[l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:2},children:"Provider Selection"}),l.jsxs(_i,{fullWidth:!0,sx:{mb:2},children:[l.jsx(Ga,{sx:{color:"var(--theme-text-secondary)"},children:"Auth Provider"}),l.jsxs(aa,{value:C,onChange:le=>P(le.target.value),label:"Auth Provider",sx:{color:"var(--theme-text-primary)"},children:[l.jsx(Sr,{value:"",children:l.jsx("em",{children:"None (Disabled)"})}),l.jsx(Sr,{value:"supertokens",children:"SuperTokens"}),l.jsx(Sr,{value:"auth0",children:"Auth0"}),l.jsx(Sr,{value:"supabase",children:"Supabase"}),l.jsx(Sr,{value:"basic",children:"Basic Auth"})]})]}),l.jsxs(ne,{sx:{display:"flex",gap:2,alignItems:"center"},children:[l.jsx(Ba,{control:l.jsx(_s,{checked:G,onChange:le=>$(le.target.checked),sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"var(--theme-primary)"}}}),label:"Auth Required",sx:{color:"var(--theme-text-primary)"}}),l.jsx(Rt,{label:"Exclude Paths (comma-separated)",value:j,onChange:le=>q(le.target.value),size:"small",sx:{flex:1,"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}},placeholder:"/api/health, /api/public/*"})]})]})}),C==="auth0"&&l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:2},children:"Auth0 Configuration"}),l.jsxs(ne,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",md:"1fr 1fr"},gap:2},children:[l.jsx(Rt,{label:"Domain",value:k.domain,onChange:le=>I({...k,domain:le.target.value}),required:!0,placeholder:"your-tenant.auth0.com",sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Client ID",value:k.clientId,onChange:le=>I({...k,clientId:le.target.value}),required:!0,sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Client Secret",type:"password",value:k.clientSecret,onChange:le=>I({...k,clientSecret:le.target.value}),required:!0,sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Base URL",value:k.baseUrl,onChange:le=>I({...k,baseUrl:le.target.value}),required:!0,placeholder:"https://your-app.com",sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Session Secret",type:"password",value:k.secret,onChange:le=>I({...k,secret:le.target.value}),required:!0,sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"API Audience (optional)",value:k.audience||"",onChange:le=>I({...k,audience:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}})]})]})}),C==="supabase"&&l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:2},children:"Supabase Configuration"}),l.jsxs(ne,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",md:"1fr 1fr"},gap:2},children:[l.jsx(Rt,{label:"Project URL",value:T.url,onChange:le=>M({...T,url:le.target.value}),required:!0,placeholder:"https://your-project.supabase.co",sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Anon Key",type:"password",value:T.anonKey,onChange:le=>M({...T,anonKey:le.target.value}),required:!0,sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}})]})]})}),C==="basic"&&l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:2},children:"Basic Auth Configuration"}),l.jsxs(ne,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",md:"1fr 1fr 1fr"},gap:2},children:[l.jsx(Rt,{label:"Username",value:R.username,onChange:le=>L({...R,username:le.target.value}),required:!0,sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Password",type:"password",value:R.password,onChange:le=>L({...R,password:le.target.value}),required:!0,sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Realm (optional)",value:R.realm||"",onChange:le=>L({...R,realm:le.target.value}),placeholder:"Protected Area",sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}})]})]})}),C==="supertokens"&&l.jsxs(l.Fragment,{children:[l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:2},children:"SuperTokens Configuration"}),l.jsxs(ne,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",md:"1fr 1fr"},gap:2},children:[l.jsx(Rt,{label:"Connection URI",value:A.connectionUri,onChange:le=>H({...A,connectionUri:le.target.value}),required:!0,placeholder:"http://localhost:3567",sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"API Key (optional)",type:"password",value:A.apiKey||"",onChange:le=>H({...A,apiKey:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"App Name",value:A.appName,onChange:le=>H({...A,appName:le.target.value}),required:!0,sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"API Domain",value:A.apiDomain,onChange:le=>H({...A,apiDomain:le.target.value}),required:!0,placeholder:"http://localhost:3000",sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Website Domain",value:A.websiteDomain,onChange:le=>H({...A,websiteDomain:le.target.value}),required:!0,placeholder:"http://localhost:3000",sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"API Base Path",value:A.apiBasePath||"/auth",onChange:le=>H({...A,apiBasePath:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}})]}),l.jsx(ne,{sx:{mt:2},children:l.jsx(Ba,{control:l.jsx(_s,{checked:A.enableEmailPassword??!0,onChange:le=>H({...A,enableEmailPassword:le.target.checked}),sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"var(--theme-primary)"}}}),label:"Enable Email/Password Auth",sx:{color:"var(--theme-text-primary)"}})})]})}),l.jsxs(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:[l.jsx(gt,{sx:{pb:Q?2:0},children:l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer"},onClick:()=>X(!Q),children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)"},children:"Social Login Providers"}),Q?l.jsx(D7,{}):l.jsx(F7,{})]})}),l.jsx(Xu,{in:Q,children:l.jsxs(gt,{sx:{pt:0},children:[l.jsx(_y,{sx:{mb:2}}),l.jsxs(ne,{sx:{mb:3},children:[l.jsx(Ba,{control:l.jsx(_s,{checked:V.enabled,onChange:le=>O({...V,enabled:le.target.checked}),sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"var(--theme-primary)"}}}),label:"Google",sx:{color:"var(--theme-text-primary)",mb:1}}),V.enabled&&l.jsxs(ne,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",md:"1fr 1fr"},gap:2,ml:4},children:[l.jsx(Rt,{label:"Client ID",size:"small",value:V.clientId,onChange:le=>O({...V,clientId:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Client Secret",size:"small",type:"password",value:V.clientSecret,onChange:le=>O({...V,clientSecret:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}})]})]}),l.jsxs(ne,{sx:{mb:3},children:[l.jsx(Ba,{control:l.jsx(_s,{checked:U.enabled,onChange:le=>K({...U,enabled:le.target.checked}),sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"var(--theme-primary)"}}}),label:"GitHub",sx:{color:"var(--theme-text-primary)",mb:1}}),U.enabled&&l.jsxs(ne,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",md:"1fr 1fr"},gap:2,ml:4},children:[l.jsx(Rt,{label:"Client ID",size:"small",value:U.clientId,onChange:le=>K({...U,clientId:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Client Secret",size:"small",type:"password",value:U.clientSecret,onChange:le=>K({...U,clientSecret:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}})]})]}),l.jsxs(ne,{children:[l.jsx(Ba,{control:l.jsx(_s,{checked:Y.enabled,onChange:le=>Z({...Y,enabled:le.target.checked}),sx:{"& .MuiSwitch-switchBase.Mui-checked":{color:"var(--theme-primary)"}}}),label:"Apple",sx:{color:"var(--theme-text-primary)",mb:1}}),Y.enabled&&l.jsxs(ne,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",md:"1fr 1fr"},gap:2,ml:4},children:[l.jsx(Rt,{label:"Client ID",size:"small",value:Y.clientId,onChange:le=>Z({...Y,clientId:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Client Secret",size:"small",type:"password",value:Y.clientSecret,onChange:le=>Z({...Y,clientSecret:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Key ID",size:"small",value:Y.keyId||"",onChange:le=>Z({...Y,keyId:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}}),l.jsx(Rt,{label:"Team ID",size:"small",value:Y.teamId||"",onChange:le=>Z({...Y,teamId:le.target.value}),sx:{"& .MuiInputBase-input":{color:"var(--theme-text-primary)"}}})]})]})]})})]})]}),x&&l.jsxs(Kt,{severity:x.success?"success":"error",sx:{mb:3},children:[l.jsx(pe,{variant:"body2",sx:{fontWeight:600},children:x.success?"Connection Successful":"Connection Failed"}),l.jsx(pe,{variant:"body2",children:x.message}),((Me=x.details)==null?void 0:Me.latency)&&l.jsxs(pe,{variant:"caption",sx:{display:"block",mt:.5},children:["Latency: ",x.details.latency,"ms"]})]}),l.jsxs(ne,{sx:{display:"flex",gap:2,justifyContent:"space-between"},children:[l.jsxs(ne,{sx:{display:"flex",gap:2},children:[l.jsx(sn,{variant:"outlined",startIcon:l.jsx(_7,{}),onClick:he,disabled:h,sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Cancel"}),(e==null?void 0:e.runtimeConfig)&&l.jsx(sn,{variant:"outlined",color:"error",startIcon:l.jsx(Lh,{}),onClick:()=>de(!0),disabled:h,children:"Reset to Env Vars"})]}),l.jsxs(ne,{sx:{display:"flex",gap:2},children:[l.jsx(sn,{variant:"outlined",startIcon:m?l.jsx(cr,{size:16}):l.jsx(sc,{}),onClick:ce,disabled:!C||m||h,sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:"Test Connection"}),l.jsx(sn,{variant:"contained",startIcon:h?l.jsx(cr,{size:16,sx:{color:"white"}}):l.jsx(d0,{}),onClick:Le,disabled:h,sx:{bgcolor:"var(--theme-primary)","&:hover":{bgcolor:"var(--theme-primary-dark)"}},children:"Save Configuration"})]})]})]}):l.jsxs(l.Fragment,{children:[l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:l.jsxs(gt,{children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2,mb:2},children:[eW((e==null?void 0:e.state)||"disabled"),l.jsxs(ne,{sx:{flex:1},children:[l.jsxs(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)"},children:["Status:"," ",l.jsx(qt,{label:((Xe=e==null?void 0:e.state)==null?void 0:Xe.toUpperCase())||"UNKNOWN",size:"small",sx:{bgcolor:`${nC((e==null?void 0:e.state)||"disabled")}20`,color:nC((e==null?void 0:e.state)||"disabled"),fontWeight:600}})]}),(e==null?void 0:e.adapter)&&l.jsxs(pe,{variant:"body2",sx:{color:"var(--theme-text-secondary)",mt:.5},children:["Adapter: ",l.jsx("strong",{children:e.adapter})]})]}),(e==null?void 0:e.state)==="enabled"&&(e==null?void 0:e.adapter)&&l.jsx(sn,{variant:"outlined",size:"small",startIcon:m?l.jsx(cr,{size:14}):l.jsx(sc,{}),onClick:Fe,disabled:m,sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:"Test Connection"})]}),x&&!d&&l.jsxs(Kt,{severity:x.success?"success":"error",sx:{mb:2},children:[l.jsx(pe,{variant:"body2",sx:{fontWeight:600},children:x.success?"Connection Successful":"Connection Failed"}),l.jsx(pe,{variant:"body2",children:x.message}),((dt=x.details)==null?void 0:dt.latency)&&l.jsxs(pe,{variant:"caption",sx:{display:"block",mt:.5},children:["Latency: ",x.details.latency,"ms"]})]}),(e==null?void 0:e.state)==="enabled"&&!(e!=null&&e.runtimeConfig)&&l.jsxs(Kt,{severity:"success",sx:{mb:2},children:[l.jsx(pe,{variant:"body2",sx:{fontWeight:600},children:"Configured via Environment Variables"}),l.jsx(pe,{variant:"body2",children:'Authentication is configured using environment variables. Click "Edit" to override with runtime configuration (requires PostgreSQL).'})]}),(e==null?void 0:e.runtimeConfig)&&l.jsx(qt,{label:"Runtime Configuration Active",size:"small",sx:{bgcolor:"var(--theme-primary)",color:"white",mb:2}}),(e==null?void 0:e.state)==="error"&&e.error&&l.jsx(Kt,{severity:"error",sx:{mb:2},children:e.error}),(e==null?void 0:e.missingVars)&&e.missingVars.length>0&&l.jsxs(Kt,{severity:"warning",sx:{mb:2},children:[l.jsx(pe,{variant:"body2",sx:{fontWeight:600,mb:1},children:"Missing environment variables:"}),l.jsx(ne,{component:"ul",sx:{m:0,pl:2},children:e.missingVars.map(le=>l.jsx("li",{children:l.jsx("code",{children:le})},le))})]}),(e==null?void 0:e.state)==="disabled"&&l.jsxs(Kt,{severity:"info",children:[l.jsxs(pe,{variant:"body2",children:["Authentication is disabled. Click the edit button to configure a provider, or set the"," ",l.jsx("code",{children:"AUTH_ADAPTER"})," environment variable."]}),l.jsxs(pe,{variant:"body2",sx:{mt:1},children:["Valid options: ",l.jsx("code",{children:"supertokens"}),", ",l.jsx("code",{children:"auth0"}),", ",l.jsx("code",{children:"supabase"}),","," ",l.jsx("code",{children:"basic"})]})]})]})}),$e.length>0&&l.jsxs(yt,{sx:{bgcolor:"var(--theme-surface)"},children:[l.jsx(gt,{sx:{pb:0},children:l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:2},children:"Current Configuration"})}),l.jsx(Qa,{children:l.jsxs(Xa,{size:"small",children:[l.jsx(Ya,{children:l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Variable"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Value"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)",width:60},children:"Actions"})]})}),l.jsx(Ka,{children:$e.map(([le,Ye])=>l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:l.jsx(pe,{sx:{color:"var(--theme-text-primary)",fontFamily:"monospace",fontSize:13},children:le})}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:l.jsx(pe,{sx:{color:Ye.includes("*")?"var(--theme-text-secondary)":"var(--theme-text-primary)",fontFamily:"monospace",fontSize:13},children:Ye})}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},children:l.jsx(fr,{title:c===le?"Copied!":"Copy value",children:l.jsx(Qt,{size:"small",onClick:()=>oe(le,Ye),sx:{color:c===le?"var(--theme-success)":"var(--theme-text-secondary)"},children:l.jsx(u0,{fontSize:"small"})})})})]},le))})]})})]}),(e==null?void 0:e.state)==="enabled"&&$e.length===0&&l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsx(gt,{children:l.jsx(pe,{sx:{color:"var(--theme-text-secondary)",textAlign:"center"},children:"No configuration details available"})})})]}),l.jsxs(Jv,{open:re,onClose:()=>de(!1),children:[l.jsx(t0,{children:"Reset to Environment Variables?"}),l.jsx(e0,{children:l.jsx(pe,{children:"This will delete the runtime configuration from the database. The auth plugin will fall back to environment variables on the next request."})}),l.jsxs(Zv,{children:[l.jsx(sn,{onClick:()=>de(!1),children:"Cancel"}),l.jsx(sn,{onClick:Ne,color:"error",disabled:h,children:h?l.jsx(cr,{size:20}):"Reset"})]})]})]})}function ly(e){return e<1e3?`${e}ms`:e<6e4?`${e/1e3}s`:e<36e5?`${e/6e4}m`:`${e/36e5}h`}function rW(){const[e,t]=b.useState(null),[r,n]=b.useState(!0),[o,a]=b.useState(!1),[c,u]=b.useState(null),[d,f]=b.useState(null),[h,v]=b.useState(6e4),[m,y]=b.useState(100),[x,w]=b.useState("sliding-window"),[C,P]=b.useState(!0),[k,I]=b.useState(3e5),T=async()=>{n(!0),u(null);try{const L=await At.getRateLimitConfig();t(L),v(L.windowMs),y(L.maxRequests),w(L.strategy),P(L.cleanupEnabled),I(L.cleanupIntervalMs)}catch(L){u(L instanceof Error?L.message:"Failed to fetch config")}finally{n(!1)}};b.useEffect(()=>{T()},[]);const M=async()=>{a(!0),u(null),f(null);try{const L=await At.updateRateLimitConfig({windowMs:h,maxRequests:m,strategy:x,cleanupEnabled:C,cleanupIntervalMs:k});t(L.config),f("Configuration saved successfully"),setTimeout(()=>f(null),3e3)}catch(L){u(L instanceof Error?L.message:"Failed to save config")}finally{a(!1)}},R=e&&(h!==e.windowMs||m!==e.maxRequests||x!==e.strategy||C!==e.cleanupEnabled||k!==e.cleanupIntervalMs);return r?l.jsx(ne,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:"50vh"},children:l.jsx(cr,{})}):c&&!e?l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",border:"1px solid var(--theme-error)"},children:l.jsx(gt,{children:l.jsx(pe,{color:"error",children:c})})}):l.jsxs(ne,{children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(bT,{sx:{color:"var(--theme-primary)",fontSize:32}}),l.jsx(pe,{variant:"h4",sx:{color:"var(--theme-text-primary)"},children:"Rate Limits"})]}),l.jsxs(ne,{sx:{display:"flex",gap:1},children:[l.jsx(fr,{title:"Refresh",children:l.jsx(Qt,{onClick:T,sx:{color:"var(--theme-text-secondary)"},children:l.jsx(Ys,{})})}),l.jsx(sn,{variant:"contained",startIcon:o?l.jsx(cr,{size:16,color:"inherit"}):l.jsx(d0,{}),onClick:M,disabled:o||!R,sx:{minWidth:100},children:o?"Saving...":"Save"})]})]}),l.jsx(pe,{variant:"body2",sx:{mb:4,color:"var(--theme-text-secondary)"},children:"Configure rate limiting defaults for your API"}),d&&l.jsx(Kt,{severity:"success",sx:{mb:3},children:d}),c&&e&&l.jsx(Kt,{severity:"error",sx:{mb:3},children:c}),l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:2},children:"System Status"}),l.jsxs(ne,{sx:{display:"flex",gap:3,flexWrap:"wrap"},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(f0,{sx:{color:"var(--theme-text-secondary)"}}),l.jsxs(ne,{children:[l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:"Store"}),l.jsx(pe,{sx:{color:"var(--theme-text-primary)"},children:e==null?void 0:e.store})]})]}),l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(A7,{sx:{color:e!=null&&e.cacheAvailable?"var(--theme-success)":"var(--theme-warning)"}}),l.jsxs(ne,{children:[l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:"Cache"}),l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(pe,{sx:{color:"var(--theme-text-primary)"},children:e==null?void 0:e.cache}),l.jsx(qt,{label:e!=null&&e.cacheAvailable?"Available":"Unavailable",size:"small",sx:{bgcolor:e!=null&&e.cacheAvailable?"var(--theme-success)20":"var(--theme-warning)20",color:e!=null&&e.cacheAvailable?"var(--theme-success)":"var(--theme-warning)"}})]})]})]})]})]})}),l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:3},children:"Default Rate Limit Settings"}),l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",gap:3},children:[l.jsxs(_i,{fullWidth:!0,children:[l.jsx(Ga,{sx:{color:"var(--theme-text-secondary)"},children:"Strategy"}),l.jsxs(aa,{value:x,label:"Strategy",onChange:L=>w(L.target.value),sx:{color:"var(--theme-text-primary)","& .MuiOutlinedInput-notchedOutline":{borderColor:"var(--theme-border)"}},children:[l.jsx(Sr,{value:"sliding-window",children:"Sliding Window - Smooth rate limiting with weighted overlap"}),l.jsx(Sr,{value:"fixed-window",children:"Fixed Window - Simple discrete time windows"}),l.jsx(Sr,{value:"token-bucket",children:"Token Bucket - Allows bursts while maintaining average rate"})]})]}),l.jsxs(ne,{sx:{display:"flex",gap:3,flexWrap:"wrap"},children:[l.jsx(Rt,{label:"Window (ms)",type:"number",value:h,onChange:L=>v(Math.max(1e3,parseInt(L.target.value)||6e4)),helperText:`= ${ly(h)}`,sx:{flex:1,minWidth:200},InputProps:{inputProps:{min:1e3,step:1e3}}}),l.jsx(Rt,{label:"Max Requests",type:"number",value:m,onChange:L=>y(Math.max(1,parseInt(L.target.value)||100)),helperText:"Per window per key",sx:{flex:1,minWidth:200},InputProps:{inputProps:{min:1}}})]}),l.jsx(Kt,{severity:"info",sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(pe,{variant:"body2",children:[l.jsx("strong",{children:"Current limit:"})," ",m," requests per ",ly(h)," using ",x," strategy"]})})]})]})}),l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:3},children:"Cleanup Job"}),l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",gap:3},children:[l.jsx(Ba,{control:l.jsx(_s,{checked:C,onChange:L=>P(L.target.checked),color:"primary"}),label:"Enable automatic cleanup of expired rate limits",sx:{color:"var(--theme-text-primary)"}}),C&&l.jsx(Rt,{label:"Cleanup Interval (ms)",type:"number",value:k,onChange:L=>I(Math.max(6e4,parseInt(L.target.value)||3e5)),helperText:`= ${ly(k)}`,sx:{maxWidth:300},InputProps:{inputProps:{min:6e4,step:6e4}}})]})]})})]})}function nW(){const[e,t]=b.useState(null),[r,n]=b.useState([]),[o,a]=b.useState(!0),[c,u]=b.useState(null),[d,f]=b.useState(null),[h,v]=b.useState(null),[m,y]=b.useState(!1),[x,w]=b.useState(null),C=b.useRef(!0),P=b.useCallback(async()=>{try{const[R,L]=await Promise.all([At.getNotificationsStats(),At.getNotificationsClients()]);C.current&&(t(R),n(L.clients),u(null))}catch(R){C.current&&(R instanceof Error&&R.message.includes("404")?u("Notifications plugin not enabled"):u(R instanceof Error?R.message:"Failed to fetch data"))}finally{C.current&&a(!1)}},[]);b.useEffect(()=>{C.current=!0,P();const R=setInterval(P,5e3);return()=>{C.current=!1,clearInterval(R)}},[P]);const k=async R=>{v(R.id),w(null);try{await At.disconnectNotificationsClient(R.id),C.current&&(f(`Client ${$l(R.id)} disconnected`),setTimeout(()=>{C.current&&f(null)},3e3),await P())}catch(L){C.current&&u(L instanceof Error?L.message:"Failed to disconnect client")}finally{C.current&&v(null)}},I=async()=>{y(!0);try{const R=await At.forceNotificationsReconnect();C.current&&(f(R.message),setTimeout(()=>{C.current&&f(null)},3e3),await P())}catch(R){C.current&&u(R instanceof Error?R.message:"Failed to force reconnect")}finally{C.current&&y(!1)}};if(o)return l.jsx(ne,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:"50vh"},children:l.jsx(cr,{})});if(c&&!e)return l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",border:"1px solid var(--theme-border)"},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(Hf,{sx:{color:"var(--theme-text-secondary)"}}),l.jsx(pe,{sx:{color:"var(--theme-text-secondary)"},children:c})]})})});const T=(e==null?void 0:e.connectionHealth.isHealthy)??!1,M=T?"var(--theme-success)":"var(--theme-warning)";return l.jsxs(ne,{children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[l.jsx(xT,{sx:{color:"var(--theme-primary)",fontSize:32}}),l.jsx(pe,{variant:"h4",sx:{color:"var(--theme-text-primary)"},children:"Notifications"})]}),l.jsxs(ne,{sx:{display:"flex",gap:1},children:[l.jsx(fr,{title:"Refresh",children:l.jsx(Qt,{onClick:P,sx:{color:"var(--theme-text-secondary)"},children:l.jsx(Ys,{})})}),l.jsx(sn,{variant:"outlined",startIcon:m?l.jsx(cr,{size:16}):l.jsx(yB,{}),onClick:I,disabled:m,sx:{borderColor:"var(--theme-border)"},children:m?"Reconnecting...":"Force Reconnect"})]})]}),l.jsx(pe,{variant:"body2",sx:{mb:4,color:"var(--theme-text-secondary)"},children:"Manage realtime notification connections and SSE clients"}),d&&l.jsx(Kt,{severity:"success",sx:{mb:3},children:d}),c&&e&&l.jsx(Kt,{severity:"error",sx:{mb:3},children:c}),l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:l.jsx(gt,{sx:{py:1.5,"&:last-child":{pb:1.5}},children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1},children:[T?l.jsx(ST,{sx:{color:M,fontSize:20}}):l.jsx(Hf,{sx:{color:M,fontSize:20}}),l.jsx(pe,{sx:{color:M,fontWeight:500},children:T?"Connected":"Reconnecting..."}),(e==null?void 0:e.connectionHealth.isReconnecting)&&l.jsx(qt,{label:`Attempt ${e.connectionHealth.reconnectAttempts}`,size:"small",sx:{bgcolor:"var(--theme-warning)20",color:"var(--theme-warning)",fontSize:"0.7rem",height:18}})]}),l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:2},children:[l.jsxs(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:[e==null?void 0:e.channels.length," channel",(e==null?void 0:e.channels.length)!==1?"s":""]}),(e==null?void 0:e.lastEventAt)&&l.jsxs(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:["Last event: ",xv(e.connectionHealth.timeSinceLastEvent)," ago"]})]})]})})}),l.jsxs(kc,{columns:4,spacing:"small",equalHeight:!0,children:[l.jsx(Ha,{icon:l.jsx(Wy,{sx:{fontSize:28}}),label:"Active Clients",value:(e==null?void 0:e.currentConnections)??0,subValue:`${(e==null?void 0:e.totalConnections)??0} total`,color:"var(--theme-primary)"}),l.jsx(Ha,{icon:l.jsx(ac,{sx:{fontSize:28}}),label:"By Device",value:(e==null?void 0:e.clientsByType.device)??0,subValue:`${(e==null?void 0:e.clientsByType.user)??0} by user`,color:"var(--theme-info)"}),l.jsx(Ha,{icon:l.jsx(p0,{sx:{fontSize:28}}),label:"Events Routed",value:Kl((e==null?void 0:e.eventsRouted)??0),subValue:`${Kl((e==null?void 0:e.eventsProcessed)??0)} processed`,color:"var(--theme-success)"}),l.jsx(Ha,{icon:l.jsx(Wo,{sx:{fontSize:28}}),label:"Dropped",value:Kl((e==null?void 0:e.eventsDroppedNoClients)??0),subValue:`${(e==null?void 0:e.eventsParseFailed)??0} parse errors`,color:((e==null?void 0:e.eventsDroppedNoClients)??0)>0?"var(--theme-warning)":"var(--theme-text-secondary)"})]}),l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mt:3},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:2},children:"Connected Clients"}),r.length===0?l.jsx(pe,{sx:{color:"var(--theme-text-secondary)",py:4,textAlign:"center"},children:"No clients currently connected"}):l.jsx(Qa,{component:_r,sx:{bgcolor:"transparent",boxShadow:"none"},children:l.jsxs(Xa,{size:"small",children:[l.jsx(Ya,{children:l.jsxs(Ur,{children:[l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Client ID"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Device ID"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"User ID"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Connected"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:"Duration"}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},align:"right",children:"Actions"})]})}),l.jsx(Ka,{children:r.map(R=>l.jsxs(Ur,{hover:!0,children:[l.jsx(Ve,{sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:l.jsx(fr,{title:R.id,children:l.jsx("code",{style:{fontSize:"0.85em"},children:$l(R.id)})})}),l.jsx(Ve,{sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:R.deviceId?l.jsx(fr,{title:R.deviceId,children:l.jsx(qt,{size:"small",icon:l.jsx(Wy,{sx:{fontSize:14}}),label:$l(R.deviceId),sx:{bgcolor:"var(--theme-primary)20",color:"var(--theme-primary)"}})}):l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:"—"})}),l.jsx(Ve,{sx:{color:"var(--theme-text-primary)",borderColor:"var(--theme-border)"},children:R.userId?l.jsx(fr,{title:R.userId,children:l.jsx(qt,{size:"small",icon:l.jsx(ac,{sx:{fontSize:14}}),label:$l(R.userId),sx:{bgcolor:"var(--theme-info)20",color:"var(--theme-info)"}})}):l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:"—"})}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:new Date(R.connectedAt).toLocaleTimeString()}),l.jsx(Ve,{sx:{color:"var(--theme-text-secondary)",borderColor:"var(--theme-border)"},children:xv(R.durationMs)}),l.jsx(Ve,{sx:{borderColor:"var(--theme-border)"},align:"right",children:l.jsx(fr,{title:"Disconnect client",children:l.jsx(Qt,{size:"small",onClick:()=>w(R),disabled:h===R.id,sx:{color:"var(--theme-error)"},children:h===R.id?l.jsx(cr,{size:18}):l.jsx(oB,{fontSize:"small"})})})})]},R.id))})]})})]})}),l.jsxs(Jv,{open:!!x,onClose:()=>w(null),"aria-labelledby":"disconnect-dialog-title",children:[l.jsx(t0,{id:"disconnect-dialog-title",children:"Disconnect Client?"}),l.jsx(e0,{children:l.jsxs(WL,{children:["Are you sure you want to disconnect this client?",(x==null?void 0:x.deviceId)&&l.jsxs(l.Fragment,{children:[l.jsx("br",{}),l.jsx("strong",{children:"Device:"})," ",$l(x.deviceId)]}),(x==null?void 0:x.userId)&&l.jsxs(l.Fragment,{children:[l.jsx("br",{}),l.jsx("strong",{children:"User:"})," ",$l(x.userId)]}),l.jsx("br",{}),l.jsx("br",{}),"The client will receive a disconnect event and the connection will be closed. The client may automatically reconnect."]})}),l.jsxs(Zv,{children:[l.jsx(sn,{onClick:()=>w(null),children:"Cancel"}),l.jsx(sn,{onClick:()=>x&&k(x),color:"error",autoFocus:!0,children:"Disconnect"})]})]})]})}function oW(){const[e,t]=b.useState(null),[r,n]=b.useState(!0),[o,a]=b.useState(null),[c,u]=b.useState(null),[d,f]=b.useState({}),h=b.useCallback(async()=>{n(!0),a(null);try{const m=await At.fetch("/ai-proxy/config");t(m)}catch(m){a(m instanceof Error?m.message:"Failed to fetch integrations config")}finally{n(!1)}},[]);b.useEffect(()=>{h()},[h]);const v=async m=>{u(m),f(y=>({...y,[m]:{success:!1,message:"Testing..."}}));try{const y=await At.fetch(`/ai-proxy/test/${m}`,{method:"POST"});f(x=>({...x,[m]:y}))}catch(y){f(x=>({...x,[m]:{success:!1,message:y instanceof Error?y.message:"Test failed"}}))}finally{u(null)}};return r?l.jsx(ne,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:"50vh"},children:l.jsx(cr,{})}):l.jsxs(ne,{children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:1},children:[l.jsx(pe,{variant:"h4",sx:{color:"var(--theme-text-primary)"},children:"AI Integrations"}),l.jsx(fr,{title:"Refresh",children:l.jsx(Qt,{onClick:h,sx:{color:"var(--theme-text-secondary)"},children:l.jsx(Ys,{})})})]}),l.jsx(pe,{variant:"body2",sx:{mb:4,color:"var(--theme-text-secondary)"},children:"Manage AI service connections for QwickBot"}),o&&l.jsx(Kt,{severity:"error",sx:{mb:3},onClose:()=>a(null),children:o}),e&&l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mb:3},children:l.jsx(gt,{children:l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:3},children:[l.jsxs(ne,{children:[l.jsx(pe,{variant:"h3",sx:{color:"var(--theme-primary)",fontWeight:600},children:e.stats.totalRequests}),l.jsx(pe,{variant:"body2",sx:{color:"var(--theme-text-secondary)"},children:"Total API Requests"})]}),l.jsxs(ne,{sx:{borderLeft:"1px solid var(--theme-border)",pl:3},children:[l.jsx(pe,{variant:"h3",sx:{color:"var(--theme-success)",fontWeight:600},children:e.integrations.filter(m=>m.configured).length}),l.jsx(pe,{variant:"body2",sx:{color:"var(--theme-text-secondary)"},children:"Configured Services"})]})]})})}),l.jsx(ne,{sx:{display:"grid",gridTemplateColumns:{xs:"1fr",md:"1fr 1fr"},gap:3},children:e==null?void 0:e.integrations.map(m=>{const y=d[m.id],x=c===m.id;return l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{children:[l.jsxs(ne,{sx:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",mb:2},children:[l.jsxs(ne,{children:[l.jsxs(ne,{sx:{display:"flex",alignItems:"center",gap:1,mb:.5},children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)"},children:m.name}),l.jsx(qt,{label:m.configured?"Configured":"Not Configured",size:"small",sx:{bgcolor:m.configured?"var(--theme-success)20":"var(--theme-error)20",color:m.configured?"var(--theme-success)":"var(--theme-error)",fontWeight:500}})]}),l.jsx(pe,{variant:"body2",sx:{color:"var(--theme-text-secondary)"},children:m.description})]}),m.configured?l.jsx(Di,{sx:{color:"var(--theme-success)"}}):l.jsx(Wo,{sx:{color:"var(--theme-error)"}})]}),l.jsxs(ne,{sx:{mb:2,p:1.5,bgcolor:"var(--theme-background)",borderRadius:1},children:[l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)",display:"block",mb:.5},children:"API Key"}),l.jsx(pe,{sx:{fontFamily:"monospace",fontSize:13,color:m.configured?"var(--theme-text-primary)":"var(--theme-text-secondary)"},children:m.apiKey})]}),y&&l.jsx(ne,{sx:{mb:2},children:x?l.jsx(Sd,{sx:{height:4,borderRadius:2}}):l.jsxs(Kt,{severity:y.success?"success":"error",sx:{py:.5,"& .MuiAlert-message":{fontSize:13}},children:[y.message,y.latency!==void 0&&l.jsxs(pe,{variant:"caption",sx:{display:"block",mt:.5},children:["Latency: ",y.latency,"ms"]})]})}),l.jsxs(ne,{sx:{display:"flex",gap:1,justifyContent:"flex-end"},children:[l.jsx(sn,{size:"small",startIcon:l.jsx(uB,{}),href:m.docsUrl,target:"_blank",sx:{color:"var(--theme-text-secondary)","&:hover":{color:"var(--theme-primary)"}},children:"Docs"}),l.jsx(sn,{size:"small",variant:"outlined",startIcon:x?l.jsx(cr,{size:14}):l.jsx(sc,{}),onClick:()=>v(m.id),disabled:!m.configured||x,sx:{borderColor:"var(--theme-border)",color:"var(--theme-text-primary)","&:hover":{borderColor:"var(--theme-primary)"}},children:"Test Connection"})]})]})},m.id)})}),e&&e.integrations.some(m=>!m.configured)&&l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)",mt:3},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{color:"var(--theme-text-primary)",mb:2},children:"Setup Instructions"}),l.jsx(pe,{variant:"body2",sx:{color:"var(--theme-text-secondary)",mb:2},children:"Add the following environment variables to configure the AI services:"}),l.jsx(ne,{component:"pre",sx:{p:2,bgcolor:"var(--theme-background)",borderRadius:1,overflow:"auto",fontFamily:"monospace",fontSize:13,color:"var(--theme-text-primary)"},children:`# Groq - for chat (https://console.groq.com)
|
|
465
465
|
GROQ_API_KEY=your_groq_api_key
|
|
466
466
|
|
|
467
467
|
# Gemini - for vision (https://ai.google.dev)
|
|
468
468
|
GEMINI_API_KEY=your_gemini_api_key`})]})})]})}function iW({pluginId:e,title:t,route:r}){const[n,o]=b.useState(!0),[a,c]=b.useState(null),[u,d]=b.useState(null);return b.useEffect(()=>{(async()=>{try{const h=await fetch(`${At.baseUrl}/api${r}`);if(h.ok){const v=await h.json();d(v),c(null)}else h.status===404?(d(null),c(null)):c(`Failed to load page: ${h.statusText}`)}catch(h){c(h instanceof Error?h.message:"Failed to load page")}finally{o(!1)}})()},[r]),n?l.jsx(ne,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:"50vh"},children:l.jsx(cr,{})}):l.jsxs(ne,{children:[l.jsx(pe,{variant:"h4",sx:{mb:1,color:"var(--theme-text-primary)"},children:t}),l.jsxs(pe,{variant:"body2",sx:{mb:4,color:"var(--theme-text-secondary)"},children:["Plugin: ",e]}),a&&l.jsx(Kt,{severity:"error",sx:{mb:3},children:a}),(u==null?void 0:u.cards)&&u.cards.length>0&&l.jsx(ne,{sx:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:2,mb:4},children:u.cards.map((f,h)=>l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h4",sx:{color:f.color||"var(--theme-text-primary)"},children:f.value}),l.jsx(pe,{variant:"body2",sx:{color:"var(--theme-text-secondary)"},children:f.title}),f.subtitle&&l.jsx(pe,{variant:"caption",sx:{color:"var(--theme-text-secondary)"},children:f.subtitle})]})},h))}),(u==null?void 0:u.sections)&&u.sections.length>0&&l.jsx(ne,{sx:{display:"flex",flexDirection:"column",gap:3},children:u.sections.map((f,h)=>l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"h6",sx:{mb:2,color:"var(--theme-text-primary)"},children:f.title}),l.jsx(pe,{variant:"body2",sx:{color:"var(--theme-text-secondary)",whiteSpace:"pre-wrap"},children:f.content})]})},h))}),!u&&!a&&l.jsx(yt,{sx:{bgcolor:"var(--theme-surface)"},children:l.jsxs(gt,{children:[l.jsx(pe,{variant:"body1",sx:{color:"var(--theme-text-secondary)"},children:"This plugin page is available. Configure the plugin to add content here."}),l.jsxs(pe,{variant:"body2",sx:{mt:2,color:"var(--theme-text-secondary)"},children:["API endpoint: ",l.jsxs("code",{children:["/api",r]})]})]})})]})}function aW(){const e=Ev();return l.jsxs(ne,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"50vh",textAlign:"center"},children:[l.jsx(pe,{variant:"h1",sx:{color:"var(--theme-primary)",mb:2},children:"404"}),l.jsx(pe,{variant:"h5",sx:{color:"var(--theme-text-primary)",mb:1},children:"Page Not Found"}),l.jsx(pe,{sx:{color:"var(--theme-text-secondary)",mb:4},children:"The page you're looking for doesn't exist or has been moved."}),l.jsx(sn,{variant:"contained",startIcon:l.jsx(yT,{}),onClick:()=>e("/"),sx:{bgcolor:"var(--theme-primary)","&:hover":{bgcolor:"var(--theme-primary)"}},children:"Back to Dashboard"})]})}const lC=[{id:"dashboard",label:"Dashboard",route:"/",icon:"dashboard"},{id:"plugins",label:"Plugins",route:"/plugins",icon:"extension"},{id:"logs",label:"Logs",route:"/logs",icon:"article"},{id:"system",label:"System",route:"/system",icon:"settings"}],sW={users:{id:"users",label:"Users",route:"/users",icon:"people"}},lW=new Set(["/","/plugins","/logs","/system","/users","/entitlements","/auth","/rate-limits","/notifications","/integrations"]),cW="1.0.0",uj=window.__APP_BASE_PATH__??"";At.setBaseUrl(uj);const uW=l.jsx(ne,{sx:{display:"flex",alignItems:"center",justifyContent:"center",gap:.5,py:2},children:l.jsxs(vt,{variant:"caption",customColor:"var(--theme-text-secondary)",children:["Built with"," ",l.jsx(FO,{href:"https://qwickapps.com/products/qwickapps-server",target:"_blank",rel:"noopener noreferrer",sx:{color:"primary.main"},children:"QwickApps Server"})," ","v",cW]})});function dW(){const[e,t]=b.useState(lC),[r,n]=b.useState(new Set),[o,a]=b.useState([]),[c,u]=b.useState("Control Panel"),[d,f]=b.useState(),[h,v]=b.useState(!0);b.useEffect(()=>{(async()=>{try{const[w,C]=await Promise.allSettled([At.getInfo(),At.getUiContributions()]);if(w.status==="fulfilled"?(u(w.value.logoName),f(w.value.logoIconUrl)):console.warn("Failed to fetch product info:",w.reason),C.status==="fulfilled"){const{plugins:P,menuItems:k}=C.value,I=new Set(P.map(R=>R.id));n(I),a(k);const T=[...lC];for(const[R,L]of Object.entries(sW))I.has(R)&&T.push(L);const M=[...k].sort((R,L)=>(R.order??100)-(L.order??100));for(const R of M)T.some(L=>L.route===R.route)||T.push({id:R.id,label:R.label,route:R.route,icon:R.icon||"extension"});t(T)}else console.warn("Failed to fetch UI contributions:",C.reason)}finally{v(!1)}})()},[]);const m=d?l.jsx("img",{src:d,alt:c,style:{width:32,height:32,objectFit:"contain"}}):void 0,y=l.jsx(rU,{icon:m,name:c});return h?l.jsx(ne,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:"100vh",bgcolor:"var(--theme-background, #1a1a2e)"}}):l.jsx(r3,{basename:uj||void 0,children:l.jsx(IU,{initialComponents:DU(),children:l.jsx(kU,{children:l.jsx(eU,{config:TU,logo:y,footerContent:uW,enableScaffolding:!0,navigationItems:e,showThemeSwitcher:!0,showPaletteSwitcher:!0,children:l.jsxs(Z4,{children:[l.jsx(mo,{path:"/",element:l.jsx(HU,{})}),l.jsx(mo,{path:"/plugins",element:l.jsx(YU,{})}),l.jsx(mo,{path:"/logs",element:l.jsx(VU,{})}),l.jsx(mo,{path:"/system",element:l.jsx(GU,{})}),r.has("users")&&l.jsx(mo,{path:"/users",element:l.jsx(JU,{})}),r.has("entitlements")&&l.jsx(mo,{path:"/entitlements",element:l.jsx(ZU,{})}),r.has("auth")&&l.jsx(mo,{path:"/auth",element:l.jsx(tW,{})}),r.has("rate-limit")&&l.jsx(mo,{path:"/rate-limits",element:l.jsx(rW,{})}),r.has("notifications")&&l.jsx(mo,{path:"/notifications",element:l.jsx(nW,{})}),r.has("ai-proxy")&&l.jsx(mo,{path:"/integrations",element:l.jsx(oW,{})}),o.filter(x=>!lW.has(x.route)).map(x=>l.jsx(mo,{path:x.route,element:l.jsx(iW,{pluginId:x.pluginId,title:x.label,route:x.route})},x.id)),l.jsx(mo,{path:"*",element:l.jsx(aW,{})})]})})})})})}a4.createRoot(document.getElementById("root")).render(l.jsx(Lt.StrictMode,{children:l.jsx(dW,{})}));
|
|
469
|
-
//# sourceMappingURL=index-
|
|
469
|
+
//# sourceMappingURL=index-BfC7mG5L.js.map
|