@superdangerous/app-framework 4.16.8 → 4.16.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdangerous/app-framework",
3
- "version": "4.16.8",
3
+ "version": "4.16.9",
4
4
  "description": "Opinionated TypeScript framework for structured vibecoding - building internal web and desktop apps with batteries included",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/ui/dist/index.js CHANGED
@@ -8,7 +8,7 @@ ${fe.message}`:fe.message,Ds={...Dt,metadata:{...Dt.metadata||{},stack:wn}},Ms=[
8
8
  ${le.metadata.stack}`:"";return Dt+wn}).join(`
9
9
  `),Y=new Blob([F],{type:"text/plain"}),fe=URL.createObjectURL(Y),ke=document.createElement("a");ke.href=fe,ke.download=`logs-${new Date().toISOString()}.txt`,ke.click(),URL.revokeObjectURL(fe);}sonner.toast.success("Logs exported successfully");}catch{sonner.toast.error("Failed to export logs");}},Ot=async()=>{try{let F=L.map(Y=>{let fe=qt(Y.timestamp),ke=Y.category||Y.source?` [${Y.category||Y.source}]`:"",le=`${fe} ${Y.level.toUpperCase()}${ke} ${Y.message}`,He=Y.metadata?.stack?`
10
10
  ${Y.metadata.stack}`:"";return le+He}).join(`
11
- `);await navigator.clipboard.writeText(F),sonner.toast.success("Logs copied to clipboard");}catch{sonner.toast.error("Failed to copy logs");}},qt=F=>{try{let Y=new Date(F);return dateFns.format(Y,"yyyy-MM-dd HH:mm:ss.SSS")}catch{return F}},Wt=F=>F<1024?`${F} B`:F<1024*1024?`${(F/1024).toFixed(1)} KB`:`${(F/(1024*1024)).toFixed(1)} MB`,Tr=F=>F?F.replace(/\x1b\[[0-9;]*m/g,"").replace(/\u001b\[[0-9;]*m/g,"").replace(/\x1b\[[0-9;]*m/g,"").replace(/\[[0-9;]+m/g,"").replace(/\[[\d;]*m/g,""):"",Wr=F=>jsxRuntime.jsxs("div",{className:"px-3 py-2 font-mono text-xs border-b border-gray-100 dark:border-gray-800 text-gray-800 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-900",children:[jsxRuntime.jsxs("div",{className:"flex items-start gap-2",children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 whitespace-nowrap",children:qt(F.timestamp)}),jsxRuntime.jsx("span",{className:"flex-shrink-0",children:jsxRuntime.jsx(sr,{level:F.level})}),(F.category||F.source)&&jsxRuntime.jsxs("span",{className:"text-gray-600 dark:text-gray-400 whitespace-nowrap",children:["[",F.category||F.source,"]"]}),jsxRuntime.jsx("span",{className:"whitespace-pre-wrap break-all",children:Tr(F.message)})]}),F.metadata?.stack&&jsxRuntime.jsx("pre",{className:"ml-[180px] whitespace-pre overflow-x-auto text-[10px] leading-snug mt-1 text-gray-500 dark:text-gray-400",children:Tr(F.metadata.stack)}),F.metadata&&!F.metadata.stack&&Object.keys(F.metadata).length>0&&jsxRuntime.jsx("div",{className:"ml-[180px] mt-1 text-gray-500 dark:text-gray-400",children:Object.entries(F.metadata).map(([Y,fe])=>jsxRuntime.jsxs("span",{className:"mr-4",children:[jsxRuntime.jsxs("span",{className:"font-medium",children:[Y,":"]})," ",typeof fe=="object"?JSON.stringify(fe):String(fe)]},Y))})]},F.id),et=[...q].sort((F,Y)=>{let fe=F.filename||F.name||"",ke=Y.filename||Y.name||"",le=0;switch(vr){case "filename":le=fe.localeCompare(ke);break;case "size":le=F.size-Y.size;break;case "modified":le=new Date(F.modified).getTime()-new Date(Y.modified).getTime();break}return Ko==="asc"?le:-le}),er=F=>{vr===F?Xo(Y=>Y==="asc"?"desc":"asc"):(Ls(F),Xo("desc"));},Lt=({field:F})=>vr!==F?jsxRuntime.jsx(lucideReact.ArrowUpDown,{className:"h-3 w-3 ml-1 opacity-50"}):Ko==="asc"?jsxRuntime.jsx(lucideReact.ArrowUp,{className:"h-3 w-3 ml-1"}):jsxRuntime.jsx(lucideReact.ArrowDown,{className:"h-3 w-3 ml-1"}),kO=async()=>{if(!(!Mt||!s)){try{await s(Mt),j(F=>F.filter(Y=>(Y.filename||Y.name)!==Mt)),sonner.toast.success("Archive deleted successfully");}catch{sonner.toast.error("Failed to delete archive");}Re(null);}},EO=A?R:R.filter(F=>F.id!=="archives");return jsxRuntime.jsxs("div",{className:I("space-y-6",H),children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h1",{className:"text-3xl font-bold",children:"Logs"}),jsxRuntime.jsxs("div",{className:"text-muted-foreground flex items-center",children:["View system logs and diagnostic information \u2022 Current level:"," ",jsxRuntime.jsx(tt,{className:I("ml-1 text-xs px-2 py-0",x[M]||x.info),children:M.toUpperCase()})]})]}),jsxRuntime.jsx("div",{className:"flex items-center gap-4",children:E==="current"&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[c>0&&jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(jt,{id:"auto-refresh",checked:Ve,onCheckedChange:nt}),jsxRuntime.jsx(Ct,{htmlFor:"auto-refresh",className:"text-sm cursor-pointer",children:"Auto-refresh"})]}),p&&jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(jt,{id:"auto-scroll",checked:C,onCheckedChange:K}),jsxRuntime.jsx(Ct,{htmlFor:"auto-scroll",className:"text-sm cursor-pointer",children:"Auto-scroll"})]}),jsxRuntime.jsx("div",{className:"h-6 w-px bg-border"}),r&&jsxRuntime.jsxs(V,{variant:"outline",size:"sm",onClick:()=>r().then(F=>F&&D(O($(F)))),children:[jsxRuntime.jsx(lucideReact.RefreshCw,{className:"h-4 w-4 mr-2"}),"Refresh"]}),N&&jsxRuntime.jsxs(V,{variant:"outline",size:"sm",onClick:Ot,children:[jsxRuntime.jsx(lucideReact.Copy,{className:"h-4 w-4 mr-2"}),"Copy"]}),S&&jsxRuntime.jsxs(V,{variant:"outline",size:"sm",onClick:xe,children:[jsxRuntime.jsx(lucideReact.Download,{className:"h-4 w-4 mr-2"}),"Export"]}),o&&w&&jsxRuntime.jsxs(V,{variant:"destructive",size:"sm",onClick:()=>Fe(true),children:[jsxRuntime.jsx(lucideReact.Trash2,{className:"h-4 w-4 mr-2"}),"Delete"]})]})})]}),jsxRuntime.jsxs("div",{className:"flex gap-6",children:[P&&jsxRuntime.jsx(Ne,{className:"w-64 h-fit",children:jsxRuntime.jsxs("div",{className:"p-4",children:[jsxRuntime.jsx("h3",{className:"font-semibold mb-4",children:"Categories"}),jsxRuntime.jsx("div",{className:"space-y-1",children:EO.map(F=>{let Y=F.icon;return jsxRuntime.jsxs("button",{onClick:()=>z(F.id),className:I("w-full flex items-center gap-3 px-3 py-2 rounded-md text-sm transition-colors",E===F.id?"bg-primary text-primary-foreground":"hover:bg-muted"),children:[jsxRuntime.jsx(Y,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{className:"text-left",children:F.label})]},F.id)})})]})}),jsxRuntime.jsx("div",{className:"flex-1",children:E==="archives"?jsxRuntime.jsxs(Ne,{className:"p-0 overflow-hidden",children:[jsxRuntime.jsxs("div",{className:"px-6 py-4 border-b",children:[jsxRuntime.jsx("h2",{className:"text-xl font-semibold",children:"Log Archives"}),jsxRuntime.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Download or manage archived log files \u2022 ",et.length," file",et.length!==1?"s":""]})]}),et.length===0?jsxRuntime.jsx("div",{className:"p-6",children:jsxRuntime.jsxs(ot,{children:[jsxRuntime.jsx(lucideReact.AlertCircle,{className:"h-4 w-4"}),jsxRuntime.jsx(at,{children:"No archived log files available"})]})}):jsxRuntime.jsx("div",{className:"overflow-auto",style:{maxHeight:v},children:jsxRuntime.jsxs("table",{className:"w-full",children:[jsxRuntime.jsx("thead",{className:"bg-muted/50 sticky top-0",children:jsxRuntime.jsxs("tr",{children:[jsxRuntime.jsx("th",{className:"text-left px-4 py-2 font-medium text-sm",children:jsxRuntime.jsxs("button",{className:"flex items-center hover:text-foreground",onClick:()=>er("filename"),children:["Name",jsxRuntime.jsx(Lt,{field:"filename"})]})}),jsxRuntime.jsx("th",{className:"text-right px-4 py-2 font-medium text-sm w-28",children:jsxRuntime.jsxs("button",{className:"flex items-center justify-end hover:text-foreground ml-auto",onClick:()=>er("size"),children:["Size",jsxRuntime.jsx(Lt,{field:"size"})]})}),jsxRuntime.jsx("th",{className:"text-right px-4 py-2 font-medium text-sm w-36",children:jsxRuntime.jsxs("button",{className:"flex items-center justify-end hover:text-foreground ml-auto",onClick:()=>er("modified"),children:["Modified",jsxRuntime.jsx(Lt,{field:"modified"})]})}),jsxRuntime.jsx("th",{className:"text-right px-4 py-2 font-medium text-sm w-24",children:"Actions"})]})}),jsxRuntime.jsx("tbody",{children:et.map(F=>{let Y=F.filename||F.name||"unknown";return jsxRuntime.jsxs("tr",{className:"border-t hover:bg-muted/30",children:[jsxRuntime.jsx("td",{className:"px-4 py-2",children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.Archive,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),jsxRuntime.jsx("span",{className:"font-mono text-sm truncate",children:Y})]})}),jsxRuntime.jsx("td",{className:"px-4 py-2 text-right text-sm text-muted-foreground font-mono",children:Wt(F.size)}),jsxRuntime.jsx("td",{className:"px-4 py-2 text-right text-sm text-muted-foreground",children:dateFns.format(new Date(F.modified),"MMM d, yyyy HH:mm")}),jsxRuntime.jsx("td",{className:"px-4 py-2 text-right",children:jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-1",children:[i&&jsxRuntime.jsx(V,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>i(Y),title:"Download",children:jsxRuntime.jsx(lucideReact.Download,{className:"h-4 w-4"})}),s&&jsxRuntime.jsx(V,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-destructive hover:text-destructive",onClick:()=>Re(Y),title:"Delete",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"h-4 w-4"})})]})})]},Y)})})]})})]}):jsxRuntime.jsxs(Ne,{className:"p-0 overflow-hidden",children:[jsxRuntime.jsx("div",{className:"px-4 py-3 border-b bg-gray-50 dark:bg-gray-900 flex items-center justify-between",children:jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[h&&jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Level:"}),jsxRuntime.jsxs(St,{value:pe,onValueChange:De,children:[jsxRuntime.jsx(ut,{className:"w-36 h-8",children:jsxRuntime.jsx(kt,{children:pe==="all"?jsxRuntime.jsx("span",{children:"All Levels"}):jsxRuntime.jsx(sr,{level:pe})})}),jsxRuntime.jsxs(dt,{children:[jsxRuntime.jsx(Me,{value:"all",children:"All Levels"}),jsxRuntime.jsx(Me,{value:"error",children:jsxRuntime.jsx(sr,{level:"error"})}),jsxRuntime.jsx(Me,{value:"warn",children:jsxRuntime.jsx(sr,{level:"warn"})}),jsxRuntime.jsx(Me,{value:"info",children:jsxRuntime.jsx(sr,{level:"info"})}),jsxRuntime.jsx(Me,{value:"debug",children:jsxRuntime.jsx(sr,{level:"debug"})}),jsxRuntime.jsx(Me,{value:"verbose",children:jsxRuntime.jsx(sr,{level:"verbose"})})]})]})]}),h&&Se.length>0&&jsxRuntime.jsxs(St,{value:Ue,onValueChange:Pe,children:[jsxRuntime.jsx(ut,{className:"w-44 h-8",children:jsxRuntime.jsx(kt,{})}),jsxRuntime.jsxs(dt,{children:[jsxRuntime.jsx(Me,{value:"all",children:"All Categories"}),Se.map(F=>jsxRuntime.jsx(Me,{value:F,children:F},F))]})]}),b&&jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx(lucideReact.Search,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400"}),jsxRuntime.jsx("input",{type:"text",placeholder:"Search logs...",value:Q,onChange:F=>T(F.target.value),className:"pl-8 pr-3 py-1.5 text-sm border rounded-md w-64 focus:outline-none focus:ring-2 focus:ring-primary"})]})]})}),jsxRuntime.jsx("div",{className:I("bg-white dark:bg-gray-900"),style:{height:v},children:re?jsxRuntime.jsx("div",{className:"flex items-center justify-center h-full",children:jsxRuntime.jsx("div",{className:"h-8 w-8 rounded-full border-2 border-gray-300 border-t-transparent animate-spin"})}):L.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center h-full text-gray-400",children:jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx(lucideReact.Terminal,{className:"h-12 w-12 mx-auto mb-2 opacity-50"}),jsxRuntime.jsx("p",{children:"No logs to display"}),jsxRuntime.jsx("p",{className:"text-xs mt-1",children:"Logs will appear here as they are generated"})]})}):jsxRuntime.jsx(reactVirtuoso.Virtuoso,{ref:J,data:L,followOutput:C?"smooth":false,overscan:200,itemContent:(F,Y)=>Wr(Y),style:{height:"100%"}})}),jsxRuntime.jsx("div",{className:"border-t bg-muted/50 px-4 py-2 flex justify-between items-center",children:jsxRuntime.jsxs("div",{className:"text-sm text-muted-foreground",children:[L.length," ",L.length===1?"line":"lines"]})})]})})]}),jsxRuntime.jsx(io,{open:ge,onOpenChange:Fe,title:"Delete Logs",description:"Are you sure you want to delete all logs? This action cannot be undone.",confirmLabel:"Delete",variant:"destructive",onConfirm:me}),jsxRuntime.jsx(io,{open:!!Mt,onOpenChange:F=>!F&&Re(null),title:"Delete Archive",description:`Are you sure you want to delete "${Mt}"? This action cannot be undone.`,confirmLabel:"Delete",variant:"destructive",onConfirm:kO})]})}var Qr=class extends Error{constructor(t,r,n){super(t),this.name="ApiError",this.status=r,this.details=n;}};function Y1(){return window.__TAURI__?"http://localhost:3000":undefined?.VITE_API_URL?undefined.VITE_API_URL:""}async function la(e,t={}){let{timeout:r=3e4,retries:n=0,retryDelay:o=1e3,...a}=t,s=`${Y1()}${e}`,l=new Headers(a.headers);!l.has("Content-Type")&&a.body&&typeof a.body=="string"&&l.set("Content-Type","application/json");let c=new AbortController,d=setTimeout(()=>c.abort(),r),u=null;for(let g=0;g<=n;g++)try{let p=await fetch(s,{...a,headers:l,signal:c.signal});clearTimeout(d);let f=p.headers.get("content-type"),m;if(f?.includes("application/json")?m=await p.json():m=await p.text(),typeof m=="object"&&"success"in m){let b=m;if(!b.success)throw new Qr(b.error||b.message||"Request failed",p.status,b.details);return b.data??b.logs??b.files??b.entries??b.items??b}if(!p.ok)throw new Qr(m.message||m.error||`HTTP ${p.status}`,p.status);return m}catch(p){if(u=p,p instanceof Qr&&p.status<500)throw p;if(p instanceof Error&&p.name==="AbortError")throw new Qr("Request timeout",408);g<n&&await new Promise(f=>setTimeout(f,o*(g+1)));}throw clearTimeout(d),u||new Qr("Request failed",500)}function K1({apiUrl:e="/api/logs"}){let t=lr.useCallback(async()=>{try{let a=await la(`${e}/entries`);return a?.entries||a?.logs||[]}catch(a){return console.warn("Failed to fetch logs:",a),[]}},[e]),r=lr.useCallback(async()=>{try{let a=await la(`${e}/files`);return (a?.files||a?.archives||[]).map(i=>({filename:i.filename||i.name,name:i.name,size:i.size,modified:i.modified}))}catch(a){return console.warn("Failed to fetch archives:",a),[]}},[e]),n=lr.useCallback(async()=>{await la(`${e}/clear`,{method:"POST"});},[e]),o=lr.useCallback(a=>{window.open(`${e}/download/${a}`,"_blank");},[e]);return jsxRuntime.jsx(Js,{onFetchLogs:t,onFetchArchives:r,onClearLogs:n,onDownloadArchive:o,enableSearch:true,enableFilter:true,enableExport:true,enableClear:true,enableAutoScroll:true,showCategories:true,showArchives:true,height:"calc(100vh - 200px)"})}function he(...e){return tailwindMerge.twMerge(clsx.clsx(e))}function el({show:e,onRestart:t,onDismiss:r,className:n}){let[o,a]=lr.useState(e),[i,s]=lr.useState(false);return lr.useEffect(()=>{e?(a(true),setTimeout(()=>s(true),10)):(s(false),setTimeout(()=>a(false),300));},[e]),o?jsxRuntime.jsx("div",{className:he("fixed top-0 left-0 right-0 z-50 transition-all duration-300 ease-in-out",i?"translate-y-0 opacity-100":"-translate-y-full opacity-0",n),children:jsxRuntime.jsxs(ot,{className:"rounded-none border-x-0 border-t-0 bg-amber-50 dark:bg-amber-950/50",children:[jsxRuntime.jsx(lucideReact.AlertCircle,{className:"h-4 w-4 text-amber-600 dark:text-amber-400"}),jsxRuntime.jsxs(at,{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-amber-800 dark:text-amber-200",children:"Configuration changes require a restart to take effect"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[t&&jsxRuntime.jsxs(V,{size:"sm",variant:"default",onClick:t,className:"bg-amber-600 hover:bg-amber-700 text-white",children:[jsxRuntime.jsx(lucideReact.RefreshCw,{className:"h-3 w-3 mr-1"}),"Restart Now"]}),r&&jsxRuntime.jsx(V,{size:"sm",variant:"ghost",onClick:r,className:"text-amber-700 hover:text-amber-800 dark:text-amber-300 dark:hover:text-amber-200",children:jsxRuntime.jsx(lucideReact.X,{className:"h-3 w-3"})})]})]})]})}):null}function lL({categories:e,values:t,loading:r=false,saving:n=false,onSave:o,onReset:a,onRestart:i,showRestartBanner:s=false,className:l,title:c="Settings"}){let[d,u]=lr.useState(t),[g,p]=lr.useState({}),[f,m]=lr.useState(e[0]?.id||""),[b,h]=lr.useState({}),[S,w]=lr.useState(false),N=(A,v)=>{u(_=>({..._,[A]:v})),w(true);let H=e.flatMap(_=>_.settings).find(_=>_.key===A);if(H?.validation){let _=H.validation(v);p(D=>({...D,[A]:_||""}));}},R=async()=>{let A={},v=false;if(e.forEach(H=>{H.settings.forEach(_=>{if(_.validation){let D=_.validation(d[_.key]);D&&(A[_.key]=D,v=true);}});}),v){p(A);return}await o(d),w(false);},x=()=>{u(t),p({}),w(false),a&&a();},M=e.find(A=>A.id===f)?.settings||[],P=A=>{let v=d[A.key]??A.defaultValue,H=g[A.key];switch(A.type){case "text":return jsxRuntime.jsx(yt,{value:v||"",onChange:_=>N(A.key,_.target.value),placeholder:A.placeholder,className:H?"border-red-500":""});case "password":return jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx(yt,{type:b[A.key]?"text":"password",value:v||"",onChange:_=>N(A.key,_.target.value),placeholder:A.placeholder,className:he("pr-10",H?"border-red-500":"")}),jsxRuntime.jsx("button",{type:"button",onClick:()=>h(_=>({..._,[A.key]:!_[A.key]})),className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700",children:b[A.key]?jsxRuntime.jsx(lucideReact.EyeOff,{className:"h-4 w-4"}):jsxRuntime.jsx(lucideReact.Eye,{className:"h-4 w-4"})})]});case "number":return jsxRuntime.jsx(yt,{type:"number",value:v||"",onChange:_=>N(A.key,parseFloat(_.target.value)),min:A.min,max:A.max,placeholder:A.placeholder,className:H?"border-red-500":""});case "boolean":return jsxRuntime.jsx(jt,{checked:v||false,onCheckedChange:_=>N(A.key,_)});case "select":return jsxRuntime.jsxs(St,{value:String(v||""),onValueChange:_=>N(A.key,_),children:[jsxRuntime.jsx(ut,{className:H?"border-red-500":"",children:jsxRuntime.jsx(kt,{placeholder:"Select an option"})}),jsxRuntime.jsx(dt,{children:A.options?.map(_=>jsxRuntime.jsx(Me,{value:_.value,children:_.label},_.value))})]});case "custom":return A.customComponent;default:return null}};return r?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8",children:jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto mb-4"}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading settings..."})]})}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[s&&jsxRuntime.jsx(el,{show:true,onRestart:i,onDismiss:()=>{}}),jsxRuntime.jsxs("div",{className:he("space-y-6",l),children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-center",children:[jsxRuntime.jsx("h1",{className:"text-2xl font-bold",children:c}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsxs(V,{variant:"outline",size:"sm",onClick:x,disabled:!S||n,children:[jsxRuntime.jsx(lucideReact.RotateCcw,{className:"h-4 w-4"}),"Reset"]}),jsxRuntime.jsx(V,{size:"sm",onClick:R,disabled:!S||n||Object.keys(g).some(A=>g[A]),children:n?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-white"}),"Saving..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.Save,{className:"h-4 w-4"}),"Save Changes"]})})]})]}),jsxRuntime.jsxs("div",{className:"grid grid-cols-12 gap-6",children:[jsxRuntime.jsx("div",{className:"col-span-3",children:jsxRuntime.jsx(Ne,{className:"p-2",children:e.map(A=>jsxRuntime.jsxs("button",{onClick:()=>m(A.id),className:he("w-full text-left px-3 py-2 rounded-md transition-colors flex items-center gap-2",f===A.id?"bg-primary text-primary-foreground":"hover:bg-gray-100 dark:hover:bg-gray-800"),children:[A.icon,jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{className:"font-medium",children:A.label}),A.description&&jsxRuntime.jsx("div",{className:"text-xs opacity-70",children:A.description})]})]},A.id))})}),jsxRuntime.jsx("div",{className:"col-span-9",children:jsxRuntime.jsx(Ne,{className:"p-6",children:jsxRuntime.jsx("div",{className:"space-y-6",children:M.map(A=>jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("div",{className:"flex items-center justify-between",children:jsxRuntime.jsxs(Ct,{htmlFor:A.key,children:[A.label,A.requiresRestart&&jsxRuntime.jsx("span",{className:"ml-2 text-xs text-amber-600",children:"(Requires restart)"})]})}),A.description&&jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:A.description}),P(A),g[A.key]&&jsxRuntime.jsxs(ot,{variant:"destructive",className:"py-2",children:[jsxRuntime.jsx(lucideReact.AlertCircle,{className:"h-4 w-4"}),jsxRuntime.jsx(at,{children:g[A.key]})]})]},A.key))})})})]})]})]})}function pa({url:e,className:t,checkInterval:r=5e3}){let[n,o]=lr.useState(false),[a,i]=lr.useState(true),s=lr.useRef(false);lr.useEffect(()=>{if(s.current)return;s.current=true;let u=true,g=e||"",p=async()=>{if(u)try{let m=await fetch(`${g}/api/health`,{credentials:"include"});u&&(o(m.ok),i(!1));}catch{u&&(o(false),i(false));}};p();let f=setInterval(p,r);return ()=>{u=false,clearInterval(f),s.current=false;}},[]);let l=a?"bg-gray-400":n?"bg-green-500":"bg-red-500",c=a?"Checking...":n?"Connected":"Disconnected",d=a?"Checking connection to backend API...":n?"Frontend is connected to the backend API via WebSockets. Real-time updates are enabled.":"Cannot connect to the backend API. Please check if the backend server is running.";return jsxRuntime.jsx(na,{children:jsxRuntime.jsxs(oa,{children:[jsxRuntime.jsx(aa,{asChild:true,children:jsxRuntime.jsxs("button",{className:he("inline-flex items-center gap-2 px-3 py-1 rounded-full","bg-gray-800/50 backdrop-blur-sm","hover:bg-gray-800/70 transition-all duration-200","cursor-default select-none",t),type:"button","aria-label":`Connection status: ${c}`,children:[jsxRuntime.jsxs("div",{className:"relative flex items-center justify-center w-2 h-2",children:[jsxRuntime.jsx("div",{className:he("absolute w-2 h-2 rounded-full transition-all duration-300",l,n&&"shadow-lg shadow-green-500/50")}),n&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"absolute w-2 h-2 rounded-full bg-green-500 opacity-75",style:{animation:"calm-ping 3s cubic-bezier(0, 0, 0.2, 1) infinite"}}),jsxRuntime.jsx("div",{className:"absolute w-2 h-2 rounded-full bg-green-500 opacity-50",style:{animation:"calm-ping 3s cubic-bezier(0, 0, 0.2, 1) infinite 1s"}})]})]}),jsxRuntime.jsx("span",{className:"text-xs font-medium",children:c})]})}),jsxRuntime.jsx(oo,{side:"bottom",className:"max-w-xs",children:jsxRuntime.jsx("p",{className:"text-sm",children:d})})]})})}if(typeof document<"u"){let e=document.createElement("style");e.textContent=`
11
+ `);await navigator.clipboard.writeText(F),sonner.toast.success("Logs copied to clipboard");}catch{sonner.toast.error("Failed to copy logs");}},qt=F=>{try{let Y=new Date(F);return dateFns.format(Y,"yyyy-MM-dd HH:mm:ss.SSS")}catch{return F}},Wt=F=>F<1024?`${F} B`:F<1024*1024?`${(F/1024).toFixed(1)} KB`:`${(F/(1024*1024)).toFixed(1)} MB`,Tr=F=>F?F.replace(/\x1b\[[0-9;]*m/g,"").replace(/\u001b\[[0-9;]*m/g,"").replace(/\x1b\[[0-9;]*m/g,"").replace(/\[[0-9;]+m/g,"").replace(/\[[\d;]*m/g,""):"",Wr=F=>jsxRuntime.jsxs("div",{className:"px-3 py-2 font-mono text-xs border-b border-gray-100 dark:border-gray-800 text-gray-800 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-900",children:[jsxRuntime.jsxs("div",{className:"flex items-start gap-2",children:[jsxRuntime.jsx("span",{className:"text-gray-500 dark:text-gray-400 whitespace-nowrap",children:qt(F.timestamp)}),jsxRuntime.jsx("span",{className:"flex-shrink-0",children:jsxRuntime.jsx(sr,{level:F.level})}),(F.category||F.source)&&jsxRuntime.jsxs("span",{className:"text-gray-600 dark:text-gray-400 whitespace-nowrap",children:["[",F.category||F.source,"]"]}),jsxRuntime.jsx("span",{className:"whitespace-pre-wrap break-all",children:Tr(F.message)})]}),F.metadata?.stack&&jsxRuntime.jsx("pre",{className:"ml-[180px] whitespace-pre overflow-x-auto text-[10px] leading-snug mt-1 text-gray-500 dark:text-gray-400",children:Tr(F.metadata.stack)}),F.metadata&&!F.metadata.stack&&Object.keys(F.metadata).length>0&&jsxRuntime.jsx("div",{className:"ml-[180px] mt-1 text-gray-500 dark:text-gray-400",children:Object.entries(F.metadata).map(([Y,fe])=>jsxRuntime.jsxs("span",{className:"mr-4",children:[jsxRuntime.jsxs("span",{className:"font-medium",children:[Y,":"]})," ",typeof fe=="object"?JSON.stringify(fe):String(fe)]},Y))})]},F.id),et=[...q].sort((F,Y)=>{let fe=F.filename||F.name||"",ke=Y.filename||Y.name||"",le=0;switch(vr){case "filename":le=fe.localeCompare(ke);break;case "size":le=F.size-Y.size;break;case "modified":le=new Date(F.modified).getTime()-new Date(Y.modified).getTime();break}return Ko==="asc"?le:-le}),er=F=>{vr===F?Xo(Y=>Y==="asc"?"desc":"asc"):(Ls(F),Xo("desc"));},Lt=({field:F})=>vr!==F?jsxRuntime.jsx(lucideReact.ArrowUpDown,{className:"h-3 w-3 ml-1 opacity-50"}):Ko==="asc"?jsxRuntime.jsx(lucideReact.ArrowUp,{className:"h-3 w-3 ml-1"}):jsxRuntime.jsx(lucideReact.ArrowDown,{className:"h-3 w-3 ml-1"}),kO=async()=>{if(!(!Mt||!s)){try{await s(Mt),j(F=>F.filter(Y=>(Y.filename||Y.name)!==Mt)),sonner.toast.success("Archive deleted successfully");}catch{sonner.toast.error("Failed to delete archive");}Re(null);}},EO=A?R:R.filter(F=>F.id!=="archives");return jsxRuntime.jsxs("div",{className:I("space-y-6",H),children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("h1",{className:"text-3xl font-bold",children:"Logs"}),jsxRuntime.jsxs("div",{className:"text-muted-foreground flex items-center",children:["View system logs and diagnostic information \u2022 Current level:"," ",jsxRuntime.jsx(tt,{className:I("ml-1 text-xs px-2 py-0",x[M]||x.info),children:M.toUpperCase()})]})]}),jsxRuntime.jsx("div",{className:"flex items-center gap-4",children:E==="current"&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[c>0&&jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(jt,{id:"auto-refresh",checked:Ve,onCheckedChange:nt}),jsxRuntime.jsx(Ct,{htmlFor:"auto-refresh",className:"text-sm cursor-pointer",children:"Auto-refresh"})]}),p&&jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(jt,{id:"auto-scroll",checked:C,onCheckedChange:K}),jsxRuntime.jsx(Ct,{htmlFor:"auto-scroll",className:"text-sm cursor-pointer",children:"Auto-scroll"})]}),jsxRuntime.jsx("div",{className:"h-6 w-px bg-border"}),r&&jsxRuntime.jsxs(V,{variant:"outline",size:"sm",onClick:()=>r().then(F=>F&&D(O($(F)))),children:[jsxRuntime.jsx(lucideReact.RefreshCw,{className:"h-4 w-4 mr-2"}),"Refresh"]}),N&&jsxRuntime.jsxs(V,{variant:"outline",size:"sm",onClick:Ot,children:[jsxRuntime.jsx(lucideReact.Copy,{className:"h-4 w-4 mr-2"}),"Copy"]}),S&&jsxRuntime.jsxs(V,{variant:"outline",size:"sm",onClick:xe,children:[jsxRuntime.jsx(lucideReact.Download,{className:"h-4 w-4 mr-2"}),"Export"]}),o&&w&&jsxRuntime.jsxs(V,{variant:"destructive",size:"sm",onClick:()=>Fe(true),children:[jsxRuntime.jsx(lucideReact.Trash2,{className:"h-4 w-4 mr-2"}),"Delete"]})]})})]}),jsxRuntime.jsxs("div",{className:"flex gap-6",children:[P&&jsxRuntime.jsx(Ne,{className:"w-64 h-fit",children:jsxRuntime.jsxs("div",{className:"p-4",children:[jsxRuntime.jsx("h3",{className:"font-semibold mb-4",children:"Categories"}),jsxRuntime.jsx("div",{className:"space-y-1",children:EO.map(F=>{let Y=F.icon;return jsxRuntime.jsxs("button",{onClick:()=>z(F.id),className:I("w-full flex items-center gap-3 px-3 py-2 rounded-md text-sm transition-colors",E===F.id?"bg-primary text-primary-foreground":"hover:bg-muted"),children:[jsxRuntime.jsx(Y,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{className:"text-left",children:F.label})]},F.id)})})]})}),jsxRuntime.jsx("div",{className:"flex-1",children:E==="archives"?jsxRuntime.jsxs(Ne,{className:"p-0 overflow-hidden",children:[jsxRuntime.jsxs("div",{className:"px-6 py-4 border-b",children:[jsxRuntime.jsx("h2",{className:"text-xl font-semibold",children:"Log Archives"}),jsxRuntime.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Download or manage archived log files \u2022 ",et.length," file",et.length!==1?"s":""]})]}),et.length===0?jsxRuntime.jsx("div",{className:"p-6",children:jsxRuntime.jsxs(ot,{children:[jsxRuntime.jsx(lucideReact.AlertCircle,{className:"h-4 w-4"}),jsxRuntime.jsx(at,{children:"No archived log files available"})]})}):jsxRuntime.jsx("div",{className:"overflow-auto",style:{maxHeight:v},children:jsxRuntime.jsxs("table",{className:"w-full",children:[jsxRuntime.jsx("thead",{className:"bg-background sticky top-0 z-10 border-b",children:jsxRuntime.jsxs("tr",{children:[jsxRuntime.jsx("th",{className:"text-left px-4 py-2 font-medium text-sm",children:jsxRuntime.jsxs("button",{className:"flex items-center hover:text-foreground",onClick:()=>er("filename"),children:["Name",jsxRuntime.jsx(Lt,{field:"filename"})]})}),jsxRuntime.jsx("th",{className:"text-right px-4 py-2 font-medium text-sm w-28",children:jsxRuntime.jsxs("button",{className:"flex items-center justify-end hover:text-foreground ml-auto",onClick:()=>er("size"),children:["Size",jsxRuntime.jsx(Lt,{field:"size"})]})}),jsxRuntime.jsx("th",{className:"text-right px-4 py-2 font-medium text-sm w-36",children:jsxRuntime.jsxs("button",{className:"flex items-center justify-end hover:text-foreground ml-auto",onClick:()=>er("modified"),children:["Modified",jsxRuntime.jsx(Lt,{field:"modified"})]})}),jsxRuntime.jsx("th",{className:"text-right px-4 py-2 font-medium text-sm w-24",children:"Actions"})]})}),jsxRuntime.jsx("tbody",{children:et.map(F=>{let Y=F.filename||F.name||"unknown";return jsxRuntime.jsxs("tr",{className:"border-t hover:bg-muted/30",children:[jsxRuntime.jsx("td",{className:"px-4 py-2",children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.Archive,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),jsxRuntime.jsx("span",{className:"font-mono text-sm truncate",children:Y})]})}),jsxRuntime.jsx("td",{className:"px-4 py-2 text-right text-sm text-muted-foreground font-mono",children:Wt(F.size)}),jsxRuntime.jsx("td",{className:"px-4 py-2 text-right text-sm text-muted-foreground",children:dateFns.format(new Date(F.modified),"MMM d, yyyy HH:mm")}),jsxRuntime.jsx("td",{className:"px-4 py-2 text-right",children:jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-1",children:[i&&jsxRuntime.jsx(V,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>i(Y),title:"Download",children:jsxRuntime.jsx(lucideReact.Download,{className:"h-4 w-4"})}),s&&jsxRuntime.jsx(V,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-destructive hover:text-destructive",onClick:()=>Re(Y),title:"Delete",children:jsxRuntime.jsx(lucideReact.Trash2,{className:"h-4 w-4"})})]})})]},Y)})})]})})]}):jsxRuntime.jsxs(Ne,{className:"p-0 overflow-hidden",children:[jsxRuntime.jsx("div",{className:"px-4 py-3 border-b bg-gray-50 dark:bg-gray-900 flex items-center justify-between",children:jsxRuntime.jsxs("div",{className:"flex items-center gap-3",children:[h&&jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Level:"}),jsxRuntime.jsxs(St,{value:pe,onValueChange:De,children:[jsxRuntime.jsx(ut,{className:"w-36 h-8",children:jsxRuntime.jsx(kt,{children:pe==="all"?jsxRuntime.jsx("span",{children:"All Levels"}):jsxRuntime.jsx(sr,{level:pe})})}),jsxRuntime.jsxs(dt,{children:[jsxRuntime.jsx(Me,{value:"all",children:"All Levels"}),jsxRuntime.jsx(Me,{value:"error",children:jsxRuntime.jsx(sr,{level:"error"})}),jsxRuntime.jsx(Me,{value:"warn",children:jsxRuntime.jsx(sr,{level:"warn"})}),jsxRuntime.jsx(Me,{value:"info",children:jsxRuntime.jsx(sr,{level:"info"})}),jsxRuntime.jsx(Me,{value:"debug",children:jsxRuntime.jsx(sr,{level:"debug"})}),jsxRuntime.jsx(Me,{value:"verbose",children:jsxRuntime.jsx(sr,{level:"verbose"})})]})]})]}),h&&Se.length>0&&jsxRuntime.jsxs(St,{value:Ue,onValueChange:Pe,children:[jsxRuntime.jsx(ut,{className:"w-44 h-8",children:jsxRuntime.jsx(kt,{})}),jsxRuntime.jsxs(dt,{children:[jsxRuntime.jsx(Me,{value:"all",children:"All Categories"}),Se.map(F=>jsxRuntime.jsx(Me,{value:F,children:F},F))]})]}),b&&jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx(lucideReact.Search,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400"}),jsxRuntime.jsx("input",{type:"text",placeholder:"Search logs...",value:Q,onChange:F=>T(F.target.value),className:"pl-8 pr-3 py-1.5 text-sm border rounded-md w-64 focus:outline-none focus:ring-2 focus:ring-primary"})]})]})}),jsxRuntime.jsx("div",{className:I("bg-white dark:bg-gray-900"),style:{height:v},children:re?jsxRuntime.jsx("div",{className:"flex items-center justify-center h-full",children:jsxRuntime.jsx("div",{className:"h-8 w-8 rounded-full border-2 border-gray-300 border-t-transparent animate-spin"})}):L.length===0?jsxRuntime.jsx("div",{className:"flex items-center justify-center h-full text-gray-400",children:jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx(lucideReact.Terminal,{className:"h-12 w-12 mx-auto mb-2 opacity-50"}),jsxRuntime.jsx("p",{children:"No logs to display"}),jsxRuntime.jsx("p",{className:"text-xs mt-1",children:"Logs will appear here as they are generated"})]})}):jsxRuntime.jsx(reactVirtuoso.Virtuoso,{ref:J,data:L,followOutput:C?"smooth":false,overscan:200,itemContent:(F,Y)=>Wr(Y),style:{height:"100%"}})}),jsxRuntime.jsx("div",{className:"border-t bg-muted/50 px-4 py-2 flex justify-between items-center",children:jsxRuntime.jsxs("div",{className:"text-sm text-muted-foreground",children:[L.length," ",L.length===1?"line":"lines"]})})]})})]}),jsxRuntime.jsx(io,{open:ge,onOpenChange:Fe,title:"Delete Logs",description:"Are you sure you want to delete all logs? This action cannot be undone.",confirmLabel:"Delete",variant:"destructive",onConfirm:me}),jsxRuntime.jsx(io,{open:!!Mt,onOpenChange:F=>!F&&Re(null),title:"Delete Archive",description:`Are you sure you want to delete "${Mt}"? This action cannot be undone.`,confirmLabel:"Delete",variant:"destructive",onConfirm:kO})]})}var Qr=class extends Error{constructor(t,r,n){super(t),this.name="ApiError",this.status=r,this.details=n;}};function Y1(){return window.__TAURI__?"http://localhost:3000":undefined?.VITE_API_URL?undefined.VITE_API_URL:""}async function la(e,t={}){let{timeout:r=3e4,retries:n=0,retryDelay:o=1e3,...a}=t,s=`${Y1()}${e}`,l=new Headers(a.headers);!l.has("Content-Type")&&a.body&&typeof a.body=="string"&&l.set("Content-Type","application/json");let c=new AbortController,d=setTimeout(()=>c.abort(),r),u=null;for(let g=0;g<=n;g++)try{let p=await fetch(s,{...a,headers:l,signal:c.signal});clearTimeout(d);let f=p.headers.get("content-type"),m;if(f?.includes("application/json")?m=await p.json():m=await p.text(),typeof m=="object"&&"success"in m){let b=m;if(!b.success)throw new Qr(b.error||b.message||"Request failed",p.status,b.details);return b.data??b.logs??b.files??b.entries??b.items??b}if(!p.ok)throw new Qr(m.message||m.error||`HTTP ${p.status}`,p.status);return m}catch(p){if(u=p,p instanceof Qr&&p.status<500)throw p;if(p instanceof Error&&p.name==="AbortError")throw new Qr("Request timeout",408);g<n&&await new Promise(f=>setTimeout(f,o*(g+1)));}throw clearTimeout(d),u||new Qr("Request failed",500)}function K1({apiUrl:e="/api/logs"}){let t=lr.useCallback(async()=>{try{let a=await la(`${e}/entries`);return a?.entries||a?.logs||[]}catch(a){return console.warn("Failed to fetch logs:",a),[]}},[e]),r=lr.useCallback(async()=>{try{let a=await la(`${e}/files`);return (a?.files||a?.archives||[]).map(i=>({filename:i.filename||i.name,name:i.name,size:i.size,modified:i.modified}))}catch(a){return console.warn("Failed to fetch archives:",a),[]}},[e]),n=lr.useCallback(async()=>{await la(`${e}/clear`,{method:"POST"});},[e]),o=lr.useCallback(a=>{window.open(`${e}/download/${a}`,"_blank");},[e]);return jsxRuntime.jsx(Js,{onFetchLogs:t,onFetchArchives:r,onClearLogs:n,onDownloadArchive:o,enableSearch:true,enableFilter:true,enableExport:true,enableClear:true,enableAutoScroll:true,showCategories:true,showArchives:true,height:"calc(100vh - 200px)"})}function he(...e){return tailwindMerge.twMerge(clsx.clsx(e))}function el({show:e,onRestart:t,onDismiss:r,className:n}){let[o,a]=lr.useState(e),[i,s]=lr.useState(false);return lr.useEffect(()=>{e?(a(true),setTimeout(()=>s(true),10)):(s(false),setTimeout(()=>a(false),300));},[e]),o?jsxRuntime.jsx("div",{className:he("fixed top-0 left-0 right-0 z-50 transition-all duration-300 ease-in-out",i?"translate-y-0 opacity-100":"-translate-y-full opacity-0",n),children:jsxRuntime.jsxs(ot,{className:"rounded-none border-x-0 border-t-0 bg-amber-50 dark:bg-amber-950/50",children:[jsxRuntime.jsx(lucideReact.AlertCircle,{className:"h-4 w-4 text-amber-600 dark:text-amber-400"}),jsxRuntime.jsxs(at,{className:"flex items-center justify-between",children:[jsxRuntime.jsx("span",{className:"text-amber-800 dark:text-amber-200",children:"Configuration changes require a restart to take effect"}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[t&&jsxRuntime.jsxs(V,{size:"sm",variant:"default",onClick:t,className:"bg-amber-600 hover:bg-amber-700 text-white",children:[jsxRuntime.jsx(lucideReact.RefreshCw,{className:"h-3 w-3 mr-1"}),"Restart Now"]}),r&&jsxRuntime.jsx(V,{size:"sm",variant:"ghost",onClick:r,className:"text-amber-700 hover:text-amber-800 dark:text-amber-300 dark:hover:text-amber-200",children:jsxRuntime.jsx(lucideReact.X,{className:"h-3 w-3"})})]})]})]})}):null}function lL({categories:e,values:t,loading:r=false,saving:n=false,onSave:o,onReset:a,onRestart:i,showRestartBanner:s=false,className:l,title:c="Settings"}){let[d,u]=lr.useState(t),[g,p]=lr.useState({}),[f,m]=lr.useState(e[0]?.id||""),[b,h]=lr.useState({}),[S,w]=lr.useState(false),N=(A,v)=>{u(_=>({..._,[A]:v})),w(true);let H=e.flatMap(_=>_.settings).find(_=>_.key===A);if(H?.validation){let _=H.validation(v);p(D=>({...D,[A]:_||""}));}},R=async()=>{let A={},v=false;if(e.forEach(H=>{H.settings.forEach(_=>{if(_.validation){let D=_.validation(d[_.key]);D&&(A[_.key]=D,v=true);}});}),v){p(A);return}await o(d),w(false);},x=()=>{u(t),p({}),w(false),a&&a();},M=e.find(A=>A.id===f)?.settings||[],P=A=>{let v=d[A.key]??A.defaultValue,H=g[A.key];switch(A.type){case "text":return jsxRuntime.jsx(yt,{value:v||"",onChange:_=>N(A.key,_.target.value),placeholder:A.placeholder,className:H?"border-red-500":""});case "password":return jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx(yt,{type:b[A.key]?"text":"password",value:v||"",onChange:_=>N(A.key,_.target.value),placeholder:A.placeholder,className:he("pr-10",H?"border-red-500":"")}),jsxRuntime.jsx("button",{type:"button",onClick:()=>h(_=>({..._,[A.key]:!_[A.key]})),className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700",children:b[A.key]?jsxRuntime.jsx(lucideReact.EyeOff,{className:"h-4 w-4"}):jsxRuntime.jsx(lucideReact.Eye,{className:"h-4 w-4"})})]});case "number":return jsxRuntime.jsx(yt,{type:"number",value:v||"",onChange:_=>N(A.key,parseFloat(_.target.value)),min:A.min,max:A.max,placeholder:A.placeholder,className:H?"border-red-500":""});case "boolean":return jsxRuntime.jsx(jt,{checked:v||false,onCheckedChange:_=>N(A.key,_)});case "select":return jsxRuntime.jsxs(St,{value:String(v||""),onValueChange:_=>N(A.key,_),children:[jsxRuntime.jsx(ut,{className:H?"border-red-500":"",children:jsxRuntime.jsx(kt,{placeholder:"Select an option"})}),jsxRuntime.jsx(dt,{children:A.options?.map(_=>jsxRuntime.jsx(Me,{value:_.value,children:_.label},_.value))})]});case "custom":return A.customComponent;default:return null}};return r?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8",children:jsxRuntime.jsxs("div",{className:"text-center",children:[jsxRuntime.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto mb-4"}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading settings..."})]})}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[s&&jsxRuntime.jsx(el,{show:true,onRestart:i,onDismiss:()=>{}}),jsxRuntime.jsxs("div",{className:he("space-y-6",l),children:[jsxRuntime.jsxs("div",{className:"flex justify-between items-center",children:[jsxRuntime.jsx("h1",{className:"text-2xl font-bold",children:c}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsxs(V,{variant:"outline",size:"sm",onClick:x,disabled:!S||n,children:[jsxRuntime.jsx(lucideReact.RotateCcw,{className:"h-4 w-4"}),"Reset"]}),jsxRuntime.jsx(V,{size:"sm",onClick:R,disabled:!S||n||Object.keys(g).some(A=>g[A]),children:n?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-white"}),"Saving..."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.Save,{className:"h-4 w-4"}),"Save Changes"]})})]})]}),jsxRuntime.jsxs("div",{className:"grid grid-cols-12 gap-6",children:[jsxRuntime.jsx("div",{className:"col-span-3",children:jsxRuntime.jsx(Ne,{className:"p-2",children:e.map(A=>jsxRuntime.jsxs("button",{onClick:()=>m(A.id),className:he("w-full text-left px-3 py-2 rounded-md transition-colors flex items-center gap-2",f===A.id?"bg-primary text-primary-foreground":"hover:bg-gray-100 dark:hover:bg-gray-800"),children:[A.icon,jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("div",{className:"font-medium",children:A.label}),A.description&&jsxRuntime.jsx("div",{className:"text-xs opacity-70",children:A.description})]})]},A.id))})}),jsxRuntime.jsx("div",{className:"col-span-9",children:jsxRuntime.jsx(Ne,{className:"p-6",children:jsxRuntime.jsx("div",{className:"space-y-6",children:M.map(A=>jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("div",{className:"flex items-center justify-between",children:jsxRuntime.jsxs(Ct,{htmlFor:A.key,children:[A.label,A.requiresRestart&&jsxRuntime.jsx("span",{className:"ml-2 text-xs text-amber-600",children:"(Requires restart)"})]})}),A.description&&jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:A.description}),P(A),g[A.key]&&jsxRuntime.jsxs(ot,{variant:"destructive",className:"py-2",children:[jsxRuntime.jsx(lucideReact.AlertCircle,{className:"h-4 w-4"}),jsxRuntime.jsx(at,{children:g[A.key]})]})]},A.key))})})})]})]})]})}function pa({url:e,className:t,checkInterval:r=5e3}){let[n,o]=lr.useState(false),[a,i]=lr.useState(true),s=lr.useRef(false);lr.useEffect(()=>{if(s.current)return;s.current=true;let u=true,g=e||"",p=async()=>{if(u)try{let m=await fetch(`${g}/api/health`,{credentials:"include"});u&&(o(m.ok),i(!1));}catch{u&&(o(false),i(false));}};p();let f=setInterval(p,r);return ()=>{u=false,clearInterval(f),s.current=false;}},[]);let l=a?"bg-gray-400":n?"bg-green-500":"bg-red-500",c=a?"Checking...":n?"Connected":"Disconnected",d=a?"Checking connection to backend API...":n?"Frontend is connected to the backend API via WebSockets. Real-time updates are enabled.":"Cannot connect to the backend API. Please check if the backend server is running.";return jsxRuntime.jsx(na,{children:jsxRuntime.jsxs(oa,{children:[jsxRuntime.jsx(aa,{asChild:true,children:jsxRuntime.jsxs("button",{className:he("inline-flex items-center gap-2 px-3 py-1 rounded-full","bg-gray-800/50 backdrop-blur-sm","hover:bg-gray-800/70 transition-all duration-200","cursor-default select-none",t),type:"button","aria-label":`Connection status: ${c}`,children:[jsxRuntime.jsxs("div",{className:"relative flex items-center justify-center w-2 h-2",children:[jsxRuntime.jsx("div",{className:he("absolute w-2 h-2 rounded-full transition-all duration-300",l,n&&"shadow-lg shadow-green-500/50")}),n&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"absolute w-2 h-2 rounded-full bg-green-500 opacity-75",style:{animation:"calm-ping 3s cubic-bezier(0, 0, 0.2, 1) infinite"}}),jsxRuntime.jsx("div",{className:"absolute w-2 h-2 rounded-full bg-green-500 opacity-50",style:{animation:"calm-ping 3s cubic-bezier(0, 0, 0.2, 1) infinite 1s"}})]})]}),jsxRuntime.jsx("span",{className:"text-xs font-medium",children:c})]})}),jsxRuntime.jsx(oo,{side:"bottom",className:"max-w-xs",children:jsxRuntime.jsx("p",{className:"text-sm",children:d})})]})})}if(typeof document<"u"){let e=document.createElement("style");e.textContent=`
12
12
  @keyframes calm-ping {
13
13
  0% {
14
14
  transform: scale(1);