@camstack/addon-admin-ui 1.1.0 → 1.1.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.
Files changed (74) hide show
  1. package/dist/assets/{AddLocationWizard-g-iCisaY.js → AddLocationWizard-B7NQrvQP.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-Be4jy8Na.js → AddonCollectionPage-D4Wz9_AG.js} +1 -1
  3. package/dist/assets/{Addons-B8Uz3p3b.js → Addons-3i1oLJtd.js} +1 -1
  4. package/dist/assets/{AdminTabs-82KAodwc.js → AdminTabs-exsrTA0L.js} +1 -1
  5. package/dist/assets/{BrokerForm-CMM9A0YF.js → BrokerForm-C4v2xZtu.js} +1 -1
  6. package/dist/assets/{BrokerStep-Cuy5HRqo.js → BrokerStep-BEfPTHLt.js} +1 -1
  7. package/dist/assets/{Capabilities-v-1LhcyN.js → Capabilities-P6llMX3A.js} +1 -1
  8. package/dist/assets/{CapabilityBadges-_mvuGKpR.js → CapabilityBadges-DLXZprJF.js} +1 -1
  9. package/dist/assets/{Cluster-Ct5NThFV.js → Cluster-BrxWKAE8.js} +1 -1
  10. package/dist/assets/{Dashboard-Wvx41atC.js → Dashboard-Cdju_v5B.js} +1 -1
  11. package/dist/assets/{Data-B6aXh0KW.js → Data-BE1rOCo5.js} +1 -1
  12. package/dist/assets/{DetectionIntelligence-C8fXC3er.js → DetectionIntelligence-CNbKejIJ.js} +1 -1
  13. package/dist/assets/{DeviceDetail-YGwPomw3.js → DeviceDetail-9TxNipEW.js} +1 -1
  14. package/dist/assets/{Devices-91ljVfC2.js → Devices-Dme10ten.js} +1 -1
  15. package/dist/assets/{EmbedPlayerPage-CdA-C2RV.js → EmbedPlayerPage-D3b7XSTf.js} +1 -1
  16. package/dist/assets/{FormBuilder-lgISTqit.js → FormBuilder-F0_yVuZJ.js} +1 -1
  17. package/dist/assets/{Identity-4Vbqib91.js → Identity-B0vmD82l.js} +1 -1
  18. package/dist/assets/{IntegrationDetail-CbT-KOnh.js → IntegrationDetail-BX9Vofi9.js} +1 -1
  19. package/dist/assets/{Integrations-Csosdze5.js → Integrations-Ce1LEOJC.js} +1 -1
  20. package/dist/assets/{Integrations-CA9f1mkA.js → Integrations-DLyYA6BJ.js} +1 -1
  21. package/dist/assets/{Logs-BniPjEHE.js → Logs-D6Y707It.js} +1 -1
  22. package/dist/assets/{MotionZonesSettings-CsC6s4D-.js → MotionZonesSettings-C-UJsV7d.js} +1 -1
  23. package/dist/assets/{MyAccess-C4uyXRm5.js → MyAccess-CqoZL76B.js} +1 -1
  24. package/dist/assets/{Network-UKU1_Wz1.js → Network-H7Ng5tKj.js} +1 -1
  25. package/dist/assets/{NodeAddonsSettingsPanel-CYN-oFxS.js → NodeAddonsSettingsPanel-CswS1clZ.js} +1 -1
  26. package/dist/assets/{Pipeline-CdUm5Au3.js → Pipeline-Cxw8cc4A.js} +1 -1
  27. package/dist/assets/{PrivacyMaskSettings-CHHQ8IRg.js → PrivacyMaskSettings-BgvCJbvO.js} +1 -1
  28. package/dist/assets/{ProviderIcon-Qs52Bs5y.js → ProviderIcon-C0d_O9nW.js} +1 -1
  29. package/dist/assets/{Settings-C9_KnucX.js → Settings-x2bYRzJT.js} +1 -1
  30. package/dist/assets/{Showroom-3ChHkIOI.js → Showroom-CCvWZtUn.js} +1 -1
  31. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-B5VtjlIx.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Jn-3F1c-.js} +1 -1
  32. package/dist/assets/{bell-DExIwcYQ.js → bell-CnGyOjR-.js} +1 -1
  33. package/dist/assets/circle-check-big-Ba9jjpcr.js +1 -0
  34. package/dist/assets/{copy-Dbvs5ZFj.js → copy-COQXB9NT.js} +1 -1
  35. package/dist/assets/{dist-DivYVFrG.js → dist-CF8BeEGh.js} +1 -1
  36. package/dist/assets/dist-CNPLri82.js +1 -0
  37. package/dist/assets/{download-uGUg4MiO.js → download-D5j8EDrN.js} +1 -1
  38. package/dist/assets/{esm-BxvhK64b.js → esm-Dc9m00q0.js} +1 -1
  39. package/dist/assets/{hostInit-BA6qu1oM.js → hostInit-BnPitclL.js} +1 -1
  40. package/dist/assets/{index-CmHNa_oF.js → index-BW7XX5wA.js} +3 -3
  41. package/dist/assets/{key-round-Dv37pGLu.js → key-round-B7aAsiul.js} +1 -1
  42. package/dist/assets/{mf-entry-bootstrap-0-3ed6fffa.js → mf-entry-bootstrap-0-9a2ad04d.js} +2 -2
  43. package/dist/assets/{pencil-Bhm5xitE.js → pencil-DK4zkTC6.js} +1 -1
  44. package/dist/assets/{player-overlays-BD7QrhVv.js → player-overlays-C7uO3QRz.js} +1 -1
  45. package/dist/assets/plus-BhEoEvZK.js +1 -0
  46. package/dist/assets/{radio-3gUKVJtq.js → radio-Dy8HhsgR.js} +1 -1
  47. package/dist/assets/{refresh-cw-DakczWNP.js → refresh-cw-Da6Dj3o0.js} +1 -1
  48. package/dist/assets/remoteEntry-BTRtJbwS.js +1 -0
  49. package/dist/assets/{rotate-ccw-BWniHp6E.js → rotate-ccw-CvN9zsyg.js} +1 -1
  50. package/dist/assets/rotate-cw-BvT3aWsW.js +1 -0
  51. package/dist/assets/search-b11oabHc.js +1 -0
  52. package/dist/assets/{server-CTIRdXE3.js → server-BXljhg3E.js} +1 -1
  53. package/dist/assets/{sparkles-DjKBLEHs.js → sparkles-DJtFF7Iu.js} +1 -1
  54. package/dist/assets/{square-check-big-dQtGbsrJ.js → square-check-big-DNbPWX7Q.js} +1 -1
  55. package/dist/assets/square-xoGtHzHQ.js +1 -0
  56. package/dist/assets/src-CHN2F0ZH.js +1 -0
  57. package/dist/assets/{src-FrhjLfXG.js → src-OU6ujZuo.js} +4 -4
  58. package/dist/assets/{upload-B3OAHFII.js → upload-B6zuUrvA.js} +1 -1
  59. package/dist/assets/{useDevice-B88gjmGG.js → useDevice-Dvwk7M-g.js} +1 -1
  60. package/dist/assets/{useEventInvalidation-BfLge4TE.js → useEventInvalidation-XemypjzX.js} +1 -1
  61. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CZ1gZe2y.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CIWZjc8E.js} +2 -2
  62. package/dist/assets/{wifi-BXqTH5i3.js → wifi-Ceis20wn.js} +1 -1
  63. package/dist/assets/{zap-BszHFP1r.js → zap-OlmwS3EI.js} +1 -1
  64. package/dist/index.html +5 -5
  65. package/dist/server/addon.js +195 -2
  66. package/package.json +1 -1
  67. package/dist/assets/circle-check-big-B0dF5gJZ.js +0 -1
  68. package/dist/assets/dist-DBAJfCeK.js +0 -1
  69. package/dist/assets/plus-CkYGohZo.js +0 -1
  70. package/dist/assets/remoteEntry-Dhb4tik2.js +0 -1
  71. package/dist/assets/rotate-cw-B9ioWOhh.js +0 -1
  72. package/dist/assets/search-nxykxEeu.js +0 -1
  73. package/dist/assets/square-k19zsBE3.js +0 -1
  74. package/dist/assets/src-DsE0ulBa.js +0 -1
@@ -1 +1 @@
1
- import{$i as e,Lr as t,Pi as n,Vi as r,Vr as i,Wr as a,Zr as o,_r as s,ar as c,dr as l,ea as u,fr as d,g as f,gr as p,h as m,hr as h,ir as g,m as _,mr as v,na as y,pr as b,ta as x,zi as S}from"./src-FrhjLfXG.js";import{G as C,I as w,K as T,S as E,W as D,Z as O,b as k,o as A,x as j,z as M}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{t as N}from"./pencil-Bhm5xitE.js";import{t as P}from"./radio-3gUKVJtq.js";import{t as ee}from"./refresh-cw-DakczWNP.js";import{t as F}from"./rotate-cw-B9ioWOhh.js";import{t as I}from"./server-CTIRdXE3.js";import{t as L}from"./upload-B3OAHFII.js";import{B as R,F as te,L as z,M as B,P as V,i as ne,k as re,o as ie,p as H,s as U,x as W}from"./index-CmHNa_oF.js";import{t as G}from"./format-size-CO9d3C3-.js";import{t as K}from"./NodeAddonsSettingsPanel-CYN-oFxS.js";import{a as q,i as J,n as Y,r as X,t as ae}from"./esm-BxvhK64b.js";var Z=R(`ghost`,[[`path`,{d:`M9 10h.01`,key:`qbtxuw`}],[`path`,{d:`M15 10h.01`,key:`1qmjsl`}],[`path`,{d:`M12 2a8 8 0 0 0-8 8v12l3-3 2.5 2.5L12 19l2.5 2.5L17 19l3 3V10a8 8 0 0 0-8-8z`,key:`uwwb07`}]]),oe=R(`git-fork`,[[`circle`,{cx:`12`,cy:`18`,r:`3`,key:`1mpf1b`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`path`,{d:`M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9`,key:`1uq4wg`}],[`path`,{d:`M12 12v3`,key:`158kv8`}]]),se=R(`memory-stick`,[[`path`,{d:`M6 19v-3`,key:`1nvgqn`}],[`path`,{d:`M10 19v-3`,key:`iu8nkm`}],[`path`,{d:`M14 19v-3`,key:`kcehxu`}],[`path`,{d:`M18 19v-3`,key:`1vh91z`}],[`path`,{d:`M8 11V9`,key:`63erz4`}],[`path`,{d:`M16 11V9`,key:`fru6f3`}],[`path`,{d:`M12 11V9`,key:`ha00sb`}],[`path`,{d:`M2 15h20`,key:`16ne18`}],[`path`,{d:`M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z`,key:`lhddv3`}]]),Q=R(`skull`,[[`path`,{d:`m12.5 17-.5-1-.5 1h1z`,key:`3me087`}],[`path`,{d:`M15 22a1 1 0 0 0 1-1v-1a2 2 0 0 0 1.56-3.25 8 8 0 1 0-11.12 0A2 2 0 0 0 8 20v1a1 1 0 0 0 1 1z`,key:`1o5pge`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}]]),ce=R(`table-2`,[[`path`,{d:`M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18`,key:`gugj83`}]]);O();function le(e){let t=new FormData;return t.append(`file`,e.file,e.file.name),t.append(`nodeId`,e.nodeId),e.addonId&&t.append(`addonId`,e.addonId),new Promise((n,r)=>{let i=new XMLHttpRequest;i.open(`POST`,`/api/addons/upload`),e.token&&i.setRequestHeader(`Authorization`,`Bearer ${e.token}`),i.upload.addEventListener(`progress`,t=>{t.lengthComputable&&e.onProgress(Math.round(t.loaded/t.total*100))}),i.addEventListener(`load`,()=>{let e;try{e=JSON.parse(i.responseText)}catch{r(Error(`HTTP ${i.status}`));return}i.status>=200&&i.status<300?n(e):r(Error(e.error??`HTTP ${i.status}`))}),i.addEventListener(`error`,()=>r(Error(`Network error during upload`))),i.addEventListener(`abort`,()=>r(Error(`Upload aborted`))),i.send(t)})}function ue({nodeId:e,addons:t,isHub:r}){let i=A(),a=n(),[o,c]=T(null),[u,d]=T(null),[f,p]=T(!1),[m,h]=T(null),[g,_]=T(0),v=C(null),y=b(),x=s(),S=l({nodeId:e}),w=S.data??[],D=new Map(t.map(e=>[e.id,e.capabilities])),O=w.length>0?w.map(e=>({id:e.id,status:e.status,capabilities:D.get(e.id)??[],version:e.version,packageName:e.packageName})):t.map(e=>({id:e.id,status:e.status,capabilities:e.capabilities,version:void 0,packageName:void 0})),k=()=>{i.invalidateQueries({queryKey:[[`nodes`,`topology`]]}),S.refetch()},M=async t=>{c(t);try{await y.mutateAsync({nodeId:e,addonId:t}),k()}catch(e){console.error(`Failed to restart addon:`,e)}finally{c(null)}},N=async t=>{if(await a({title:`Uninstall addon`,message:`Remove "${t}" from ${e}? The addon directory will be deleted on disk.`,confirmLabel:`Uninstall`,variant:`danger`})){d(t);try{await x.mutateAsync({nodeId:e,addonId:t}),k()}catch(e){console.error(`Failed to uninstall addon:`,e)}finally{d(null)}}},P=E(`div`,{className:`flex items-center gap-2 mb-2`,children:[j(`input`,{ref:v,type:`file`,accept:`.tgz,.tar.gz`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(n){t.target.value=``,h(null),p(!0),_(0);try{await le({file:n,nodeId:e,token:localStorage.getItem(`camstack_admin_token`),onProgress:_}),k()}catch(e){h(e instanceof Error?e.message:String(e))}finally{p(!1),_(0)}}}}),E(`button`,{onClick:()=>v.current?.click(),disabled:f,className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[f?j(W,{className:`h-3 w-3 animate-spin`}):j(L,{className:`h-3 w-3`}),f?`Uploading… ${g}%`:`Upload addon (.tgz)`]}),f&&j(`div`,{className:`flex-1 h-1 rounded-full bg-muted overflow-hidden max-w-[140px]`,children:j(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${g}%`}})}),m&&j(`span`,{className:`text-[10px] text-destructive`,children:m})]});return O.length===0?E(`div`,{children:[P,j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:S.isLoading?`Loading addons…`:`No addons on this node`})]}):E(`div`,{children:[P,E(`table`,{className:`w-full text-xs`,children:[j(`thead`,{children:E(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`py-2 font-medium`,children:`Addon`}),j(`th`,{className:`py-2 font-medium`,children:`Version`}),j(`th`,{className:`py-2 font-medium`,children:`Capabilities`}),j(`th`,{className:`py-2 font-medium`,children:`Status`}),j(`th`,{className:`py-2 font-medium w-16`})]})}),j(`tbody`,{children:O.map(e=>E(`tr`,{className:`border-t border-border/50`,children:[E(`td`,{className:`py-2 font-medium`,children:[j(`div`,{children:e.id}),e.packageName&&j(`div`,{className:`text-[9px] text-muted-foreground`,children:e.packageName})]}),j(`td`,{className:`py-2 text-muted-foreground`,children:e.version??`—`}),j(`td`,{className:`py-2`,children:j(`div`,{className:`flex flex-wrap gap-1`,children:e.capabilities.length>0?e.capabilities.map(e=>j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400`,children:e},e)):j(`span`,{className:`text-muted-foreground`,children:`—`})})}),j(`td`,{className:`py-2`,children:j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e.status===`running`?`bg-success/10 text-success`:e.status===`error`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e.status})}),j(`td`,{className:`py-2`,children:E(`div`,{className:`flex items-center gap-1 justify-end`,children:[j(`button`,{onClick:()=>M(e.id),disabled:o===e.id||u===e.id,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.id}`,children:j(F,{className:`h-3 w-3 ${o===e.id?`animate-spin`:``}`})}),j(`button`,{onClick:()=>N(e.id),disabled:o===e.id||u===e.id,className:`p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50`,title:`Uninstall ${e.id}`,children:u===e.id?j(W,{className:`h-3 w-3 animate-spin`}):j(U,{className:`h-3 w-3`})})]})})]},e.id))})]})]})}O();function de(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function fe({state:e}){return j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var pe=[`trace`,`debug`,`info`,`warn`,`error`];function me({proc:t,nodeId:n,defaultExpanded:r,activePanel:i,onTogglePanel:a}){let o=t.services??[],s=o.length===1,[c,l]=T(s||r),[d,p]=T(null),[m,g]=T(`info`),S=t.name.includes(`(core)`),C=b(),w=v(),D=h(),O=async e=>{p(e);try{await C.mutateAsync({nodeId:n,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{p(null)}},k=async()=>{p(t.name);try{await w.mutateAsync({nodeId:n,processName:t.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{p(null)}},A=async e=>{let r=`${n}/${t.name}`;try{await D.mutateAsync({nodeId:r,level:e}),g(e)}catch(e){console.error(`Failed to set log level:`,e)}};return E(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[E(`div`,{role:s?void 0:`button`,tabIndex:s?void 0:0,onClick:s?void 0:()=>l(!c),onKeyDown:s?void 0:e=>{(e.key===`Enter`||e.key===` `)&&l(!c)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${s?``:`hover:bg-muted/40 cursor-pointer`}`,children:[s?j(`span`,{className:`h-3 w-3 shrink-0`}):j(c?V:B,{className:`h-3 w-3 text-muted-foreground shrink-0`}),S?j(I,{className:`h-3.5 w-3.5 text-primary shrink-0`}):j(z,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),j(`span`,{className:`text-xs font-semibold flex-1`,children:t.name}),E(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,t.pid]}),j(fe,{state:t.state}),E(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[t.cpuPercent,`% CPU`]}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:G(t.memoryRss)}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:de(t.uptimeSeconds)}),!S&&E(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[E(e,{children:[j(y,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:m}),j(u,{align:`end`,className:`min-w-[70px] py-0.5`,children:pe.map(e=>j(x,{onClick:()=>A(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===m?`text-primary font-semibold`:``}`,children:e},e))})]}),j(`button`,{onClick:k,disabled:d===t.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:j(F,{className:`h-3 w-3 ${d===t.name?`animate-spin`:``}`})})]})]}),c&&o.length>0&&j(`div`,{className:`divide-y divide-border/30`,children:o.map(e=>E(`div`,{children:[E(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[j(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),j(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&E(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&E(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),E(`div`,{className:`flex items-center gap-1 shrink-0`,children:[j(`button`,{onClick:()=>a(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:j(H,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>a(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:j(P,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>O(e.addonId),disabled:d===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:j(F,{className:`h-3 w-3 ${d===e.addonId?`animate-spin`:``}`})})]})]}),i?.addonId===e.addonId&&i.type===`logs`&&j(`div`,{className:`border-t border-border/40 bg-muted/5`,children:j(f,{addonId:e.addonId,agentId:n,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>a(e.addonId,`logs`)})}),i?.addonId===e.addonId&&i.type===`events`&&j(`div`,{className:`border-t border-border/40 bg-muted/5`,children:j(_,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>a(e.addonId,`events`)})})]},e.addonId))}),c&&o.length===0&&j(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function he({nodeId:e,processes:t}){let[n,r]=T(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):j(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>j(me,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}O();function ge(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function _e(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function ve({nodeId:e}){let t=A(),r=n(),[i,a]=T(`all`),o=S(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:s}=c({nodeId:e}),l=o?.processes??s,u=D(()=>l?[...l]:[],[l]),d=D(()=>i===`ghost`?u.filter(e=>e.classification===`ghost`):u,[u,i]),f=D(()=>{let e=u.filter(e=>e.classification===`ghost`),t=new Map;for(let n of e)t.has(n.ppid)||t.set(n.ppid,[]),t.get(n.ppid).push(n);return[...t.entries()].filter(([,e])=>e.length>1).map(([e,t])=>({ppid:e,children:t})).toSorted((e,t)=>t.children.length-e.children.length)},[u]),p=g({onSettled:()=>{t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]})}}),m=D(()=>{let e=new Map;for(let t of u)e.set(t.pid,t.classification);return e},[u]),h=async(t,n)=>{if(t.classification===`root`||t.classification===`system`)return;let i=t.classification===`ghost`?`ghost`:t.addonId??`process`,a=n?`SIGKILL`:`SIGTERM`;await r({title:`Send ${a}?`,message:`Target pid ${t.pid} (${i}) on node ${e}.`,confirmLabel:`Send ${a}`,variant:`danger`})&&p.mutate({nodeId:e,pid:t.pid,force:n})},_=async(t,n)=>{try{await p.mutateAsync({nodeId:e,pid:t,force:n})}catch{}},v=async n=>{let i=m.get(n.ppid);if(i===`root`||i===`system`){await r({title:`Cannot kill protected ancestor`,message:i===`root`?`pid ${n.ppid} is the current node supervisor. Restart the node via the cluster page instead.`:`pid ${n.ppid} is a system ancestor (concurrently / vite / npm wrapper). Killing it would tear down the dev tree.`,confirmLabel:`OK`,cancelLabel:`Close`,variant:`warning`});return}await r({title:`Kill ghost parent + ${n.children.length} child(ren)?`,message:`SIGKILL parent pid ${n.ppid} and SIGTERM ${n.children.length} ghost child(ren) on node ${e}.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all([_(n.ppid,!0),...n.children.map(e=>_(e.pid,!1))]),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},y=async()=>{let n=u.filter(e=>e.classification===`ghost`);n.length!==0&&await r({title:`Kill all ${n.length} ghost process(es)?`,message:`SIGKILL ${n.length} ghost process(es) on node ${e}. This is irreversible.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all(n.map(e=>_(e.pid,!0))),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},b=u.filter(e=>e.classification===`ghost`).length,x=u.filter(e=>e.classification===`managed`).length,C=u.filter(e=>e.classification===`root`).length,w=u.filter(e=>e.classification===`system`).length;return E(`div`,{className:`space-y-4`,children:[E(`div`,{className:`flex items-start justify-between gap-4`,children:[E(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`ps`," scan + kernel `$process.list` cross-reference. Ghosts = camstack-shaped commands with no managed binding (usually orphaned to ppid=1). Refreshes every 10s."]}),E(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[j(ee,{className:`h-3 w-3`}),` Refresh`]})]}),E(`div`,{className:`grid grid-cols-4 gap-3`,children:[E(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Root`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:C})]}),E(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Managed`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:x})]}),E(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`System`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:w})]}),E(`div`,{className:`rounded-lg border p-3 ${b>0?`border-destructive/40 bg-destructive/5`:`border-border`}`,children:[E(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle flex items-center gap-1`,children:[b>0&&j(Q,{className:`h-3 w-3 text-destructive`}),` Ghosts`]}),j(`div`,{className:`text-xl font-semibold ${b>0?`text-destructive`:`text-foreground`}`,children:b})]})]}),f.length>0&&E(`div`,{className:`rounded-lg border border-amber-500/40 bg-amber-500/5 p-3`,children:[E(`div`,{className:`flex items-center gap-1 text-[11px] font-semibold text-amber-400 mb-2`,children:[j(ie,{className:`h-3 w-3`}),` Recurring ghost parents (`,f.length,`)`]}),j(`div`,{className:`space-y-1.5`,children:f.map(e=>E(`div`,{className:`text-[11px] text-foreground flex items-center justify-between gap-2`,children:[E(`div`,{className:`flex items-center gap-2`,children:[E(`span`,{className:`font-mono text-foreground-subtle`,children:[`ppid `,e.ppid]}),E(`span`,{children:[`→ `,e.children.length,` ghost(s)`]})]}),E(`button`,{type:`button`,disabled:p.isPending,onClick:()=>{v(e)},className:`inline-flex items-center gap-1 rounded border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-400 hover:bg-amber-500/20 disabled:opacity-30`,children:[j(Q,{className:`h-3 w-3`}),` Kill parent + `,e.children.length]})]},e.ppid))})]}),E(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[E(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Filter:`}),E(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${i===`all`?`bg-primary text-primary-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>a(`all`),children:[`All (`,u.length,`)`]}),E(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${i===`ghost`?`bg-destructive text-destructive-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>a(`ghost`),children:[`Ghost only (`,b,`)`]})]}),b>0&&E(`button`,{type:`button`,disabled:p.isPending,onClick:()=>{y()},className:`inline-flex items-center gap-1 rounded border border-destructive/40 bg-destructive/10 px-2 py-1 text-[11px] font-medium text-destructive hover:bg-destructive/20 disabled:opacity-30`,children:[j(Q,{className:`h-3 w-3`}),` Kill all `,b,` ghost(s)`]})]}),j(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:E(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`bg-surface`,children:E(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[j(`th`,{className:`text-left px-3 py-2`,children:`Class`}),j(`th`,{className:`text-right px-3 py-2`,children:`PID`}),j(`th`,{className:`text-right px-3 py-2`,children:`PPID`}),j(`th`,{className:`text-left px-3 py-2`,children:`Addon`}),j(`th`,{className:`text-left px-3 py-2`,children:`Command`}),j(`th`,{className:`text-right px-3 py-2`,children:`CPU%`}),j(`th`,{className:`text-right px-3 py-2`,children:`RSS`}),j(`th`,{className:`text-right px-3 py-2`,children:`Uptime`}),j(`th`,{className:`w-44`})]})}),E(`tbody`,{children:[d.length===0&&j(`tr`,{children:j(`td`,{colSpan:9,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:i===`ghost`?`No ghost processes detected.`:`Scanning…`})}),d.map(e=>E(`tr`,{className:`border-t border-border ${e.classification===`ghost`?`bg-destructive/5`:``}`,children:[j(`td`,{className:`px-3 py-2`,children:j(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`ghost`?`bg-destructive/20 text-destructive`:e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})}),j(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.pid}),E(`td`,{className:`px-3 py-2 text-right font-mono text-foreground-subtle`,children:[e.ppid,e.orphaned?` ⚠`:``]}),j(`td`,{className:`px-3 py-2 text-foreground-subtle text-[11px]`,children:e.addonId??`—`}),j(`td`,{className:`px-3 py-2 font-mono text-[10px] text-foreground-subtle break-all`,children:_e(e.command)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:e.cpuPercent.toFixed(1)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:G(e.memoryRssBytes)}),j(`td`,{className:`px-3 py-2 text-right text-foreground-subtle`,children:ge(e.uptimeSec)}),j(`td`,{className:`px-3 py-2 text-right`,children:E(`div`,{className:`inline-flex gap-1`,children:[E(`button`,{type:`button`,disabled:p.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{h(e,!1)},title:`SIGTERM`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-border text-[10px] text-foreground hover:bg-surface-hover disabled:opacity-30`,children:[j(U,{className:`h-3 w-3`}),` Term`]}),E(`button`,{type:`button`,disabled:p.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{h(e,!0)},title:`SIGKILL`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-destructive/30 text-[10px] text-destructive hover:bg-destructive/10 disabled:opacity-30`,children:[j(Q,{className:`h-3 w-3`}),` Kill`]})]})})]},e.pid))]})]})}),p.isError&&E(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,p.error instanceof Error?p.error.message:`unknown`]})]})}function ye({nodeId:e,addonIds:t}){return t.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No addons on this node`}):j(`div`,{className:`w-full py-2`,children:j(K,{nodeId:e,addonIds:t,level:`global`})})}O();function be({nodeId:e,addons:n}){let r=A(),{data:i,isLoading:a}=t({nodeId:e}),s=D(()=>{let e=new Map;for(let t of n)for(let n of t.capabilities){let r=e.get(n)??[];r.push(t.id),e.set(n,r)}return[...e.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({capName:e,providers:t}))},[n]),c=o({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return s.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No capabilities on this node`}):E(`table`,{className:`w-full text-xs`,children:[j(`thead`,{children:E(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`py-2 font-medium w-1/2`,children:`Capability`}),j(`th`,{className:`py-2 font-medium`,children:`Bound provider`})]})}),j(`tbody`,{children:s.map(({capName:t,providers:n})=>{let r=i?.[t]??n[0]??``,o=n.length===1;return E(`tr`,{className:`border-t border-border/50`,children:[j(`td`,{className:`py-2 font-medium`,children:t}),j(`td`,{className:`py-2`,children:j(`select`,{value:r,onChange:n=>c.mutate({nodeId:e,capName:t,addonId:n.target.value}),disabled:o||c.isPending||a,className:`w-full rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-60`,title:o?`Only one provider installed — choice becomes available once a second addon registers this capability`:void 0,children:n.map(e=>j(`option`,{value:e,children:e},e))})})]},t)})})]})}O();function xe(e){if(e==null)return`—`;let t=Math.floor(e/1e3),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return n>0?`${n}d ${r}h ${i}m`:r>0?`${r}h ${i}m`:`${i}m`}function Se(e){let[t,n]=T(!1),[r,i]=T(e.name),a=A(),o=d({onSuccess:()=>{a.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),s=(e.localIps??[]).filter(e=>!e.includes(`:`)),c=(e.localIps??[]).filter(e=>e.includes(`:`)),l=async()=>{if(!r.trim()||r===e.name){n(!1);return}try{await o.mutateAsync({nodeId:e.nodeId,name:r.trim()}),n(!1)}catch(e){console.error(`Rename failed:`,e)}},u=[[`Node ID`,j(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,t?E(`div`,{className:`flex items-center gap-1.5`,children:[j(`input`,{type:`text`,className:`flex-1 px-2 py-0.5 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary`,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&l(),e.key===`Escape`&&n(!1)},disabled:o.isPending,autoFocus:!0}),j(`button`,{onClick:()=>void l(),disabled:o.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:`Save`,children:j(te,{className:`h-3.5 w-3.5`})}),j(`button`,{onClick:()=>n(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:`Cancel`,children:j(ne,{className:`h-3.5 w-3.5`})})]}):E(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&j(`button`,{onClick:()=>{i(e.name),n(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:`Rename`,children:j(N,{className:`h-3 w-3`})})]})],[`Hostname`,j(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:`Hub`}):j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`Agent`})],[`Platform`,E(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,E(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,e.cpuCores,` cores)`]})],[`Memory`,j(`span`,{className:`text-xs`,children:e.memoryMB>0?`${(e.memoryMB/1024).toFixed(1)} GB`:`—`})],[`Uptime`,j(`span`,{className:`text-xs`,children:xe(e.uptime)})],[`Engines`,e.engines.length>0?j(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e))}):j(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return s.length>0&&u.push([`IPv4`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:s.map((e,t)=>j(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),c.length>0&&u.push([`IPv6`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map((e,t)=>j(`span`,{className:`font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]`,title:e,children:e},`${e}-${t}`))})]),j(`div`,{className:`py-2`,children:j(`table`,{className:`w-full text-sm`,children:j(`tbody`,{children:u.map(([e,t],n)=>E(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[j(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),j(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}O();function Ce({node:e}){let[t,n]=T(`info`),r=e.processes??[],i=e.addons.map(e=>e.id);return e.isOnline?E(`div`,{className:`border border-border rounded-xl overflow-hidden`,children:[E(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),E(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),E(`div`,{className:`ml-auto flex gap-3 text-xs text-muted-foreground`,children:[E(`span`,{className:`flex items-center gap-1`,children:[j(re,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),E(`span`,{className:`flex items-center gap-1`,children:[j(se,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),j(`div`,{className:`flex border-b border-border px-4`,children:[`info`,`addons`,`forks`,`processes`,`settings`,`capabilities`].map(i=>j(`button`,{onClick:()=>n(i),className:`px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===i?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:i===`info`?`Info`:i===`addons`?`Addons (${e.addons.length})`:i===`forks`?`Forks (${r.length})`:i===`processes`?`Processes`:i===`settings`?`Settings`:`Capabilities`},i))}),E(`div`,{className:`px-4 py-2`,children:[t===`info`&&j(Se,{nodeId:e.id,name:e.name,hostname:e.hostname,platform:e.platform,arch:e.arch,cpuModel:e.cpuModel,cpuCores:e.cpuCores,memoryMB:e.memoryMB,engines:e.engines,isHub:e.isHub,uptime:e.uptime,localIps:e.localIps}),t===`addons`&&j(ue,{nodeId:e.id,addons:e.addons,isHub:e.isHub}),t===`forks`&&j(he,{nodeId:e.id,processes:r}),t===`processes`&&j(ve,{nodeId:e.id}),t===`settings`&&j(ye,{nodeId:e.id,addonIds:i}),t===`capabilities`&&j(be,{nodeId:e.id,addons:e.addons})]})]}):E(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[E(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),E(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),j(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`})]}),E(`div`,{className:`px-4 py-3 text-xs text-muted-foreground`,children:[e.addons.length,` addon`,e.addons.length===1?``:`s`,` assigned — will resume when node reconnects`]})]})}O();function we({nodes:e,focusNodeId:t,focusNonce:n}){let r=[...e].toSorted((e,t)=>e.isHub?-1:t.isHub?1:e.isOnline&&!t.isOnline?-1:!e.isOnline&&t.isOnline?1:e.name.localeCompare(t.name)),i=C(null);return M(()=>{if(!t)return;let e=i.current?.querySelector(`#node-card-${CSS.escape(t)}`);e&&e.scrollIntoView({behavior:`smooth`,block:`start`})},[t,n]),j(`div`,{ref:i,className:`flex flex-col gap-4`,children:r.map(e=>j(`div`,{id:`node-card-${e.id}`,children:j(Ce,{node:e})},e.id))})}O();function Te(e){return e===`running`||e===`online`?`bg-success`:e===`crashed`||e===`failed`?`bg-destructive`:`bg-muted-foreground`}function Ee({runner:e,nodeId:t,expanded:n,pid:r,onToggleCaps:i}){let[a,o]=T(!1),s=b();function c(){s.mutateAsync({nodeId:t,addonId:e.addonId})}function l(){o(e=>!e)}return E(`div`,{className:`border border-border rounded-md px-2 py-1.5 text-xs space-y-1`,children:[E(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[j(`span`,{className:`shrink-0 h-1.5 w-1.5 rounded-full ${Te(e.state)}`,"aria-label":`status: ${e.state}`}),j(`span`,{className:`font-medium truncate flex-1 min-w-0`,children:e.name}),E(`span`,{className:`shrink-0 text-muted-foreground`,children:[e.cpu.toFixed(1),`%`]}),j(`span`,{className:`shrink-0 text-muted-foreground`,children:G(e.mem)}),E(`button`,{type:`button`,"aria-label":`caps: ${e.caps.length}`,onClick:()=>i(r),className:`shrink-0 inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-muted text-muted-foreground hover:bg-muted/80`,children:[j(n?V:B,{className:`h-2.5 w-2.5`,"aria-hidden":!0}),E(`span`,{children:[`caps: `,e.caps.length]})]}),j(`button`,{type:`button`,"aria-label":`Restart addon`,onClick:c,className:`shrink-0 p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted`,children:j(F,{className:`h-3 w-3`})}),j(`button`,{type:`button`,"aria-label":`Logs`,onClick:l,className:`shrink-0 p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted`,children:j(H,{className:`h-3 w-3`})})]}),n&&e.caps.length>0&&j(`ul`,{className:`pl-3 space-y-0.5`,children:e.caps.map(e=>E(`li`,{className:`text-muted-foreground`,children:[j(`span`,{className:`text-foreground`,children:e.name}),` · `,j(`span`,{children:e.addonId})]},`${e.name}\0${e.addonId}`))}),a&&j(m,{addonId:e.addonId,agentId:t,showScope:!0,onClose:()=>o(!1)})]})}O();function De(e){return e?`bg-success`:`bg-muted-foreground`}function $({data:e}){let[t,n]=T(new Set),r=w(e=>{n(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]);return M(()=>{e.expandAllNonce!==0&&(e.expandAllValue?n(new Set(e.runners.map(e=>e.pid))):n(new Set))},[e.expandAllNonce,e.expandAllValue,e.runners]),E(`div`,{className:`border border-border rounded-xl bg-background shadow-md min-w-[280px] max-w-[360px] flex flex-col${e.isOnline?``:` opacity-50`}`,children:[j(X,{type:`target`,position:q.Left}),j(X,{type:`source`,position:q.Right}),E(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[j(`span`,{className:`text-[10px] font-semibold px-1.5 py-0.5 rounded bg-muted text-muted-foreground shrink-0`,children:e.isHub?`HUB`:`AGENT`}),j(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${De(e.isOnline)}`,"aria-label":e.isOnline?`online`:`offline`}),j(`span`,{className:`font-semibold text-sm truncate flex-1 min-w-0`,children:e.identity.name}),j(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:e.identity.ip}),E(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:[e.identity.cpu,`%`]}),E(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:[e.identity.mem,`%`]}),j(`button`,{type:`button`,"aria-label":`Open node detail`,onClick:()=>e.onOpenNodeDetail(e.nodeId),className:`shrink-0 text-xs text-muted-foreground hover:text-foreground underline-offset-2 hover:underline ml-1`,children:`↗`})]}),E(`div`,{className:`flex flex-col gap-1 p-2 max-h-96 overflow-auto`,children:[e.runners.map(n=>j(Ee,{runner:n,nodeId:e.nodeId,expanded:t.has(n.pid),onToggleCaps:r,pid:n.pid},n.pid)),e.runners.length===0&&j(`span`,{className:`text-xs text-muted-foreground px-1`,children:`No processes`})]})]})}O();var Oe={nodeBox:$};function ke(e,t){let n=new Map,r=0,i=0;for(let a=0;a<e.length;a++){let o=e[a];o!==void 0&&(t[a]?(n.set(o,{x:0,y:i*340}),i++):(n.set(o,{x:480,y:r*340}),r++))}return n}function Ae(e,t){if(e===``)return!0;let n=e.toLowerCase();return t.identity.name.toLowerCase().includes(n)?!0:t.runners.some(e=>e.name.toLowerCase().includes(n)||e.addonId.toLowerCase().includes(n)||e.caps.some(e=>e.name.toLowerCase().includes(n)||e.addonId.toLowerCase().includes(n)))}function je({graph:e,onOpenNodeDetail:t}){let[n,r]=T(``),[i,a]=T(!1),[o,s]=T(0),c=w(()=>{a(!0),s(e=>e+1)},[]),l=w(()=>{a(!1),s(e=>e+1)},[]),u=w(e=>{t?.(e)},[t]),d=D(()=>ke(e.nodes.map(e=>e.nodeId),e.nodes.map(e=>e.isHub)),[e.nodes]),f=D(()=>e.nodes.map(e=>{let t=d.get(e.nodeId)??{x:0,y:0},r={...e,onOpenNodeDetail:u,expandAllValue:i,expandAllNonce:o},a=n!==``&&!Ae(n,r);return{id:e.nodeId,type:`nodeBox`,position:t,data:r,hidden:a}}),[e.nodes,d,u,n,i,o]),p=D(()=>e.edges.map(e=>({id:e.id,source:e.source,target:e.target,label:`moleculer`,style:e.online?{}:{strokeDasharray:`5,5`,opacity:.4},animated:!1})),[e.edges]);return E(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[E(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[j(`input`,{type:`search`,placeholder:`Filter by node / runner / cap…`,value:n,onChange:e=>r(e.target.value),className:`flex-1 text-xs border border-border rounded px-2 py-1 bg-background focus:outline-none focus:ring-1 focus:ring-ring`}),j(`button`,{type:`button`,onClick:c,className:`text-xs px-2 py-1 rounded border border-border hover:bg-muted`,children:`Expand all`}),j(`button`,{type:`button`,onClick:l,className:`text-xs px-2 py-1 rounded border border-border hover:bg-muted`,children:`Collapse all`})]}),j(`div`,{className:`flex-1 min-h-0 border-t border-border overflow-hidden`,children:E(J,{nodes:f,edges:p,nodeTypes:Oe,fitView:!0,proOptions:{hideAttribution:!0},children:[j(ae,{gap:20,size:1}),j(Y,{showInteractive:!1})]})})]})}function Me(e){if(e===void 0||e.length===0)return[];let t=new Set,n=[];for(let r of e)for(let e of r.capabilities){let i=`${e}\0${r.addonId}`;t.has(i)||(t.add(i),n.push({name:e,addonId:r.addonId}))}return n.toSorted((e,t)=>e.name.localeCompare(t.name))}function Ne(e){let t=e.services;return{pid:e.pid,name:e.name,addonId:t?.[0]?.addonId??``,cpu:e.cpuPercent,mem:e.memoryRss,state:e.state,caps:Me(t)}}function Pe(e){return{nodeId:e.id,isHub:e.isHub,isOnline:e.isOnline,identity:{name:e.name,ip:e.localIps?.[0]??``,cpu:e.cpuPercent,mem:e.memoryPercent,platform:e.platform,arch:e.arch},runners:e.processes.map(Ne)}}function Fe(e){let t=e.toSorted((e,t)=>{let n=+!!e.isHub;return+!!t.isHub-n}).map(Pe),n=t.find(e=>e.isHub);return n===void 0?{nodes:t,edges:[]}:{nodes:t,edges:t.filter(e=>!e.isHub).map(e=>({id:`hub:${n.nodeId}->${e.nodeId}`,source:n.nodeId,target:e.nodeId,online:e.isOnline&&n.isOnline}))}}O();function Ie({onlineNodeIds:e}){let t=A(),r=n(),{data:o,isLoading:s}=i(),c=a({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]})}}),l=D(()=>{if(!o)return[];let t=new Set(e);return t.add(`hub`),o.filter(e=>!t.has(e.nodeId))},[o,e]);if(s)return j(`section`,{className:`rounded-lg border border-border bg-surface p-6 text-xs text-muted-foreground animate-pulse`,children:`Loading persisted agent settings…`});let u=async e=>{await r({title:`Remove offline agent?`,message:`Drop the persisted orchestrator settings for "${e}". This won't affect a node that comes back online — it just clears stale addonDefaults so it stops cluttering the cluster view.`,confirmLabel:`Remove`,cancelLabel:`Keep`,variant:`danger`})&&c.mutate({agentNodeId:e})};return l.length===0?j(`section`,{className:`rounded-lg border border-border bg-surface p-6`,children:E(`div`,{className:`flex flex-col items-center gap-2 text-center text-muted-foreground`,children:[j(Z,{className:`h-6 w-6 opacity-40`}),j(`p`,{className:`text-xs`,children:`No stale agent entries.`}),j(`p`,{className:`text-[11px] opacity-60`,children:`Every persisted nodeId matches a node currently online in the cluster.`})]})}):E(`section`,{className:`rounded-lg border border-border bg-surface`,children:[E(`header`,{className:`flex items-center gap-2 px-4 py-3 border-b border-border`,children:[j(Z,{className:`h-4 w-4 text-muted-foreground`}),j(`h2`,{className:`text-sm font-semibold`,children:`Offline agents`}),E(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,children:[l.length,` stale `,l.length===1?`entry`:`entries`]})]}),j(`p`,{className:`px-4 pt-3 text-[11px] text-muted-foreground`,children:`Persisted orchestrator settings for nodes not currently in the live topology. Remove entries you don't expect to come back — leftover from data-dir resets, env-driven nodeId changes, or decommissioned hosts.`}),j(`ul`,{className:`divide-y divide-border`,children:l.map(e=>{let t=Object.keys(e.settings.addonDefaults??{}).length,n=Object.values(e.settings.addonDefaults??{}).filter(e=>e?.enabled).length;return E(`li`,{className:`flex items-center gap-3 px-4 py-2 text-xs`,children:[j(`span`,{className:`font-mono text-foreground`,children:e.nodeId}),E(`span`,{className:`text-muted-foreground`,children:[t,` addons configured`,t>0&&E(k,{children:[` · `,n,` enabled`]})]}),E(`button`,{type:`button`,onClick:()=>{u(e.nodeId)},disabled:c.isPending,className:`ml-auto flex items-center gap-1 px-2 py-1 rounded text-destructive hover:bg-destructive/10 disabled:opacity-50`,children:[j(U,{className:`h-3 w-3`}),`Remove`]})]},e.nodeId)})})]})}O();function Le(e){let[t,n]=T(()=>typeof window<`u`?window.matchMedia(e).matches:!1);return M(()=>{let t=window.matchMedia(e),r=e=>n(e.matches);return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}function Re(){let{data:e,isLoading:t}=p(void 0,{staleTime:1/0}),[n,i]=T(null);return r(`cluster.topology-snapshot`,e=>{let t=e.data?.nodes;Array.isArray(t)&&i(t)}),{nodes:D(()=>n??e??[],[n,e]),isLoading:t&&!n}}function ze(){let[e,t]=T(`table`),[n,r]=T(void 0),[a,o]=T(0),s=Le(`(max-width: 767px)`),c=s&&e===`graph`?`table`:e,{nodes:l,isLoading:u}=Re(),d=D(()=>Fe(l),[l]),f=l.filter(e=>e.isOnline).length,p=l.filter(e=>!e.isOnline).length,m=D(()=>l.map(e=>e.id??``).filter(Boolean),[l]),{data:h}=i(),g=D(()=>{if(!h)return 0;let e=new Set(m);return e.add(`hub`),h.filter(t=>!e.has(t.nodeId)).length},[h,m]),_=w(e=>{t(`table`),r(e),o(e=>e+1)},[]),v=(n,r,i,a)=>E(`button`,{onClick:()=>t(n),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${e===n?`bg-primary text-primary-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[j(i,{className:`h-3.5 w-3.5`}),r,a!==void 0&&a>0&&j(`span`,{className:`ml-1 inline-flex h-4 min-w-[1rem] items-center justify-center rounded-full px-1 text-[10px] font-semibold ${e===n?`bg-primary-foreground/20 text-primary-foreground`:`bg-destructive/15 text-destructive`}`,children:a})]});return E(`div`,{className:`flex flex-col h-full gap-4 p-4`,children:[E(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[E(`div`,{className:`flex items-center gap-2`,children:[f>0&&E(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-success/10 text-success`,children:[f,` online`]}),p>0&&E(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:[p,` offline`]})]}),E(`div`,{className:`flex gap-0.5 p-1 rounded-lg bg-muted`,children:[v(`table`,`Table`,ce),!s&&v(`graph`,`Graph`,oe),v(`offline-agents`,`Offline agents`,Z,g)]})]}),u?j(`div`,{className:`flex items-center justify-center flex-1 text-muted-foreground`,children:`Loading cluster topology...`}):c===`graph`?j(je,{graph:d,onOpenNodeDetail:_}):c===`table`?j(`div`,{className:`flex-1 overflow-auto`,children:j(we,{nodes:l,focusNodeId:n,focusNonce:a})}):j(`div`,{className:`flex-1 overflow-auto`,children:j(Ie,{onlineNodeIds:m})})]})}export{ze as ClusterPage};
1
+ import{$i as e,Lr as t,Pi as n,Vi as r,Vr as i,Wr as a,Zr as o,_r as s,ar as c,dr as l,ea as u,fr as d,g as f,gr as p,h as m,hr as h,ir as g,m as _,mr as v,na as y,pr as b,ta as x,zi as S}from"./src-OU6ujZuo.js";import{G as C,I as w,K as T,S as E,W as D,Z as O,b as k,o as A,x as j,z as M}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{t as N}from"./pencil-DK4zkTC6.js";import{t as P}from"./radio-Dy8HhsgR.js";import{t as ee}from"./refresh-cw-Da6Dj3o0.js";import{t as F}from"./rotate-cw-BvT3aWsW.js";import{t as I}from"./server-BXljhg3E.js";import{t as L}from"./upload-B6zuUrvA.js";import{B as R,F as te,L as z,M as B,P as V,i as ne,k as re,o as ie,p as H,s as U,x as W}from"./index-BW7XX5wA.js";import{t as G}from"./format-size-CO9d3C3-.js";import{t as K}from"./NodeAddonsSettingsPanel-CswS1clZ.js";import{a as q,i as J,n as Y,r as X,t as ae}from"./esm-Dc9m00q0.js";var Z=R(`ghost`,[[`path`,{d:`M9 10h.01`,key:`qbtxuw`}],[`path`,{d:`M15 10h.01`,key:`1qmjsl`}],[`path`,{d:`M12 2a8 8 0 0 0-8 8v12l3-3 2.5 2.5L12 19l2.5 2.5L17 19l3 3V10a8 8 0 0 0-8-8z`,key:`uwwb07`}]]),oe=R(`git-fork`,[[`circle`,{cx:`12`,cy:`18`,r:`3`,key:`1mpf1b`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`path`,{d:`M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9`,key:`1uq4wg`}],[`path`,{d:`M12 12v3`,key:`158kv8`}]]),se=R(`memory-stick`,[[`path`,{d:`M6 19v-3`,key:`1nvgqn`}],[`path`,{d:`M10 19v-3`,key:`iu8nkm`}],[`path`,{d:`M14 19v-3`,key:`kcehxu`}],[`path`,{d:`M18 19v-3`,key:`1vh91z`}],[`path`,{d:`M8 11V9`,key:`63erz4`}],[`path`,{d:`M16 11V9`,key:`fru6f3`}],[`path`,{d:`M12 11V9`,key:`ha00sb`}],[`path`,{d:`M2 15h20`,key:`16ne18`}],[`path`,{d:`M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z`,key:`lhddv3`}]]),Q=R(`skull`,[[`path`,{d:`m12.5 17-.5-1-.5 1h1z`,key:`3me087`}],[`path`,{d:`M15 22a1 1 0 0 0 1-1v-1a2 2 0 0 0 1.56-3.25 8 8 0 1 0-11.12 0A2 2 0 0 0 8 20v1a1 1 0 0 0 1 1z`,key:`1o5pge`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}]]),ce=R(`table-2`,[[`path`,{d:`M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18`,key:`gugj83`}]]);O();function le(e){let t=new FormData;return t.append(`file`,e.file,e.file.name),t.append(`nodeId`,e.nodeId),e.addonId&&t.append(`addonId`,e.addonId),new Promise((n,r)=>{let i=new XMLHttpRequest;i.open(`POST`,`/api/addons/upload`),e.token&&i.setRequestHeader(`Authorization`,`Bearer ${e.token}`),i.upload.addEventListener(`progress`,t=>{t.lengthComputable&&e.onProgress(Math.round(t.loaded/t.total*100))}),i.addEventListener(`load`,()=>{let e;try{e=JSON.parse(i.responseText)}catch{r(Error(`HTTP ${i.status}`));return}i.status>=200&&i.status<300?n(e):r(Error(e.error??`HTTP ${i.status}`))}),i.addEventListener(`error`,()=>r(Error(`Network error during upload`))),i.addEventListener(`abort`,()=>r(Error(`Upload aborted`))),i.send(t)})}function ue({nodeId:e,addons:t,isHub:r}){let i=A(),a=n(),[o,c]=T(null),[u,d]=T(null),[f,p]=T(!1),[m,h]=T(null),[g,_]=T(0),v=C(null),y=b(),x=s(),S=l({nodeId:e}),w=S.data??[],D=new Map(t.map(e=>[e.id,e.capabilities])),O=w.length>0?w.map(e=>({id:e.id,status:e.status,capabilities:D.get(e.id)??[],version:e.version,packageName:e.packageName})):t.map(e=>({id:e.id,status:e.status,capabilities:e.capabilities,version:void 0,packageName:void 0})),k=()=>{i.invalidateQueries({queryKey:[[`nodes`,`topology`]]}),S.refetch()},M=async t=>{c(t);try{await y.mutateAsync({nodeId:e,addonId:t}),k()}catch(e){console.error(`Failed to restart addon:`,e)}finally{c(null)}},N=async t=>{if(await a({title:`Uninstall addon`,message:`Remove "${t}" from ${e}? The addon directory will be deleted on disk.`,confirmLabel:`Uninstall`,variant:`danger`})){d(t);try{await x.mutateAsync({nodeId:e,addonId:t}),k()}catch(e){console.error(`Failed to uninstall addon:`,e)}finally{d(null)}}},P=E(`div`,{className:`flex items-center gap-2 mb-2`,children:[j(`input`,{ref:v,type:`file`,accept:`.tgz,.tar.gz`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(n){t.target.value=``,h(null),p(!0),_(0);try{await le({file:n,nodeId:e,token:localStorage.getItem(`camstack_admin_token`),onProgress:_}),k()}catch(e){h(e instanceof Error?e.message:String(e))}finally{p(!1),_(0)}}}}),E(`button`,{onClick:()=>v.current?.click(),disabled:f,className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[f?j(W,{className:`h-3 w-3 animate-spin`}):j(L,{className:`h-3 w-3`}),f?`Uploading… ${g}%`:`Upload addon (.tgz)`]}),f&&j(`div`,{className:`flex-1 h-1 rounded-full bg-muted overflow-hidden max-w-[140px]`,children:j(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${g}%`}})}),m&&j(`span`,{className:`text-[10px] text-destructive`,children:m})]});return O.length===0?E(`div`,{children:[P,j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:S.isLoading?`Loading addons…`:`No addons on this node`})]}):E(`div`,{children:[P,E(`table`,{className:`w-full text-xs`,children:[j(`thead`,{children:E(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`py-2 font-medium`,children:`Addon`}),j(`th`,{className:`py-2 font-medium`,children:`Version`}),j(`th`,{className:`py-2 font-medium`,children:`Capabilities`}),j(`th`,{className:`py-2 font-medium`,children:`Status`}),j(`th`,{className:`py-2 font-medium w-16`})]})}),j(`tbody`,{children:O.map(e=>E(`tr`,{className:`border-t border-border/50`,children:[E(`td`,{className:`py-2 font-medium`,children:[j(`div`,{children:e.id}),e.packageName&&j(`div`,{className:`text-[9px] text-muted-foreground`,children:e.packageName})]}),j(`td`,{className:`py-2 text-muted-foreground`,children:e.version??`—`}),j(`td`,{className:`py-2`,children:j(`div`,{className:`flex flex-wrap gap-1`,children:e.capabilities.length>0?e.capabilities.map(e=>j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400`,children:e},e)):j(`span`,{className:`text-muted-foreground`,children:`—`})})}),j(`td`,{className:`py-2`,children:j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e.status===`running`?`bg-success/10 text-success`:e.status===`error`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e.status})}),j(`td`,{className:`py-2`,children:E(`div`,{className:`flex items-center gap-1 justify-end`,children:[j(`button`,{onClick:()=>M(e.id),disabled:o===e.id||u===e.id,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.id}`,children:j(F,{className:`h-3 w-3 ${o===e.id?`animate-spin`:``}`})}),j(`button`,{onClick:()=>N(e.id),disabled:o===e.id||u===e.id,className:`p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50`,title:`Uninstall ${e.id}`,children:u===e.id?j(W,{className:`h-3 w-3 animate-spin`}):j(U,{className:`h-3 w-3`})})]})})]},e.id))})]})]})}O();function de(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function fe({state:e}){return j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var pe=[`trace`,`debug`,`info`,`warn`,`error`];function me({proc:t,nodeId:n,defaultExpanded:r,activePanel:i,onTogglePanel:a}){let o=t.services??[],s=o.length===1,[c,l]=T(s||r),[d,p]=T(null),[m,g]=T(`info`),S=t.name.includes(`(core)`),C=b(),w=v(),D=h(),O=async e=>{p(e);try{await C.mutateAsync({nodeId:n,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{p(null)}},k=async()=>{p(t.name);try{await w.mutateAsync({nodeId:n,processName:t.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{p(null)}},A=async e=>{let r=`${n}/${t.name}`;try{await D.mutateAsync({nodeId:r,level:e}),g(e)}catch(e){console.error(`Failed to set log level:`,e)}};return E(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[E(`div`,{role:s?void 0:`button`,tabIndex:s?void 0:0,onClick:s?void 0:()=>l(!c),onKeyDown:s?void 0:e=>{(e.key===`Enter`||e.key===` `)&&l(!c)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${s?``:`hover:bg-muted/40 cursor-pointer`}`,children:[s?j(`span`,{className:`h-3 w-3 shrink-0`}):j(c?V:B,{className:`h-3 w-3 text-muted-foreground shrink-0`}),S?j(I,{className:`h-3.5 w-3.5 text-primary shrink-0`}):j(z,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),j(`span`,{className:`text-xs font-semibold flex-1`,children:t.name}),E(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,t.pid]}),j(fe,{state:t.state}),E(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[t.cpuPercent,`% CPU`]}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:G(t.memoryRss)}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:de(t.uptimeSeconds)}),!S&&E(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[E(e,{children:[j(y,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:m}),j(u,{align:`end`,className:`min-w-[70px] py-0.5`,children:pe.map(e=>j(x,{onClick:()=>A(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===m?`text-primary font-semibold`:``}`,children:e},e))})]}),j(`button`,{onClick:k,disabled:d===t.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:j(F,{className:`h-3 w-3 ${d===t.name?`animate-spin`:``}`})})]})]}),c&&o.length>0&&j(`div`,{className:`divide-y divide-border/30`,children:o.map(e=>E(`div`,{children:[E(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[j(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),j(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&E(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&E(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),E(`div`,{className:`flex items-center gap-1 shrink-0`,children:[j(`button`,{onClick:()=>a(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:j(H,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>a(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:j(P,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>O(e.addonId),disabled:d===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:j(F,{className:`h-3 w-3 ${d===e.addonId?`animate-spin`:``}`})})]})]}),i?.addonId===e.addonId&&i.type===`logs`&&j(`div`,{className:`border-t border-border/40 bg-muted/5`,children:j(f,{addonId:e.addonId,agentId:n,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>a(e.addonId,`logs`)})}),i?.addonId===e.addonId&&i.type===`events`&&j(`div`,{className:`border-t border-border/40 bg-muted/5`,children:j(_,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>a(e.addonId,`events`)})})]},e.addonId))}),c&&o.length===0&&j(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function he({nodeId:e,processes:t}){let[n,r]=T(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):j(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>j(me,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}O();function ge(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function _e(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function ve({nodeId:e}){let t=A(),r=n(),[i,a]=T(`all`),o=S(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:s}=c({nodeId:e}),l=o?.processes??s,u=D(()=>l?[...l]:[],[l]),d=D(()=>i===`ghost`?u.filter(e=>e.classification===`ghost`):u,[u,i]),f=D(()=>{let e=u.filter(e=>e.classification===`ghost`),t=new Map;for(let n of e)t.has(n.ppid)||t.set(n.ppid,[]),t.get(n.ppid).push(n);return[...t.entries()].filter(([,e])=>e.length>1).map(([e,t])=>({ppid:e,children:t})).toSorted((e,t)=>t.children.length-e.children.length)},[u]),p=g({onSettled:()=>{t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]})}}),m=D(()=>{let e=new Map;for(let t of u)e.set(t.pid,t.classification);return e},[u]),h=async(t,n)=>{if(t.classification===`root`||t.classification===`system`)return;let i=t.classification===`ghost`?`ghost`:t.addonId??`process`,a=n?`SIGKILL`:`SIGTERM`;await r({title:`Send ${a}?`,message:`Target pid ${t.pid} (${i}) on node ${e}.`,confirmLabel:`Send ${a}`,variant:`danger`})&&p.mutate({nodeId:e,pid:t.pid,force:n})},_=async(t,n)=>{try{await p.mutateAsync({nodeId:e,pid:t,force:n})}catch{}},v=async n=>{let i=m.get(n.ppid);if(i===`root`||i===`system`){await r({title:`Cannot kill protected ancestor`,message:i===`root`?`pid ${n.ppid} is the current node supervisor. Restart the node via the cluster page instead.`:`pid ${n.ppid} is a system ancestor (concurrently / vite / npm wrapper). Killing it would tear down the dev tree.`,confirmLabel:`OK`,cancelLabel:`Close`,variant:`warning`});return}await r({title:`Kill ghost parent + ${n.children.length} child(ren)?`,message:`SIGKILL parent pid ${n.ppid} and SIGTERM ${n.children.length} ghost child(ren) on node ${e}.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all([_(n.ppid,!0),...n.children.map(e=>_(e.pid,!1))]),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},y=async()=>{let n=u.filter(e=>e.classification===`ghost`);n.length!==0&&await r({title:`Kill all ${n.length} ghost process(es)?`,message:`SIGKILL ${n.length} ghost process(es) on node ${e}. This is irreversible.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all(n.map(e=>_(e.pid,!0))),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},b=u.filter(e=>e.classification===`ghost`).length,x=u.filter(e=>e.classification===`managed`).length,C=u.filter(e=>e.classification===`root`).length,w=u.filter(e=>e.classification===`system`).length;return E(`div`,{className:`space-y-4`,children:[E(`div`,{className:`flex items-start justify-between gap-4`,children:[E(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`ps`," scan + kernel `$process.list` cross-reference. Ghosts = camstack-shaped commands with no managed binding (usually orphaned to ppid=1). Refreshes every 10s."]}),E(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[j(ee,{className:`h-3 w-3`}),` Refresh`]})]}),E(`div`,{className:`grid grid-cols-4 gap-3`,children:[E(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Root`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:C})]}),E(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Managed`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:x})]}),E(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`System`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:w})]}),E(`div`,{className:`rounded-lg border p-3 ${b>0?`border-destructive/40 bg-destructive/5`:`border-border`}`,children:[E(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle flex items-center gap-1`,children:[b>0&&j(Q,{className:`h-3 w-3 text-destructive`}),` Ghosts`]}),j(`div`,{className:`text-xl font-semibold ${b>0?`text-destructive`:`text-foreground`}`,children:b})]})]}),f.length>0&&E(`div`,{className:`rounded-lg border border-amber-500/40 bg-amber-500/5 p-3`,children:[E(`div`,{className:`flex items-center gap-1 text-[11px] font-semibold text-amber-400 mb-2`,children:[j(ie,{className:`h-3 w-3`}),` Recurring ghost parents (`,f.length,`)`]}),j(`div`,{className:`space-y-1.5`,children:f.map(e=>E(`div`,{className:`text-[11px] text-foreground flex items-center justify-between gap-2`,children:[E(`div`,{className:`flex items-center gap-2`,children:[E(`span`,{className:`font-mono text-foreground-subtle`,children:[`ppid `,e.ppid]}),E(`span`,{children:[`→ `,e.children.length,` ghost(s)`]})]}),E(`button`,{type:`button`,disabled:p.isPending,onClick:()=>{v(e)},className:`inline-flex items-center gap-1 rounded border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-400 hover:bg-amber-500/20 disabled:opacity-30`,children:[j(Q,{className:`h-3 w-3`}),` Kill parent + `,e.children.length]})]},e.ppid))})]}),E(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[E(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Filter:`}),E(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${i===`all`?`bg-primary text-primary-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>a(`all`),children:[`All (`,u.length,`)`]}),E(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${i===`ghost`?`bg-destructive text-destructive-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>a(`ghost`),children:[`Ghost only (`,b,`)`]})]}),b>0&&E(`button`,{type:`button`,disabled:p.isPending,onClick:()=>{y()},className:`inline-flex items-center gap-1 rounded border border-destructive/40 bg-destructive/10 px-2 py-1 text-[11px] font-medium text-destructive hover:bg-destructive/20 disabled:opacity-30`,children:[j(Q,{className:`h-3 w-3`}),` Kill all `,b,` ghost(s)`]})]}),j(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:E(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`bg-surface`,children:E(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[j(`th`,{className:`text-left px-3 py-2`,children:`Class`}),j(`th`,{className:`text-right px-3 py-2`,children:`PID`}),j(`th`,{className:`text-right px-3 py-2`,children:`PPID`}),j(`th`,{className:`text-left px-3 py-2`,children:`Addon`}),j(`th`,{className:`text-left px-3 py-2`,children:`Command`}),j(`th`,{className:`text-right px-3 py-2`,children:`CPU%`}),j(`th`,{className:`text-right px-3 py-2`,children:`RSS`}),j(`th`,{className:`text-right px-3 py-2`,children:`Uptime`}),j(`th`,{className:`w-44`})]})}),E(`tbody`,{children:[d.length===0&&j(`tr`,{children:j(`td`,{colSpan:9,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:i===`ghost`?`No ghost processes detected.`:`Scanning…`})}),d.map(e=>E(`tr`,{className:`border-t border-border ${e.classification===`ghost`?`bg-destructive/5`:``}`,children:[j(`td`,{className:`px-3 py-2`,children:j(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`ghost`?`bg-destructive/20 text-destructive`:e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})}),j(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.pid}),E(`td`,{className:`px-3 py-2 text-right font-mono text-foreground-subtle`,children:[e.ppid,e.orphaned?` ⚠`:``]}),j(`td`,{className:`px-3 py-2 text-foreground-subtle text-[11px]`,children:e.addonId??`—`}),j(`td`,{className:`px-3 py-2 font-mono text-[10px] text-foreground-subtle break-all`,children:_e(e.command)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:e.cpuPercent.toFixed(1)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:G(e.memoryRssBytes)}),j(`td`,{className:`px-3 py-2 text-right text-foreground-subtle`,children:ge(e.uptimeSec)}),j(`td`,{className:`px-3 py-2 text-right`,children:E(`div`,{className:`inline-flex gap-1`,children:[E(`button`,{type:`button`,disabled:p.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{h(e,!1)},title:`SIGTERM`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-border text-[10px] text-foreground hover:bg-surface-hover disabled:opacity-30`,children:[j(U,{className:`h-3 w-3`}),` Term`]}),E(`button`,{type:`button`,disabled:p.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{h(e,!0)},title:`SIGKILL`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-destructive/30 text-[10px] text-destructive hover:bg-destructive/10 disabled:opacity-30`,children:[j(Q,{className:`h-3 w-3`}),` Kill`]})]})})]},e.pid))]})]})}),p.isError&&E(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,p.error instanceof Error?p.error.message:`unknown`]})]})}function ye({nodeId:e,addonIds:t}){return t.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No addons on this node`}):j(`div`,{className:`w-full py-2`,children:j(K,{nodeId:e,addonIds:t,level:`global`})})}O();function be({nodeId:e,addons:n}){let r=A(),{data:i,isLoading:a}=t({nodeId:e}),s=D(()=>{let e=new Map;for(let t of n)for(let n of t.capabilities){let r=e.get(n)??[];r.push(t.id),e.set(n,r)}return[...e.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({capName:e,providers:t}))},[n]),c=o({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return s.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No capabilities on this node`}):E(`table`,{className:`w-full text-xs`,children:[j(`thead`,{children:E(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`py-2 font-medium w-1/2`,children:`Capability`}),j(`th`,{className:`py-2 font-medium`,children:`Bound provider`})]})}),j(`tbody`,{children:s.map(({capName:t,providers:n})=>{let r=i?.[t]??n[0]??``,o=n.length===1;return E(`tr`,{className:`border-t border-border/50`,children:[j(`td`,{className:`py-2 font-medium`,children:t}),j(`td`,{className:`py-2`,children:j(`select`,{value:r,onChange:n=>c.mutate({nodeId:e,capName:t,addonId:n.target.value}),disabled:o||c.isPending||a,className:`w-full rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-60`,title:o?`Only one provider installed — choice becomes available once a second addon registers this capability`:void 0,children:n.map(e=>j(`option`,{value:e,children:e},e))})})]},t)})})]})}O();function xe(e){if(e==null)return`—`;let t=Math.floor(e/1e3),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return n>0?`${n}d ${r}h ${i}m`:r>0?`${r}h ${i}m`:`${i}m`}function Se(e){let[t,n]=T(!1),[r,i]=T(e.name),a=A(),o=d({onSuccess:()=>{a.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),s=(e.localIps??[]).filter(e=>!e.includes(`:`)),c=(e.localIps??[]).filter(e=>e.includes(`:`)),l=async()=>{if(!r.trim()||r===e.name){n(!1);return}try{await o.mutateAsync({nodeId:e.nodeId,name:r.trim()}),n(!1)}catch(e){console.error(`Rename failed:`,e)}},u=[[`Node ID`,j(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,t?E(`div`,{className:`flex items-center gap-1.5`,children:[j(`input`,{type:`text`,className:`flex-1 px-2 py-0.5 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary`,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&l(),e.key===`Escape`&&n(!1)},disabled:o.isPending,autoFocus:!0}),j(`button`,{onClick:()=>void l(),disabled:o.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:`Save`,children:j(te,{className:`h-3.5 w-3.5`})}),j(`button`,{onClick:()=>n(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:`Cancel`,children:j(ne,{className:`h-3.5 w-3.5`})})]}):E(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&j(`button`,{onClick:()=>{i(e.name),n(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:`Rename`,children:j(N,{className:`h-3 w-3`})})]})],[`Hostname`,j(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:`Hub`}):j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`Agent`})],[`Platform`,E(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,E(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,e.cpuCores,` cores)`]})],[`Memory`,j(`span`,{className:`text-xs`,children:e.memoryMB>0?`${(e.memoryMB/1024).toFixed(1)} GB`:`—`})],[`Uptime`,j(`span`,{className:`text-xs`,children:xe(e.uptime)})],[`Engines`,e.engines.length>0?j(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e))}):j(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return s.length>0&&u.push([`IPv4`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:s.map((e,t)=>j(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),c.length>0&&u.push([`IPv6`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map((e,t)=>j(`span`,{className:`font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]`,title:e,children:e},`${e}-${t}`))})]),j(`div`,{className:`py-2`,children:j(`table`,{className:`w-full text-sm`,children:j(`tbody`,{children:u.map(([e,t],n)=>E(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[j(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),j(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}O();function Ce({node:e}){let[t,n]=T(`info`),r=e.processes??[],i=e.addons.map(e=>e.id);return e.isOnline?E(`div`,{className:`border border-border rounded-xl overflow-hidden`,children:[E(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),E(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),E(`div`,{className:`ml-auto flex gap-3 text-xs text-muted-foreground`,children:[E(`span`,{className:`flex items-center gap-1`,children:[j(re,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),E(`span`,{className:`flex items-center gap-1`,children:[j(se,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),j(`div`,{className:`flex border-b border-border px-4`,children:[`info`,`addons`,`forks`,`processes`,`settings`,`capabilities`].map(i=>j(`button`,{onClick:()=>n(i),className:`px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===i?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:i===`info`?`Info`:i===`addons`?`Addons (${e.addons.length})`:i===`forks`?`Forks (${r.length})`:i===`processes`?`Processes`:i===`settings`?`Settings`:`Capabilities`},i))}),E(`div`,{className:`px-4 py-2`,children:[t===`info`&&j(Se,{nodeId:e.id,name:e.name,hostname:e.hostname,platform:e.platform,arch:e.arch,cpuModel:e.cpuModel,cpuCores:e.cpuCores,memoryMB:e.memoryMB,engines:e.engines,isHub:e.isHub,uptime:e.uptime,localIps:e.localIps}),t===`addons`&&j(ue,{nodeId:e.id,addons:e.addons,isHub:e.isHub}),t===`forks`&&j(he,{nodeId:e.id,processes:r}),t===`processes`&&j(ve,{nodeId:e.id}),t===`settings`&&j(ye,{nodeId:e.id,addonIds:i}),t===`capabilities`&&j(be,{nodeId:e.id,addons:e.addons})]})]}):E(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[E(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),E(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),j(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`})]}),E(`div`,{className:`px-4 py-3 text-xs text-muted-foreground`,children:[e.addons.length,` addon`,e.addons.length===1?``:`s`,` assigned — will resume when node reconnects`]})]})}O();function we({nodes:e,focusNodeId:t,focusNonce:n}){let r=[...e].toSorted((e,t)=>e.isHub?-1:t.isHub?1:e.isOnline&&!t.isOnline?-1:!e.isOnline&&t.isOnline?1:e.name.localeCompare(t.name)),i=C(null);return M(()=>{if(!t)return;let e=i.current?.querySelector(`#node-card-${CSS.escape(t)}`);e&&e.scrollIntoView({behavior:`smooth`,block:`start`})},[t,n]),j(`div`,{ref:i,className:`flex flex-col gap-4`,children:r.map(e=>j(`div`,{id:`node-card-${e.id}`,children:j(Ce,{node:e})},e.id))})}O();function Te(e){return e===`running`||e===`online`?`bg-success`:e===`crashed`||e===`failed`?`bg-destructive`:`bg-muted-foreground`}function Ee({runner:e,nodeId:t,expanded:n,pid:r,onToggleCaps:i}){let[a,o]=T(!1),s=b();function c(){s.mutateAsync({nodeId:t,addonId:e.addonId})}function l(){o(e=>!e)}return E(`div`,{className:`border border-border rounded-md px-2 py-1.5 text-xs space-y-1`,children:[E(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[j(`span`,{className:`shrink-0 h-1.5 w-1.5 rounded-full ${Te(e.state)}`,"aria-label":`status: ${e.state}`}),j(`span`,{className:`font-medium truncate flex-1 min-w-0`,children:e.name}),E(`span`,{className:`shrink-0 text-muted-foreground`,children:[e.cpu.toFixed(1),`%`]}),j(`span`,{className:`shrink-0 text-muted-foreground`,children:G(e.mem)}),E(`button`,{type:`button`,"aria-label":`caps: ${e.caps.length}`,onClick:()=>i(r),className:`shrink-0 inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-muted text-muted-foreground hover:bg-muted/80`,children:[j(n?V:B,{className:`h-2.5 w-2.5`,"aria-hidden":!0}),E(`span`,{children:[`caps: `,e.caps.length]})]}),j(`button`,{type:`button`,"aria-label":`Restart addon`,onClick:c,className:`shrink-0 p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted`,children:j(F,{className:`h-3 w-3`})}),j(`button`,{type:`button`,"aria-label":`Logs`,onClick:l,className:`shrink-0 p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted`,children:j(H,{className:`h-3 w-3`})})]}),n&&e.caps.length>0&&j(`ul`,{className:`pl-3 space-y-0.5`,children:e.caps.map(e=>E(`li`,{className:`text-muted-foreground`,children:[j(`span`,{className:`text-foreground`,children:e.name}),` · `,j(`span`,{children:e.addonId})]},`${e.name}\0${e.addonId}`))}),a&&j(m,{addonId:e.addonId,agentId:t,showScope:!0,onClose:()=>o(!1)})]})}O();function De(e){return e?`bg-success`:`bg-muted-foreground`}function $({data:e}){let[t,n]=T(new Set),r=w(e=>{n(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]);return M(()=>{e.expandAllNonce!==0&&(e.expandAllValue?n(new Set(e.runners.map(e=>e.pid))):n(new Set))},[e.expandAllNonce,e.expandAllValue,e.runners]),E(`div`,{className:`border border-border rounded-xl bg-background shadow-md min-w-[280px] max-w-[360px] flex flex-col${e.isOnline?``:` opacity-50`}`,children:[j(X,{type:`target`,position:q.Left}),j(X,{type:`source`,position:q.Right}),E(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[j(`span`,{className:`text-[10px] font-semibold px-1.5 py-0.5 rounded bg-muted text-muted-foreground shrink-0`,children:e.isHub?`HUB`:`AGENT`}),j(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${De(e.isOnline)}`,"aria-label":e.isOnline?`online`:`offline`}),j(`span`,{className:`font-semibold text-sm truncate flex-1 min-w-0`,children:e.identity.name}),j(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:e.identity.ip}),E(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:[e.identity.cpu,`%`]}),E(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:[e.identity.mem,`%`]}),j(`button`,{type:`button`,"aria-label":`Open node detail`,onClick:()=>e.onOpenNodeDetail(e.nodeId),className:`shrink-0 text-xs text-muted-foreground hover:text-foreground underline-offset-2 hover:underline ml-1`,children:`↗`})]}),E(`div`,{className:`flex flex-col gap-1 p-2 max-h-96 overflow-auto`,children:[e.runners.map(n=>j(Ee,{runner:n,nodeId:e.nodeId,expanded:t.has(n.pid),onToggleCaps:r,pid:n.pid},n.pid)),e.runners.length===0&&j(`span`,{className:`text-xs text-muted-foreground px-1`,children:`No processes`})]})]})}O();var Oe={nodeBox:$};function ke(e,t){let n=new Map,r=0,i=0;for(let a=0;a<e.length;a++){let o=e[a];o!==void 0&&(t[a]?(n.set(o,{x:0,y:i*340}),i++):(n.set(o,{x:480,y:r*340}),r++))}return n}function Ae(e,t){if(e===``)return!0;let n=e.toLowerCase();return t.identity.name.toLowerCase().includes(n)?!0:t.runners.some(e=>e.name.toLowerCase().includes(n)||e.addonId.toLowerCase().includes(n)||e.caps.some(e=>e.name.toLowerCase().includes(n)||e.addonId.toLowerCase().includes(n)))}function je({graph:e,onOpenNodeDetail:t}){let[n,r]=T(``),[i,a]=T(!1),[o,s]=T(0),c=w(()=>{a(!0),s(e=>e+1)},[]),l=w(()=>{a(!1),s(e=>e+1)},[]),u=w(e=>{t?.(e)},[t]),d=D(()=>ke(e.nodes.map(e=>e.nodeId),e.nodes.map(e=>e.isHub)),[e.nodes]),f=D(()=>e.nodes.map(e=>{let t=d.get(e.nodeId)??{x:0,y:0},r={...e,onOpenNodeDetail:u,expandAllValue:i,expandAllNonce:o},a=n!==``&&!Ae(n,r);return{id:e.nodeId,type:`nodeBox`,position:t,data:r,hidden:a}}),[e.nodes,d,u,n,i,o]),p=D(()=>e.edges.map(e=>({id:e.id,source:e.source,target:e.target,label:`moleculer`,style:e.online?{}:{strokeDasharray:`5,5`,opacity:.4},animated:!1})),[e.edges]);return E(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[E(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[j(`input`,{type:`search`,placeholder:`Filter by node / runner / cap…`,value:n,onChange:e=>r(e.target.value),className:`flex-1 text-xs border border-border rounded px-2 py-1 bg-background focus:outline-none focus:ring-1 focus:ring-ring`}),j(`button`,{type:`button`,onClick:c,className:`text-xs px-2 py-1 rounded border border-border hover:bg-muted`,children:`Expand all`}),j(`button`,{type:`button`,onClick:l,className:`text-xs px-2 py-1 rounded border border-border hover:bg-muted`,children:`Collapse all`})]}),j(`div`,{className:`flex-1 min-h-0 border-t border-border overflow-hidden`,children:E(J,{nodes:f,edges:p,nodeTypes:Oe,fitView:!0,proOptions:{hideAttribution:!0},children:[j(ae,{gap:20,size:1}),j(Y,{showInteractive:!1})]})})]})}function Me(e){if(e===void 0||e.length===0)return[];let t=new Set,n=[];for(let r of e)for(let e of r.capabilities){let i=`${e}\0${r.addonId}`;t.has(i)||(t.add(i),n.push({name:e,addonId:r.addonId}))}return n.toSorted((e,t)=>e.name.localeCompare(t.name))}function Ne(e){let t=e.services;return{pid:e.pid,name:e.name,addonId:t?.[0]?.addonId??``,cpu:e.cpuPercent,mem:e.memoryRss,state:e.state,caps:Me(t)}}function Pe(e){return{nodeId:e.id,isHub:e.isHub,isOnline:e.isOnline,identity:{name:e.name,ip:e.localIps?.[0]??``,cpu:e.cpuPercent,mem:e.memoryPercent,platform:e.platform,arch:e.arch},runners:e.processes.map(Ne)}}function Fe(e){let t=e.toSorted((e,t)=>{let n=+!!e.isHub;return+!!t.isHub-n}).map(Pe),n=t.find(e=>e.isHub);return n===void 0?{nodes:t,edges:[]}:{nodes:t,edges:t.filter(e=>!e.isHub).map(e=>({id:`hub:${n.nodeId}->${e.nodeId}`,source:n.nodeId,target:e.nodeId,online:e.isOnline&&n.isOnline}))}}O();function Ie({onlineNodeIds:e}){let t=A(),r=n(),{data:o,isLoading:s}=i(),c=a({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]})}}),l=D(()=>{if(!o)return[];let t=new Set(e);return t.add(`hub`),o.filter(e=>!t.has(e.nodeId))},[o,e]);if(s)return j(`section`,{className:`rounded-lg border border-border bg-surface p-6 text-xs text-muted-foreground animate-pulse`,children:`Loading persisted agent settings…`});let u=async e=>{await r({title:`Remove offline agent?`,message:`Drop the persisted orchestrator settings for "${e}". This won't affect a node that comes back online — it just clears stale addonDefaults so it stops cluttering the cluster view.`,confirmLabel:`Remove`,cancelLabel:`Keep`,variant:`danger`})&&c.mutate({agentNodeId:e})};return l.length===0?j(`section`,{className:`rounded-lg border border-border bg-surface p-6`,children:E(`div`,{className:`flex flex-col items-center gap-2 text-center text-muted-foreground`,children:[j(Z,{className:`h-6 w-6 opacity-40`}),j(`p`,{className:`text-xs`,children:`No stale agent entries.`}),j(`p`,{className:`text-[11px] opacity-60`,children:`Every persisted nodeId matches a node currently online in the cluster.`})]})}):E(`section`,{className:`rounded-lg border border-border bg-surface`,children:[E(`header`,{className:`flex items-center gap-2 px-4 py-3 border-b border-border`,children:[j(Z,{className:`h-4 w-4 text-muted-foreground`}),j(`h2`,{className:`text-sm font-semibold`,children:`Offline agents`}),E(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,children:[l.length,` stale `,l.length===1?`entry`:`entries`]})]}),j(`p`,{className:`px-4 pt-3 text-[11px] text-muted-foreground`,children:`Persisted orchestrator settings for nodes not currently in the live topology. Remove entries you don't expect to come back — leftover from data-dir resets, env-driven nodeId changes, or decommissioned hosts.`}),j(`ul`,{className:`divide-y divide-border`,children:l.map(e=>{let t=Object.keys(e.settings.addonDefaults??{}).length,n=Object.values(e.settings.addonDefaults??{}).filter(e=>e?.enabled).length;return E(`li`,{className:`flex items-center gap-3 px-4 py-2 text-xs`,children:[j(`span`,{className:`font-mono text-foreground`,children:e.nodeId}),E(`span`,{className:`text-muted-foreground`,children:[t,` addons configured`,t>0&&E(k,{children:[` · `,n,` enabled`]})]}),E(`button`,{type:`button`,onClick:()=>{u(e.nodeId)},disabled:c.isPending,className:`ml-auto flex items-center gap-1 px-2 py-1 rounded text-destructive hover:bg-destructive/10 disabled:opacity-50`,children:[j(U,{className:`h-3 w-3`}),`Remove`]})]},e.nodeId)})})]})}O();function Le(e){let[t,n]=T(()=>typeof window<`u`?window.matchMedia(e).matches:!1);return M(()=>{let t=window.matchMedia(e),r=e=>n(e.matches);return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}function Re(){let{data:e,isLoading:t}=p(void 0,{staleTime:1/0}),[n,i]=T(null);return r(`cluster.topology-snapshot`,e=>{let t=e.data?.nodes;Array.isArray(t)&&i(t)}),{nodes:D(()=>n??e??[],[n,e]),isLoading:t&&!n}}function ze(){let[e,t]=T(`table`),[n,r]=T(void 0),[a,o]=T(0),s=Le(`(max-width: 767px)`),c=s&&e===`graph`?`table`:e,{nodes:l,isLoading:u}=Re(),d=D(()=>Fe(l),[l]),f=l.filter(e=>e.isOnline).length,p=l.filter(e=>!e.isOnline).length,m=D(()=>l.map(e=>e.id??``).filter(Boolean),[l]),{data:h}=i(),g=D(()=>{if(!h)return 0;let e=new Set(m);return e.add(`hub`),h.filter(t=>!e.has(t.nodeId)).length},[h,m]),_=w(e=>{t(`table`),r(e),o(e=>e+1)},[]),v=(n,r,i,a)=>E(`button`,{onClick:()=>t(n),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${e===n?`bg-primary text-primary-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[j(i,{className:`h-3.5 w-3.5`}),r,a!==void 0&&a>0&&j(`span`,{className:`ml-1 inline-flex h-4 min-w-[1rem] items-center justify-center rounded-full px-1 text-[10px] font-semibold ${e===n?`bg-primary-foreground/20 text-primary-foreground`:`bg-destructive/15 text-destructive`}`,children:a})]});return E(`div`,{className:`flex flex-col h-full gap-4 p-4`,children:[E(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[E(`div`,{className:`flex items-center gap-2`,children:[f>0&&E(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-success/10 text-success`,children:[f,` online`]}),p>0&&E(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:[p,` offline`]})]}),E(`div`,{className:`flex gap-0.5 p-1 rounded-lg bg-muted`,children:[v(`table`,`Table`,ce),!s&&v(`graph`,`Graph`,oe),v(`offline-agents`,`Offline agents`,Z,g)]})]}),u?j(`div`,{className:`flex items-center justify-center flex-1 text-muted-foreground`,children:`Loading cluster topology...`}):c===`graph`?j(je,{graph:d,onOpenNodeDetail:_}):c===`table`?j(`div`,{className:`flex-1 overflow-auto`,children:j(we,{nodes:l,focusNodeId:n,focusNonce:a})}):j(`div`,{className:`flex-1 overflow-auto`,children:j(Ie,{onlineNodeIds:m})})]})}export{ze as ClusterPage};
@@ -1 +1 @@
1
- import{O as e,dn as t,w as n}from"./src-FrhjLfXG.js";import{I as r,K as i,S as a,W as o,Z as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{t as l}from"./plus-CkYGohZo.js";import{S as u,i as d}from"./index-CmHNa_oF.js";s();var f=`camstack:dashboard-layout`,p={version:1,widgets:[]};function m(){try{let e=localStorage.getItem(f);if(!e)return p;let t=JSON.parse(e);return t&&t.version===1&&Array.isArray(t.widgets)?{version:1,widgets:t.widgets}:p}catch{return p}}function h(e){try{localStorage.setItem(f,JSON.stringify(e))}catch{}}function g(){let e=typeof crypto<`u`?crypto:void 0;return e?.randomUUID?e.randomUUID():`widget-${Date.now().toString(36)}-${Math.floor(Math.random()*1e6).toString(36)}`}function _(){let[t,n]=i(m),[s,u]=i(!1),d=e(),f=o(()=>d.filter(e=>e.hosts.includes(`dashboard`)),[d]),p=r(e=>{n(e),h(e)},[]),g=r(e=>{p({version:1,widgets:[...t.widgets,e]})},[t,p]),_=r(e=>{p({version:1,widgets:t.widgets.filter(t=>t.instanceId!==e)})},[t,p]);return a(`div`,{className:`p-4`,children:[a(`div`,{className:`flex items-center justify-between mb-4`,children:[c(`h1`,{className:`text-lg font-semibold text-foreground`,children:`Dashboard`}),a(`button`,{onClick:()=>u(!0),className:`flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:[c(l,{className:`h-3.5 w-3.5`}),`Add widget`]})]}),t.widgets.length===0?c(v,{onAdd:()=>u(!0)}):c(`div`,{className:`grid grid-cols-12 gap-3 auto-rows-[minmax(80px,_auto)]`,children:t.widgets.map(e=>c(y,{entry:e,onRemove:()=>_(e.instanceId)},e.instanceId))}),s&&c(x,{widgets:f,onClose:()=>u(!1),onAdd:e=>{g(e),u(!1)}})]})}function v({onAdd:e}){return a(`div`,{className:`flex flex-col items-center justify-center py-24 text-foreground-subtle`,children:[c(`div`,{className:`flex h-16 w-16 items-center justify-center rounded-2xl bg-surface border border-border mb-4`,children:c(u,{className:`h-8 w-8 text-foreground-subtle/40`})}),c(`p`,{className:`text-sm font-medium text-foreground/70`,children:`Your dashboard is empty`}),c(`p`,{className:`text-xs text-foreground-subtle mt-1 mb-4`,children:`Add widgets to monitor your cameras and system`}),a(`button`,{onClick:e,className:`flex items-center gap-1.5 rounded-lg bg-primary px-4 py-2 text-xs font-semibold text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg transition-all`,children:[c(l,{className:`h-3.5 w-3.5`}),`Add your first widget`]})]})}function y({entry:e,onRemove:t}){let r=b(e.columns),i=Math.max(1,Math.min(12,e.rows));return a(`div`,{className:`relative group rounded-lg border border-border bg-surface overflow-hidden flex flex-col`,style:{gridColumn:`span ${r} / span ${r}`,gridRow:`span ${i} / span ${i}`},children:[c(`button`,{type:`button`,onClick:t,title:`Remove widget`,className:`absolute right-1.5 top-1.5 z-10 inline-flex h-5 w-5 items-center justify-center rounded-md border border-border/60 bg-surface/80 text-foreground-subtle opacity-0 group-hover:opacity-100 hover:bg-danger/10 hover:text-danger hover:border-danger/40 transition-all`,children:c(d,{className:`h-3 w-3`})}),c(`div`,{className:`flex-1 min-h-0 overflow-auto p-2`,children:c(n,{widgetId:e.widgetId,host:`dashboard`,instanceId:e.instanceId,config:e.config,deviceId:e.deviceId,size:e.size,columns:e.columns,rows:e.rows})})]})}function b(e){return!Number.isFinite(e)||e<1?6:Math.min(12,Math.floor(e))}function x({widgets:e,onClose:t,onAdd:n}){let[r,o]=i(null);return c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:t,children:a(`div`,{className:`w-full max-w-2xl rounded-xl border border-border bg-surface p-5 shadow-2xl shadow-black/20`,onClick:e=>e.stopPropagation(),children:[a(`div`,{className:`flex items-center justify-between mb-4`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:r?`Configure: ${r.label}`:`Add widget`}),c(`button`,{onClick:t,className:`p-1 rounded-md hover:bg-surface-hover text-foreground-subtle hover:text-foreground transition-colors`,children:c(d,{className:`h-4 w-4`})})]}),r===null?c(S,{widgets:e,onSelect:o}):c(C,{widget:r,onCancel:()=>o(null),onAdd:n})]})})}function S({widgets:e,onSelect:t}){return e.length===0?c(`div`,{className:`text-center py-8 text-xs text-foreground-subtle italic`,children:`No dashboard-host widgets registered. Make sure the contributing addons are enabled and have rebuilt their widget bundles.`}):c(`div`,{className:`grid grid-cols-2 gap-2 max-h-96 overflow-auto`,children:e.map(e=>a(`button`,{onClick:()=>t(e),className:`flex flex-col rounded-lg border border-border p-3 text-left hover:bg-surface-hover hover:border-primary/30 transition-all group`,children:[c(`span`,{className:`text-xs font-medium text-foreground block`,children:e.label}),c(`span`,{className:`text-[10px] text-foreground-subtle truncate`,title:e.widgetId,children:e.widgetId}),e.description&&c(`span`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-2`,children:e.description})]},e.widgetId))})}function C({widget:e,onCancel:n,onAdd:r}){let[o,s]=i(e.defaultSize),[l,u]=i(e.defaultColumns),[d,f]=i(e.defaultRows),[p,m]=i(null),{data:h}=t({},{enabled:e.requires.deviceContext}),_=!e.requires.deviceContext||p!==null&&p>0;return a(`div`,{className:`space-y-3`,children:[a(`div`,{children:[c(`label`,{className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Size`}),c(`div`,{className:`flex items-center gap-1`,children:e.allowedSizes.map(e=>c(`button`,{onClick:()=>s(e),className:`px-3 py-1 rounded-md text-[11px] font-medium border transition-colors ${o===e?`bg-primary/10 text-primary border-primary/30`:`border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.toUpperCase()},e))})]}),a(`div`,{className:`grid grid-cols-2 gap-3`,children:[c(w,{label:`Columns (1-12)`,value:l,min:1,max:12,onChange:u}),c(w,{label:`Rows (1-12)`,value:d,min:1,max:12,onChange:f})]}),e.requires.deviceContext&&a(`div`,{children:[c(`label`,{className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Device`}),a(`select`,{value:p??``,onChange:e=>m(e.target.value===``?null:Number(e.target.value)),className:`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none`,children:[c(`option`,{value:``,children:`— select a device —`}),(h??[]).map(e=>a(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),a(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[c(`button`,{onClick:n,className:`px-3 py-1.5 rounded-md text-xs font-medium border border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,children:`Back`}),c(`button`,{disabled:!_,onClick:()=>{_&&r({instanceId:g(),widgetId:e.widgetId,size:o,columns:l,rows:d,...e.requires.deviceContext&&p!==null?{deviceId:p}:{}})},className:`px-3 py-1.5 rounded-md text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:`Add to dashboard`})]})]})}function w({label:e,value:t,min:n,max:r,onChange:i}){return a(`div`,{children:[c(`label`,{className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:e}),c(`input`,{type:`number`,min:n,max:r,value:t,onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&i(Math.max(n,Math.min(r,Math.floor(t))))},className:`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none`})]})}function T(){return c(_,{})}export{T as DashboardPage};
1
+ import{O as e,dn as t,w as n}from"./src-OU6ujZuo.js";import{I as r,K as i,S as a,W as o,Z as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{t as l}from"./plus-BhEoEvZK.js";import{S as u,i as d}from"./index-BW7XX5wA.js";s();var f=`camstack:dashboard-layout`,p={version:1,widgets:[]};function m(){try{let e=localStorage.getItem(f);if(!e)return p;let t=JSON.parse(e);return t&&t.version===1&&Array.isArray(t.widgets)?{version:1,widgets:t.widgets}:p}catch{return p}}function h(e){try{localStorage.setItem(f,JSON.stringify(e))}catch{}}function g(){let e=typeof crypto<`u`?crypto:void 0;return e?.randomUUID?e.randomUUID():`widget-${Date.now().toString(36)}-${Math.floor(Math.random()*1e6).toString(36)}`}function _(){let[t,n]=i(m),[s,u]=i(!1),d=e(),f=o(()=>d.filter(e=>e.hosts.includes(`dashboard`)),[d]),p=r(e=>{n(e),h(e)},[]),g=r(e=>{p({version:1,widgets:[...t.widgets,e]})},[t,p]),_=r(e=>{p({version:1,widgets:t.widgets.filter(t=>t.instanceId!==e)})},[t,p]);return a(`div`,{className:`p-4`,children:[a(`div`,{className:`flex items-center justify-between mb-4`,children:[c(`h1`,{className:`text-lg font-semibold text-foreground`,children:`Dashboard`}),a(`button`,{onClick:()=>u(!0),className:`flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:[c(l,{className:`h-3.5 w-3.5`}),`Add widget`]})]}),t.widgets.length===0?c(v,{onAdd:()=>u(!0)}):c(`div`,{className:`grid grid-cols-12 gap-3 auto-rows-[minmax(80px,_auto)]`,children:t.widgets.map(e=>c(y,{entry:e,onRemove:()=>_(e.instanceId)},e.instanceId))}),s&&c(x,{widgets:f,onClose:()=>u(!1),onAdd:e=>{g(e),u(!1)}})]})}function v({onAdd:e}){return a(`div`,{className:`flex flex-col items-center justify-center py-24 text-foreground-subtle`,children:[c(`div`,{className:`flex h-16 w-16 items-center justify-center rounded-2xl bg-surface border border-border mb-4`,children:c(u,{className:`h-8 w-8 text-foreground-subtle/40`})}),c(`p`,{className:`text-sm font-medium text-foreground/70`,children:`Your dashboard is empty`}),c(`p`,{className:`text-xs text-foreground-subtle mt-1 mb-4`,children:`Add widgets to monitor your cameras and system`}),a(`button`,{onClick:e,className:`flex items-center gap-1.5 rounded-lg bg-primary px-4 py-2 text-xs font-semibold text-primary-foreground shadow-md shadow-primary/20 hover:shadow-lg transition-all`,children:[c(l,{className:`h-3.5 w-3.5`}),`Add your first widget`]})]})}function y({entry:e,onRemove:t}){let r=b(e.columns),i=Math.max(1,Math.min(12,e.rows));return a(`div`,{className:`relative group rounded-lg border border-border bg-surface overflow-hidden flex flex-col`,style:{gridColumn:`span ${r} / span ${r}`,gridRow:`span ${i} / span ${i}`},children:[c(`button`,{type:`button`,onClick:t,title:`Remove widget`,className:`absolute right-1.5 top-1.5 z-10 inline-flex h-5 w-5 items-center justify-center rounded-md border border-border/60 bg-surface/80 text-foreground-subtle opacity-0 group-hover:opacity-100 hover:bg-danger/10 hover:text-danger hover:border-danger/40 transition-all`,children:c(d,{className:`h-3 w-3`})}),c(`div`,{className:`flex-1 min-h-0 overflow-auto p-2`,children:c(n,{widgetId:e.widgetId,host:`dashboard`,instanceId:e.instanceId,config:e.config,deviceId:e.deviceId,size:e.size,columns:e.columns,rows:e.rows})})]})}function b(e){return!Number.isFinite(e)||e<1?6:Math.min(12,Math.floor(e))}function x({widgets:e,onClose:t,onAdd:n}){let[r,o]=i(null);return c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:t,children:a(`div`,{className:`w-full max-w-2xl rounded-xl border border-border bg-surface p-5 shadow-2xl shadow-black/20`,onClick:e=>e.stopPropagation(),children:[a(`div`,{className:`flex items-center justify-between mb-4`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:r?`Configure: ${r.label}`:`Add widget`}),c(`button`,{onClick:t,className:`p-1 rounded-md hover:bg-surface-hover text-foreground-subtle hover:text-foreground transition-colors`,children:c(d,{className:`h-4 w-4`})})]}),r===null?c(S,{widgets:e,onSelect:o}):c(C,{widget:r,onCancel:()=>o(null),onAdd:n})]})})}function S({widgets:e,onSelect:t}){return e.length===0?c(`div`,{className:`text-center py-8 text-xs text-foreground-subtle italic`,children:`No dashboard-host widgets registered. Make sure the contributing addons are enabled and have rebuilt their widget bundles.`}):c(`div`,{className:`grid grid-cols-2 gap-2 max-h-96 overflow-auto`,children:e.map(e=>a(`button`,{onClick:()=>t(e),className:`flex flex-col rounded-lg border border-border p-3 text-left hover:bg-surface-hover hover:border-primary/30 transition-all group`,children:[c(`span`,{className:`text-xs font-medium text-foreground block`,children:e.label}),c(`span`,{className:`text-[10px] text-foreground-subtle truncate`,title:e.widgetId,children:e.widgetId}),e.description&&c(`span`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-2`,children:e.description})]},e.widgetId))})}function C({widget:e,onCancel:n,onAdd:r}){let[o,s]=i(e.defaultSize),[l,u]=i(e.defaultColumns),[d,f]=i(e.defaultRows),[p,m]=i(null),{data:h}=t({},{enabled:e.requires.deviceContext}),_=!e.requires.deviceContext||p!==null&&p>0;return a(`div`,{className:`space-y-3`,children:[a(`div`,{children:[c(`label`,{className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Size`}),c(`div`,{className:`flex items-center gap-1`,children:e.allowedSizes.map(e=>c(`button`,{onClick:()=>s(e),className:`px-3 py-1 rounded-md text-[11px] font-medium border transition-colors ${o===e?`bg-primary/10 text-primary border-primary/30`:`border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.toUpperCase()},e))})]}),a(`div`,{className:`grid grid-cols-2 gap-3`,children:[c(w,{label:`Columns (1-12)`,value:l,min:1,max:12,onChange:u}),c(w,{label:`Rows (1-12)`,value:d,min:1,max:12,onChange:f})]}),e.requires.deviceContext&&a(`div`,{children:[c(`label`,{className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Device`}),a(`select`,{value:p??``,onChange:e=>m(e.target.value===``?null:Number(e.target.value)),className:`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none`,children:[c(`option`,{value:``,children:`— select a device —`}),(h??[]).map(e=>a(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),a(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[c(`button`,{onClick:n,className:`px-3 py-1.5 rounded-md text-xs font-medium border border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,children:`Back`}),c(`button`,{disabled:!_,onClick:()=>{_&&r({instanceId:g(),widgetId:e.widgetId,size:o,columns:l,rows:d,...e.requires.deviceContext&&p!==null?{deviceId:p}:{}})},className:`px-3 py-1.5 rounded-md text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:`Add to dashboard`})]})]})}function w({label:e,value:t,min:n,max:r,onChange:i}){return a(`div`,{children:[c(`label`,{className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:e}),c(`input`,{type:`number`,min:n,max:r,value:t,onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&i(Math.max(n,Math.min(r,Math.floor(t))))},className:`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none`})]})}function T(){return c(_,{})}export{T as DashboardPage};
@@ -1 +1 @@
1
- import{At as e,Bi as t,Dt as n,Et as r,Mt as i,Nt as a,Ot as o,Pi as s,Pt as c,ai as l,jt as u,kt as d,li as f,oi as p,si as m,ut as h}from"./src-FrhjLfXG.js";import{I as g,K as _,S as v,W as y,Z as b,b as x,o as S,x as C,z as w}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{D as T}from"./src-DsE0ulBa.js";import{t as E}from"./download-uGUg4MiO.js";import{i as D,n as O,r as k,t as A}from"./AddLocationWizard-g-iCisaY.js";import{t as j}from"./plus-CkYGohZo.js";import{t as M}from"./rotate-cw-B9ioWOhh.js";import{B as N,M as P,P as F,R as ee,i as I,s as L,x as R}from"./index-CmHNa_oF.js";import{t as z}from"./AdminPage-vtcsGqRq.js";import{t as B}from"./format-size-CO9d3C3-.js";import{t as V}from"./AdminTabs-82KAodwc.js";var H=N(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),te=N(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),ne=N(`calendar-clock`,[[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M17.5 17.5 16 16.3V14`,key:`akvzfd`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]);b();function U(){let e=S(),t=s(),{data:n,isLoading:r,isError:i}=m({}),a=p(),o=y(()=>a.data??[],[a.data]),[c,u]=_(null),[d,h]=_(null),g=l({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),b=f({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),x=e=>{e.isDefault||b.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},w=async e=>{if(e.isDefault){await t({title:`Cannot delete default location`,message:`"${e.displayName}" is the default for type "${e.type}". Mark another location as default first, then delete this one.`,confirmLabel:`OK`,variant:`warning`});return}await t({title:`Delete location "${e.displayName}"?`,message:`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`,confirmLabel:`Delete`,variant:`danger`})&&g.mutate({id:e.id})},T=y(()=>{let e=new Map;for(let t of n??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[n]),E=r||a.isLoading,D=i||a.isError;return v(z,{children:[E&&C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),D&&C(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!E&&!D&&v(`div`,{className:`space-y-3`,children:[o.length===0&&C(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),o.map(e=>C(k,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:T.get(e.id)??[],onAdd:e=>u(e),onEdit:e=>h(e),onDelete:e=>{w(e)},onSetDefault:e=>x(e)},e.id))]}),c!==null&&C(A,{initialType:c,onClose:()=>u(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),u(null)}}),d!==null&&C(O,{location:d,onClose:()=>h(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),h(null)}})]})}b();var W=[[`backup`,`listDestinations`]],G=[`backup`,`listArchives`];function K({destinationId:e,restoreSupported:t,onOpenRestoreWizard:n}){let i=S(),a=s(),{data:c,isLoading:l,isError:u}=o({destinationId:e}),d=c??[],f=r({onSuccess:()=>{i.invalidateQueries({queryKey:[[...G]]}),i.invalidateQueries({queryKey:W})}}),p=g(async t=>{await a({title:`Delete this archive?`,message:`Permanently deletes "${t.label??t.id}" and frees ${B(t.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&f.mutate({destinationId:e,backupId:t.id})},[a,e,f]),[m,h]=_(null),b=g(async t=>{h(t.id);try{let n=localStorage.getItem(`camstack_admin_token`),r={};n&&(r.Authorization=`Bearer ${n}`);let i=await fetch(q(e,t.id),{headers:r});if(!i.ok)throw Error(`download failed: ${i.status} ${i.statusText}`);let a=await i.blob(),o=URL.createObjectURL(a),s=document.createElement(`a`);s.href=o,s.download=`${t.label??t.id}.tar.gz`,document.body.appendChild(s),s.click(),s.remove(),URL.revokeObjectURL(o)}finally{h(null)}},[e]),x=y(()=>[...d].toSorted((e,t)=>t.createdAt-e.createdAt),[d]);return l?C(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):u?C(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):x.length===0?C(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):C(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:v(`table`,{className:`w-full text-xs min-w-[640px]`,children:[C(`thead`,{children:v(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),C(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),C(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),C(`tbody`,{children:x.map(r=>v(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[C(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:J(r.createdAt)}),C(`td`,{className:`px-3 py-1.5 text-foreground`,children:r.label??C(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),C(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:r.locations.join(`, `)}),C(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:B(r.sizeBytes)}),C(`td`,{className:`px-3 py-1.5`,children:v(`div`,{className:`flex items-center justify-end gap-1`,children:[v(`button`,{onClick:()=>{b(r)},disabled:m===r.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 disabled:opacity-50`,title:`Download archive`,children:[m===r.id?C(R,{className:`h-3 w-3 animate-spin`}):C(E,{className:`h-3 w-3`}),`Download`]}),t&&n&&v(`button`,{onClick:()=>n({destinationId:e,archiveId:r.id}),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10`,title:`Restore from this archive`,children:[C(M,{className:`h-3 w-3`}),`Restore`]}),C(`button`,{onClick:()=>{p(r)},disabled:f.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete archive`,children:f.isPending?C(R,{className:`h-3 w-3 animate-spin`}):C(L,{className:`h-3 w-3`})})]})})]},r.id))})]})})}function q(e,t){return`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function J(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}b();var Y=[{id:`manual`,label:`Manual only`,cron:``},{id:`hourly`,label:`Every hour`,cron:`0 * * * *`,description:`On the hour`},{id:`every-3h`,label:`Every 3 hours`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,label:`Every 6 hours`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,label:`Daily at 03:00`,cron:`0 3 * * *`,description:`Every night at 3 AM`},{id:`weekly-sun`,label:`Weekly Sunday 03:00`,cron:`0 3 * * 0`,description:`Sunday morning at 3 AM`}];function X(e){let t=e.trim();for(let e of Y)if(e.cron===t)return e.id;return`custom`}function Z({value:e,onChange:t,previewCount:n=5,disabled:r=!1}){let i=X(e),[a,o]=_(i===`custom`);w(()=>{i!==`custom`&&o(!1)},[i]);let s=ae(e,250),c=u({cron:s,count:n},{enabled:s.trim().length>0}),l=c.data??null,d=e=>{o(!1),t(e.cron)},f=a||i===`custom`;return v(`div`,{className:`space-y-3`,children:[v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),v(`div`,{className:`flex flex-wrap gap-1.5`,children:[Y.map(e=>C(`button`,{type:`button`,onClick:()=>d(e),disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!a&&i===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.description??e.label,children:e.label},e.id)),C(`button`,{type:`button`,onClick:()=>{o(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(f?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),f&&v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),C(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:r,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),v(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,C(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),C(re,{cron:s,preview:l,loading:c.isFetching})]})}function re({cron:e,preview:t,loading:n}){return n&&t===null?v(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[C(R,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?C(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:`No future runs match this expression.`}):v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),C(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>v(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[C(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),C(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:ie(e)})]},`${e}-${t}`))})]}):C(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??`Invalid cron expression`})}function ie(e){let t=e-Date.now();if(t<=0)return`now`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function ae(e,t){let[n,r]=_(e),i=y(()=>e,[e]);return w(()=>{let e=setTimeout(()=>r(i),t);return()=>clearTimeout(e)},[i,t]),n}b();var oe=[[`backup`,`listDestinations`]];function se({onCreateAt:e,onOpenRestoreWizard:t}){let{data:n,isLoading:r,isError:i}=d(),a=n??[],[o,s]=_(null),c=e=>{s(t=>t===e?null:e)},l=fe();return r?C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading destinations…`}):i?C(`div`,{className:`text-xs text-danger`,children:`Failed to load destinations`}):a.length===0?C(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:C(`p`,{className:`text-xs text-foreground-subtle`,children:"No `backups`-typed storage locations registered. Add one in Settings → Storage to begin."})}):C(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:v(`table`,{className:`w-full text-xs min-w-[720px]`,children:[C(`thead`,{children:v(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[C(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),C(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Destination`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-28`,children:`Retention`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-56`,children:`Schedule`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-44`,children:`Last success`}),C(`th`,{className:`text-right px-3 py-2 font-medium w-44`,children:`Actions`})]})}),C(`tbody`,{children:a.map(n=>{let r=l.get(n.id);return C(ce,{row:n,isOpen:o===n.id,onToggle:()=>c(n.id),onCreateAt:e,liveLastSuccessAt:r?.at,liveLastSuccessSizeBytes:r?.sizeBytes,...t?{onOpenRestoreWizard:t}:{}},n.id)})})]})})}function ce({row:e,isOpen:t,onToggle:n,onCreateAt:r,onOpenRestoreWizard:i,liveLastSuccessAt:a,liveLastSuccessSizeBytes:o}){let s=S(),l=c({onSuccess:()=>{s.invalidateQueries({queryKey:oe})}}),[u,d]=_(String(e.retentionCount));w(()=>{d(String(e.retentionCount))},[e.retentionCount]);let[f,p]=_(!1),m=g(t=>{l.mutate({locationId:e.id,enabled:t,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[l,e.id,e.retentionCount,e.label,e.cron]),h=g(()=>{let t=Number.parseInt(u,10);if(Number.isNaN(t)||t<1){d(String(e.retentionCount));return}t!==e.retentionCount&&l.mutate({locationId:e.id,enabled:e.enabled,retentionCount:t,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[l,u,e.id,e.enabled,e.retentionCount,e.label,e.cron]),y=g(t=>{l.mutate({locationId:e.id,enabled:e.enabled,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},cron:t},{onSuccess:()=>{p(!1)}})},[l,e.id,e.enabled,e.retentionCount,e.label]);return v(x,{children:[v(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[C(`td`,{className:`px-2 py-2`,children:C(`button`,{onClick:n,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:t?`Hide archives`:`Show archives`,children:C(t?F:P,{className:`h-3.5 w-3.5`})})}),C(`td`,{className:`px-3 py-2`,children:v(`button`,{onClick:n,className:`text-left hover:underline focus:outline-none`,title:`View archives`,children:[C(`div`,{className:`text-foreground font-medium`,children:e.displayName}),v(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[C(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5`,children:e.kind}),C(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]})}),C(`td`,{className:`px-3 py-2`,children:C(`label`,{className:`inline-flex items-center cursor-pointer`,children:C(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:l.isPending,onChange:e=>m(e.target.checked)})})}),C(`td`,{className:`px-3 py-2`,children:C(`input`,{type:`number`,min:1,max:1e3,value:u,disabled:l.isPending,onChange:e=>d(e.target.value),onBlur:h,onKeyDown:t=>{t.key===`Enter`&&t.target.blur(),t.key===`Escape`&&d(String(e.retentionCount))},className:`w-16 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})}),C(`td`,{className:`px-3 py-2`,children:C(le,{cron:e.cron,nextRunAt:e.nextRunAt,onEdit:()=>p(!0),disabled:l.isPending})}),C(`td`,{className:`px-3 py-2 text-foreground-subtle`,children:(()=>{let t=pe(a,e.lastSuccessAt),n=t===a?o:e.lastSuccessSizeBytes;return t===void 0?C(`span`,{className:`italic`,children:`Never`}):C(me,{at:t,sizeBytes:n})})()}),C(`td`,{className:`px-3 py-2`,children:C(`div`,{className:`flex items-center justify-end gap-1.5`,children:e.triggerSupported&&v(`button`,{onClick:()=>r(e),className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90`,children:[C(j,{className:`h-3 w-3`}),`Create here`]})})})]}),t&&C(`tr`,{className:`border-t border-border bg-background/30`,children:C(`td`,{colSpan:7,className:`px-4 py-3`,children:C(K,{destinationId:e.id,restoreSupported:e.restoreSupported,...i?{onOpenRestoreWizard:i}:{}})})}),f&&C(de,{destinationName:e.displayName,currentCron:e.cron??``,onSave:y,onClose:()=>p(!1),saving:l.isPending,saveError:l.error instanceof Error?l.error.message:null})]})}function le({cron:e,nextRunAt:t,onEdit:n,disabled:r}){let i=typeof e==`string`&&e.trim().length>0;return v(`button`,{type:`button`,onClick:n,disabled:r,className:`group flex flex-col items-start gap-0.5 text-left rounded px-1.5 py-1 -mx-1.5 hover:bg-primary/5 disabled:opacity-50`,title:`Edit schedule`,children:[v(`div`,{className:`flex items-center gap-1.5`,children:[C(ne,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),C(`span`,{className:i?`font-mono text-foreground`:`italic text-foreground-subtle`,children:i?e:`Manual`})]}),i&&t!==void 0&&v(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[`next `,ue(t)]})]})}function ue(e){let t=e-Date.now();if(t<=0)return`imminent`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function de({destinationName:e,currentCron:t,onSave:n,onClose:r,saving:i,saveError:a}){let[o,s]=_(t);return C(`tr`,{children:C(`td`,{colSpan:7,className:`p-0`,children:C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:v(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Schedule`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e]})]}),C(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,title:`Close`,children:C(I,{className:`h-4 w-4`})})]}),v(`div`,{className:`p-4`,children:[C(Z,{value:o,onChange:s,disabled:i}),a!==null&&C(`div`,{className:`mt-3 rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:a})]}),v(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[C(`button`,{onClick:r,disabled:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground disabled:opacity-50`,children:`Cancel`}),C(`button`,{onClick:()=>n(o.trim()),disabled:i||o.trim()===t.trim(),className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:i?`Saving…`:`Save`})]})]})})})})}function fe(){let{map:e}=t(T.BackupCompleted,e=>e.destinationId);return y(()=>{let t=new Map;for(let[n,r]of e)t.set(n,{at:Date.now(),sizeBytes:r.sizeMB*1024*1024});return t},[e])}function pe(e,t){return e===void 0?t:t===void 0||e>t?e:t}function me({at:e,sizeBytes:t}){let n=he(e);return v(`span`,{title:y(()=>new Date(e).toLocaleString(),[e]),className:`text-foreground tabular-nums`,children:[n,t!==void 0&&v(`span`,{className:`ml-1 text-foreground-subtle`,children:[`· `,B(t)]})]})}function he(e){let[,t]=_(0);return w(()=>{let e=setInterval(()=>t(e=>e+1),3e4);return()=>clearInterval(e)},[]),ge(e)}function ge(e){let t=Math.max(0,Date.now()-e),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(a/365)}y ago`}b();var _e=[[`backup`,`list`]];function ve({initialDestinationId:e,initialArchiveId:t,onClose:r,onScheduled:a}){let s=S(),[c,l]=_(e&&t?2:1),[u,f]=_(e),[p,m]=_(t),[h,g]=_(new Set),{data:b}=d(),x=b??[],{data:T,isLoading:E}=o({destinationId:u??``},{enabled:!!u}),D=T??[];w(()=>{if(u!==void 0)return;let e=x.filter(e=>e.restoreSupported);e.length===1&&f(e[0].id)},[u,x]);let{data:O}=n({destinationId:u??``,backupId:p??``},{enabled:!!u&&!!p}),k=y(()=>O?.locations??[],[O]);w(()=>{k.length!==0&&g(e=>e.size===0?new Set(k):e)},[k]);let A=i({onSuccess:()=>{s.invalidateQueries({queryKey:_e}),a(),r()}}),j=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},N=!!u&&!!p,P=h.size>0,F=N&&P&&!A.isPending,L=()=>{!u||!p||A.mutate({destinationId:u,backupId:p,locations:[...h]})};return C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:v(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,c,` of 3 —`,` `,c===1?`pick source`:c===2?`pick locations`:`confirm`]})]}),C(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:C(I,{className:`h-4 w-4`})})]}),c===1&&C(ye,{destinations:x,destinationId:u,onPickDestination:e=>{f(e),m(void 0),g(new Set)},archives:D,archivesLoading:E,archiveId:p,onPickArchive:m}),c===2&&C(be,{locations:k,picked:h,onToggle:j}),c===3&&C(xe,{destinationName:x.find(e=>e.id===u)?.displayName??u??``,archive:D.find(e=>e.id===p),picked:[...h]}),v(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[C(`div`,{children:c>1&&v(`button`,{onClick:()=>l(e=>e===3?2:1),className:`inline-flex items-center gap-1 rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:[C(ee,{className:`h-3 w-3`}),`Back`]})}),v(`div`,{className:`flex items-center gap-2`,children:[C(`button`,{onClick:r,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),c<3?v(`button`,{disabled:c===1&&!N||c===2&&!P,onClick:()=>l(e=>e===1?2:3),className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[`Next`,C(te,{className:`h-3 w-3`})]}):v(`button`,{onClick:L,disabled:!F,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[A.isPending?C(R,{className:`h-3.5 w-3.5 animate-spin`}):C(M,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function ye({destinations:e,destinationId:t,onPickDestination:n,archives:r,archivesLoading:i,archiveId:a,onPickArchive:o}){let s=e.filter(e=>e.restoreSupported);return v(`div`,{className:`p-4 space-y-3`,children:[v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),v(`select`,{value:t??``,onChange:e=>n(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[C(`option`,{value:``,disabled:!0,children:`Select destination…`}),s.map(e=>v(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&C(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&i&&C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!i&&r.length===0&&C(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&r.length>0&&C(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:r.map(e=>{let t=a===e.id;return v(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>o(e.id),className:`accent-primary`}),v(`div`,{children:[C(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),C(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),C(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:B(e.sizeBytes)})]},e.id)})})]})]})}function be({locations:e,picked:t,onToggle:n}){return e.length===0?C(`div`,{className:`p-4`,children:C(`div`,{className:`text-xs text-foreground-subtle`,children:`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`})}):v(`div`,{className:`p-4 space-y-3`,children:[C(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),C(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>v(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[C(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),C(`span`,{className:`font-mono text-foreground`,children:e}),C(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ce(e)})]},e))})]})]})}function xe({destinationName:e,archive:t,picked:n}){return v(`div`,{className:`p-4 space-y-3 text-xs`,children:[C(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300`,children:`Restore is applied at next server boot. Active connections will drop when you restart.`}),v(`dl`,{className:`space-y-1.5`,children:[C(Q,{term:`Destination`,value:e}),C(Q,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&C(Q,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${B(t.sizeBytes)}`}),C(Q,{term:`Locations`,value:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function Q({term:e,value:t}){return v(`div`,{className:`flex justify-between gap-3`,children:[C(`dt`,{className:`text-foreground-subtle`,children:e}),C(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Se={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function Ce(e){return Se[e]??``}b();var $=[[`backup`,`list`]],we=[[`backup`,`listLocations`]];function Te(){let t=S(),n=s(),{data:r}=e(),i=a({onSuccess:()=>{t.invalidateQueries({queryKey:$}),t.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),t.invalidateQueries({queryKey:[[`backup`,`listArchives`]]})}}),o=h(),[c,l]=_(null),[u,d]=_(null),[f,p]=_(!1),[m,g]=_(!1),[y,b]=_(!1),x=async()=>{await n({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&o.mutate({confirm:!0})};return v(z,{children:[v(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[v(`button`,{onClick:()=>p(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[C(M,{className:`h-3.5 w-3.5`}),`Restore…`]}),v(`button`,{onClick:()=>b(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[C(j,{className:`h-3.5 w-3.5`}),`Add destination`]})]}),m&&C(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2.5 text-xs text-amber-700 dark:text-amber-300`,children:v(`div`,{className:`flex items-center justify-between gap-3`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(M,{className:`h-3.5 w-3.5`}),C(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),v(`button`,{onClick:()=>{x()},disabled:o.isPending,className:`inline-flex items-center gap-1.5 rounded bg-amber-500/20 px-2 py-1 font-medium text-amber-800 dark:text-amber-200 hover:bg-amber-500/30 disabled:opacity-50`,children:[o.isPending?C(R,{className:`h-3.5 w-3.5 animate-spin`}):C(M,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),C(se,{onCreateAt:e=>l(e),onOpenRestoreWizard:e=>d(e)}),c&&C(Ee,{destination:c,locations:r??[],onClose:()=>l(null),onSubmit:(e,n)=>{i.mutate({destinations:[c.id],locations:e,label:n||void 0},{onSuccess:()=>{l(null),t.invalidateQueries({queryKey:we})}})},submitting:i.isPending}),(u||f)&&C(ve,{...u?{initialDestinationId:u.destinationId,initialArchiveId:u.archiveId}:{},onClose:()=>{d(null),p(!1)},onScheduled:()=>g(!0)}),y&&C(A,{initialType:`backups`,onClose:()=>b(!1),onCreated:()=>{b(!1),t.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]})}})]})}function Ee({destination:e,locations:t,onClose:n,onSubmit:r,submitting:i}){let a=t.filter(e=>e.present),[o,s]=_(``),[c,l]=_(()=>new Set(a.map(e=>e.name))),u=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:v(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Create Backup`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e.displayName]})]}),C(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:C(I,{className:`h-4 w-4`})})]}),v(`div`,{className:`p-4 space-y-3`,children:[v(`div`,{className:`space-y-1`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Label (optional)`}),C(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`pre-upgrade`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Include`}),v(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:[a.length===0&&C(`div`,{className:`px-3 py-2 text-xs text-foreground-subtle italic`,children:`Nothing to back up.`}),a.map(e=>v(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(`input`,{type:`checkbox`,checked:c.has(e.name),onChange:()=>u(e.name),className:`accent-primary`}),C(`span`,{className:`font-mono text-foreground`,children:e.name})]}),v(`div`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[B(e.sizeBytes),` · `,e.fileCount,` files`]})]},e.name))]})]})]}),v(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[C(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),v(`button`,{onClick:()=>r(Array.from(c),o.trim()),disabled:i||c.size===0,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[i?C(R,{className:`h-3.5 w-3.5 animate-spin`}):C(H,{className:`h-3.5 w-3.5`}),i?`Creating…`:`Create`]})]})]})})}function De(){return C(`div`,{className:`flex flex-col p-4`,children:C(V,{tabs:[{id:`storage`,label:`Storage`,icon:D,content:C(U,{})},{id:`backup`,label:`Backup`,icon:H,content:C(Te,{})}]})})}export{De as DataPage};
1
+ import{At as e,Bi as t,Dt as n,Et as r,Mt as i,Nt as a,Ot as o,Pi as s,Pt as c,ai as l,jt as u,kt as d,li as f,oi as p,si as m,ut as h}from"./src-OU6ujZuo.js";import{I as g,K as _,S as v,W as y,Z as b,b as x,o as S,x as C,z as w}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{D as T}from"./src-CHN2F0ZH.js";import{t as E}from"./download-D5j8EDrN.js";import{i as D,n as O,r as k,t as A}from"./AddLocationWizard-B7NQrvQP.js";import{t as j}from"./plus-BhEoEvZK.js";import{t as M}from"./rotate-cw-BvT3aWsW.js";import{B as N,M as P,P as F,R as ee,i as I,s as L,x as R}from"./index-BW7XX5wA.js";import{t as z}from"./AdminPage-vtcsGqRq.js";import{t as B}from"./format-size-CO9d3C3-.js";import{t as V}from"./AdminTabs-exsrTA0L.js";var H=N(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),te=N(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),ne=N(`calendar-clock`,[[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M17.5 17.5 16 16.3V14`,key:`akvzfd`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]);b();function U(){let e=S(),t=s(),{data:n,isLoading:r,isError:i}=m({}),a=p(),o=y(()=>a.data??[],[a.data]),[c,u]=_(null),[d,h]=_(null),g=l({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),b=f({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),x=e=>{e.isDefault||b.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},w=async e=>{if(e.isDefault){await t({title:`Cannot delete default location`,message:`"${e.displayName}" is the default for type "${e.type}". Mark another location as default first, then delete this one.`,confirmLabel:`OK`,variant:`warning`});return}await t({title:`Delete location "${e.displayName}"?`,message:`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`,confirmLabel:`Delete`,variant:`danger`})&&g.mutate({id:e.id})},T=y(()=>{let e=new Map;for(let t of n??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[n]),E=r||a.isLoading,D=i||a.isError;return v(z,{children:[E&&C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),D&&C(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!E&&!D&&v(`div`,{className:`space-y-3`,children:[o.length===0&&C(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),o.map(e=>C(k,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:T.get(e.id)??[],onAdd:e=>u(e),onEdit:e=>h(e),onDelete:e=>{w(e)},onSetDefault:e=>x(e)},e.id))]}),c!==null&&C(A,{initialType:c,onClose:()=>u(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),u(null)}}),d!==null&&C(O,{location:d,onClose:()=>h(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),h(null)}})]})}b();var W=[[`backup`,`listDestinations`]],G=[`backup`,`listArchives`];function K({destinationId:e,restoreSupported:t,onOpenRestoreWizard:n}){let i=S(),a=s(),{data:c,isLoading:l,isError:u}=o({destinationId:e}),d=c??[],f=r({onSuccess:()=>{i.invalidateQueries({queryKey:[[...G]]}),i.invalidateQueries({queryKey:W})}}),p=g(async t=>{await a({title:`Delete this archive?`,message:`Permanently deletes "${t.label??t.id}" and frees ${B(t.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&f.mutate({destinationId:e,backupId:t.id})},[a,e,f]),[m,h]=_(null),b=g(async t=>{h(t.id);try{let n=localStorage.getItem(`camstack_admin_token`),r={};n&&(r.Authorization=`Bearer ${n}`);let i=await fetch(q(e,t.id),{headers:r});if(!i.ok)throw Error(`download failed: ${i.status} ${i.statusText}`);let a=await i.blob(),o=URL.createObjectURL(a),s=document.createElement(`a`);s.href=o,s.download=`${t.label??t.id}.tar.gz`,document.body.appendChild(s),s.click(),s.remove(),URL.revokeObjectURL(o)}finally{h(null)}},[e]),x=y(()=>[...d].toSorted((e,t)=>t.createdAt-e.createdAt),[d]);return l?C(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):u?C(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):x.length===0?C(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):C(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:v(`table`,{className:`w-full text-xs min-w-[640px]`,children:[C(`thead`,{children:v(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),C(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),C(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),C(`tbody`,{children:x.map(r=>v(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[C(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:J(r.createdAt)}),C(`td`,{className:`px-3 py-1.5 text-foreground`,children:r.label??C(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),C(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:r.locations.join(`, `)}),C(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:B(r.sizeBytes)}),C(`td`,{className:`px-3 py-1.5`,children:v(`div`,{className:`flex items-center justify-end gap-1`,children:[v(`button`,{onClick:()=>{b(r)},disabled:m===r.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 disabled:opacity-50`,title:`Download archive`,children:[m===r.id?C(R,{className:`h-3 w-3 animate-spin`}):C(E,{className:`h-3 w-3`}),`Download`]}),t&&n&&v(`button`,{onClick:()=>n({destinationId:e,archiveId:r.id}),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10`,title:`Restore from this archive`,children:[C(M,{className:`h-3 w-3`}),`Restore`]}),C(`button`,{onClick:()=>{p(r)},disabled:f.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete archive`,children:f.isPending?C(R,{className:`h-3 w-3 animate-spin`}):C(L,{className:`h-3 w-3`})})]})})]},r.id))})]})})}function q(e,t){return`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function J(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}b();var Y=[{id:`manual`,label:`Manual only`,cron:``},{id:`hourly`,label:`Every hour`,cron:`0 * * * *`,description:`On the hour`},{id:`every-3h`,label:`Every 3 hours`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,label:`Every 6 hours`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,label:`Daily at 03:00`,cron:`0 3 * * *`,description:`Every night at 3 AM`},{id:`weekly-sun`,label:`Weekly Sunday 03:00`,cron:`0 3 * * 0`,description:`Sunday morning at 3 AM`}];function X(e){let t=e.trim();for(let e of Y)if(e.cron===t)return e.id;return`custom`}function Z({value:e,onChange:t,previewCount:n=5,disabled:r=!1}){let i=X(e),[a,o]=_(i===`custom`);w(()=>{i!==`custom`&&o(!1)},[i]);let s=ae(e,250),c=u({cron:s,count:n},{enabled:s.trim().length>0}),l=c.data??null,d=e=>{o(!1),t(e.cron)},f=a||i===`custom`;return v(`div`,{className:`space-y-3`,children:[v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),v(`div`,{className:`flex flex-wrap gap-1.5`,children:[Y.map(e=>C(`button`,{type:`button`,onClick:()=>d(e),disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!a&&i===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.description??e.label,children:e.label},e.id)),C(`button`,{type:`button`,onClick:()=>{o(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(f?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),f&&v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),C(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:r,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),v(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,C(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),C(re,{cron:s,preview:l,loading:c.isFetching})]})}function re({cron:e,preview:t,loading:n}){return n&&t===null?v(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[C(R,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?C(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:`No future runs match this expression.`}):v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),C(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>v(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[C(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),C(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:ie(e)})]},`${e}-${t}`))})]}):C(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??`Invalid cron expression`})}function ie(e){let t=e-Date.now();if(t<=0)return`now`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function ae(e,t){let[n,r]=_(e),i=y(()=>e,[e]);return w(()=>{let e=setTimeout(()=>r(i),t);return()=>clearTimeout(e)},[i,t]),n}b();var oe=[[`backup`,`listDestinations`]];function se({onCreateAt:e,onOpenRestoreWizard:t}){let{data:n,isLoading:r,isError:i}=d(),a=n??[],[o,s]=_(null),c=e=>{s(t=>t===e?null:e)},l=fe();return r?C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading destinations…`}):i?C(`div`,{className:`text-xs text-danger`,children:`Failed to load destinations`}):a.length===0?C(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:C(`p`,{className:`text-xs text-foreground-subtle`,children:"No `backups`-typed storage locations registered. Add one in Settings → Storage to begin."})}):C(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:v(`table`,{className:`w-full text-xs min-w-[720px]`,children:[C(`thead`,{children:v(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[C(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),C(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Destination`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-28`,children:`Retention`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-56`,children:`Schedule`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-44`,children:`Last success`}),C(`th`,{className:`text-right px-3 py-2 font-medium w-44`,children:`Actions`})]})}),C(`tbody`,{children:a.map(n=>{let r=l.get(n.id);return C(ce,{row:n,isOpen:o===n.id,onToggle:()=>c(n.id),onCreateAt:e,liveLastSuccessAt:r?.at,liveLastSuccessSizeBytes:r?.sizeBytes,...t?{onOpenRestoreWizard:t}:{}},n.id)})})]})})}function ce({row:e,isOpen:t,onToggle:n,onCreateAt:r,onOpenRestoreWizard:i,liveLastSuccessAt:a,liveLastSuccessSizeBytes:o}){let s=S(),l=c({onSuccess:()=>{s.invalidateQueries({queryKey:oe})}}),[u,d]=_(String(e.retentionCount));w(()=>{d(String(e.retentionCount))},[e.retentionCount]);let[f,p]=_(!1),m=g(t=>{l.mutate({locationId:e.id,enabled:t,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[l,e.id,e.retentionCount,e.label,e.cron]),h=g(()=>{let t=Number.parseInt(u,10);if(Number.isNaN(t)||t<1){d(String(e.retentionCount));return}t!==e.retentionCount&&l.mutate({locationId:e.id,enabled:e.enabled,retentionCount:t,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[l,u,e.id,e.enabled,e.retentionCount,e.label,e.cron]),y=g(t=>{l.mutate({locationId:e.id,enabled:e.enabled,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},cron:t},{onSuccess:()=>{p(!1)}})},[l,e.id,e.enabled,e.retentionCount,e.label]);return v(x,{children:[v(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[C(`td`,{className:`px-2 py-2`,children:C(`button`,{onClick:n,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:t?`Hide archives`:`Show archives`,children:C(t?F:P,{className:`h-3.5 w-3.5`})})}),C(`td`,{className:`px-3 py-2`,children:v(`button`,{onClick:n,className:`text-left hover:underline focus:outline-none`,title:`View archives`,children:[C(`div`,{className:`text-foreground font-medium`,children:e.displayName}),v(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[C(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5`,children:e.kind}),C(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]})}),C(`td`,{className:`px-3 py-2`,children:C(`label`,{className:`inline-flex items-center cursor-pointer`,children:C(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:l.isPending,onChange:e=>m(e.target.checked)})})}),C(`td`,{className:`px-3 py-2`,children:C(`input`,{type:`number`,min:1,max:1e3,value:u,disabled:l.isPending,onChange:e=>d(e.target.value),onBlur:h,onKeyDown:t=>{t.key===`Enter`&&t.target.blur(),t.key===`Escape`&&d(String(e.retentionCount))},className:`w-16 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})}),C(`td`,{className:`px-3 py-2`,children:C(le,{cron:e.cron,nextRunAt:e.nextRunAt,onEdit:()=>p(!0),disabled:l.isPending})}),C(`td`,{className:`px-3 py-2 text-foreground-subtle`,children:(()=>{let t=pe(a,e.lastSuccessAt),n=t===a?o:e.lastSuccessSizeBytes;return t===void 0?C(`span`,{className:`italic`,children:`Never`}):C(me,{at:t,sizeBytes:n})})()}),C(`td`,{className:`px-3 py-2`,children:C(`div`,{className:`flex items-center justify-end gap-1.5`,children:e.triggerSupported&&v(`button`,{onClick:()=>r(e),className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90`,children:[C(j,{className:`h-3 w-3`}),`Create here`]})})})]}),t&&C(`tr`,{className:`border-t border-border bg-background/30`,children:C(`td`,{colSpan:7,className:`px-4 py-3`,children:C(K,{destinationId:e.id,restoreSupported:e.restoreSupported,...i?{onOpenRestoreWizard:i}:{}})})}),f&&C(de,{destinationName:e.displayName,currentCron:e.cron??``,onSave:y,onClose:()=>p(!1),saving:l.isPending,saveError:l.error instanceof Error?l.error.message:null})]})}function le({cron:e,nextRunAt:t,onEdit:n,disabled:r}){let i=typeof e==`string`&&e.trim().length>0;return v(`button`,{type:`button`,onClick:n,disabled:r,className:`group flex flex-col items-start gap-0.5 text-left rounded px-1.5 py-1 -mx-1.5 hover:bg-primary/5 disabled:opacity-50`,title:`Edit schedule`,children:[v(`div`,{className:`flex items-center gap-1.5`,children:[C(ne,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),C(`span`,{className:i?`font-mono text-foreground`:`italic text-foreground-subtle`,children:i?e:`Manual`})]}),i&&t!==void 0&&v(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[`next `,ue(t)]})]})}function ue(e){let t=e-Date.now();if(t<=0)return`imminent`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function de({destinationName:e,currentCron:t,onSave:n,onClose:r,saving:i,saveError:a}){let[o,s]=_(t);return C(`tr`,{children:C(`td`,{colSpan:7,className:`p-0`,children:C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:v(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Schedule`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e]})]}),C(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,title:`Close`,children:C(I,{className:`h-4 w-4`})})]}),v(`div`,{className:`p-4`,children:[C(Z,{value:o,onChange:s,disabled:i}),a!==null&&C(`div`,{className:`mt-3 rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:a})]}),v(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[C(`button`,{onClick:r,disabled:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground disabled:opacity-50`,children:`Cancel`}),C(`button`,{onClick:()=>n(o.trim()),disabled:i||o.trim()===t.trim(),className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:i?`Saving…`:`Save`})]})]})})})})}function fe(){let{map:e}=t(T.BackupCompleted,e=>e.destinationId);return y(()=>{let t=new Map;for(let[n,r]of e)t.set(n,{at:Date.now(),sizeBytes:r.sizeMB*1024*1024});return t},[e])}function pe(e,t){return e===void 0?t:t===void 0||e>t?e:t}function me({at:e,sizeBytes:t}){let n=he(e);return v(`span`,{title:y(()=>new Date(e).toLocaleString(),[e]),className:`text-foreground tabular-nums`,children:[n,t!==void 0&&v(`span`,{className:`ml-1 text-foreground-subtle`,children:[`· `,B(t)]})]})}function he(e){let[,t]=_(0);return w(()=>{let e=setInterval(()=>t(e=>e+1),3e4);return()=>clearInterval(e)},[]),ge(e)}function ge(e){let t=Math.max(0,Date.now()-e),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(a/365)}y ago`}b();var _e=[[`backup`,`list`]];function ve({initialDestinationId:e,initialArchiveId:t,onClose:r,onScheduled:a}){let s=S(),[c,l]=_(e&&t?2:1),[u,f]=_(e),[p,m]=_(t),[h,g]=_(new Set),{data:b}=d(),x=b??[],{data:T,isLoading:E}=o({destinationId:u??``},{enabled:!!u}),D=T??[];w(()=>{if(u!==void 0)return;let e=x.filter(e=>e.restoreSupported);e.length===1&&f(e[0].id)},[u,x]);let{data:O}=n({destinationId:u??``,backupId:p??``},{enabled:!!u&&!!p}),k=y(()=>O?.locations??[],[O]);w(()=>{k.length!==0&&g(e=>e.size===0?new Set(k):e)},[k]);let A=i({onSuccess:()=>{s.invalidateQueries({queryKey:_e}),a(),r()}}),j=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},N=!!u&&!!p,P=h.size>0,F=N&&P&&!A.isPending,L=()=>{!u||!p||A.mutate({destinationId:u,backupId:p,locations:[...h]})};return C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:v(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,c,` of 3 —`,` `,c===1?`pick source`:c===2?`pick locations`:`confirm`]})]}),C(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:C(I,{className:`h-4 w-4`})})]}),c===1&&C(ye,{destinations:x,destinationId:u,onPickDestination:e=>{f(e),m(void 0),g(new Set)},archives:D,archivesLoading:E,archiveId:p,onPickArchive:m}),c===2&&C(be,{locations:k,picked:h,onToggle:j}),c===3&&C(xe,{destinationName:x.find(e=>e.id===u)?.displayName??u??``,archive:D.find(e=>e.id===p),picked:[...h]}),v(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[C(`div`,{children:c>1&&v(`button`,{onClick:()=>l(e=>e===3?2:1),className:`inline-flex items-center gap-1 rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:[C(ee,{className:`h-3 w-3`}),`Back`]})}),v(`div`,{className:`flex items-center gap-2`,children:[C(`button`,{onClick:r,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),c<3?v(`button`,{disabled:c===1&&!N||c===2&&!P,onClick:()=>l(e=>e===1?2:3),className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[`Next`,C(te,{className:`h-3 w-3`})]}):v(`button`,{onClick:L,disabled:!F,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[A.isPending?C(R,{className:`h-3.5 w-3.5 animate-spin`}):C(M,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function ye({destinations:e,destinationId:t,onPickDestination:n,archives:r,archivesLoading:i,archiveId:a,onPickArchive:o}){let s=e.filter(e=>e.restoreSupported);return v(`div`,{className:`p-4 space-y-3`,children:[v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),v(`select`,{value:t??``,onChange:e=>n(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[C(`option`,{value:``,disabled:!0,children:`Select destination…`}),s.map(e=>v(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&C(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&i&&C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!i&&r.length===0&&C(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&r.length>0&&C(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:r.map(e=>{let t=a===e.id;return v(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>o(e.id),className:`accent-primary`}),v(`div`,{children:[C(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),C(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),C(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:B(e.sizeBytes)})]},e.id)})})]})]})}function be({locations:e,picked:t,onToggle:n}){return e.length===0?C(`div`,{className:`p-4`,children:C(`div`,{className:`text-xs text-foreground-subtle`,children:`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`})}):v(`div`,{className:`p-4 space-y-3`,children:[C(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),C(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>v(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[C(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),C(`span`,{className:`font-mono text-foreground`,children:e}),C(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ce(e)})]},e))})]})]})}function xe({destinationName:e,archive:t,picked:n}){return v(`div`,{className:`p-4 space-y-3 text-xs`,children:[C(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300`,children:`Restore is applied at next server boot. Active connections will drop when you restart.`}),v(`dl`,{className:`space-y-1.5`,children:[C(Q,{term:`Destination`,value:e}),C(Q,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&C(Q,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${B(t.sizeBytes)}`}),C(Q,{term:`Locations`,value:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function Q({term:e,value:t}){return v(`div`,{className:`flex justify-between gap-3`,children:[C(`dt`,{className:`text-foreground-subtle`,children:e}),C(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Se={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function Ce(e){return Se[e]??``}b();var $=[[`backup`,`list`]],we=[[`backup`,`listLocations`]];function Te(){let t=S(),n=s(),{data:r}=e(),i=a({onSuccess:()=>{t.invalidateQueries({queryKey:$}),t.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),t.invalidateQueries({queryKey:[[`backup`,`listArchives`]]})}}),o=h(),[c,l]=_(null),[u,d]=_(null),[f,p]=_(!1),[m,g]=_(!1),[y,b]=_(!1),x=async()=>{await n({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&o.mutate({confirm:!0})};return v(z,{children:[v(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[v(`button`,{onClick:()=>p(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[C(M,{className:`h-3.5 w-3.5`}),`Restore…`]}),v(`button`,{onClick:()=>b(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[C(j,{className:`h-3.5 w-3.5`}),`Add destination`]})]}),m&&C(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2.5 text-xs text-amber-700 dark:text-amber-300`,children:v(`div`,{className:`flex items-center justify-between gap-3`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(M,{className:`h-3.5 w-3.5`}),C(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),v(`button`,{onClick:()=>{x()},disabled:o.isPending,className:`inline-flex items-center gap-1.5 rounded bg-amber-500/20 px-2 py-1 font-medium text-amber-800 dark:text-amber-200 hover:bg-amber-500/30 disabled:opacity-50`,children:[o.isPending?C(R,{className:`h-3.5 w-3.5 animate-spin`}):C(M,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),C(se,{onCreateAt:e=>l(e),onOpenRestoreWizard:e=>d(e)}),c&&C(Ee,{destination:c,locations:r??[],onClose:()=>l(null),onSubmit:(e,n)=>{i.mutate({destinations:[c.id],locations:e,label:n||void 0},{onSuccess:()=>{l(null),t.invalidateQueries({queryKey:we})}})},submitting:i.isPending}),(u||f)&&C(ve,{...u?{initialDestinationId:u.destinationId,initialArchiveId:u.archiveId}:{},onClose:()=>{d(null),p(!1)},onScheduled:()=>g(!0)}),y&&C(A,{initialType:`backups`,onClose:()=>b(!1),onCreated:()=>{b(!1),t.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]})}})]})}function Ee({destination:e,locations:t,onClose:n,onSubmit:r,submitting:i}){let a=t.filter(e=>e.present),[o,s]=_(``),[c,l]=_(()=>new Set(a.map(e=>e.name))),u=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:v(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Create Backup`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e.displayName]})]}),C(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:C(I,{className:`h-4 w-4`})})]}),v(`div`,{className:`p-4 space-y-3`,children:[v(`div`,{className:`space-y-1`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Label (optional)`}),C(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`pre-upgrade`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Include`}),v(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:[a.length===0&&C(`div`,{className:`px-3 py-2 text-xs text-foreground-subtle italic`,children:`Nothing to back up.`}),a.map(e=>v(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(`input`,{type:`checkbox`,checked:c.has(e.name),onChange:()=>u(e.name),className:`accent-primary`}),C(`span`,{className:`font-mono text-foreground`,children:e.name})]}),v(`div`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[B(e.sizeBytes),` · `,e.fileCount,` files`]})]},e.name))]})]})]}),v(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[C(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),v(`button`,{onClick:()=>r(Array.from(c),o.trim()),disabled:i||c.size===0,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[i?C(R,{className:`h-3.5 w-3.5 animate-spin`}):C(H,{className:`h-3.5 w-3.5`}),i?`Creating…`:`Create`]})]})]})})}function De(){return C(`div`,{className:`flex flex-col p-4`,children:C(V,{tabs:[{id:`storage`,label:`Storage`,icon:D,content:C(U,{})},{id:`backup`,label:`Backup`,icon:H,content:C(Te,{})}]})})}export{De as DataPage};
@@ -1 +1 @@
1
- import{An as e,Cn as t,Dn as n,En as r,Mn as i,Nn as a,On as o,Pn as s,Tn as c,aa as l,ca as u,fa as d,ia as f,jn as p,kn as m,oa as h,pa as g,ra as _,sa as v,ua as y,wn as b}from"./src-FrhjLfXG.js";import{K as x,S,W as C,Z as w,b as T,o as E,x as D}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{t as O}from"./pencil-Bhm5xitE.js";import{t as k}from"./plus-CkYGohZo.js";import{t as A}from"./sparkles-DjKBLEHs.js";import{t as j}from"./square-check-big-dQtGbsrJ.js";import{t as M}from"./square-k19zsBE3.js";import{B as N,F as P,M as F,P as I,i as L,m as R,s as z,x as B}from"./index-CmHNa_oF.js";import{t as V}from"./AdminPage-vtcsGqRq.js";var H=N(`user-check`,[[`path`,{d:`m16 11 2 2 4-4`,key:`9rsbq5`}],[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),U=N(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]),W=N(`user-x`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`17`,x2:`22`,y1:`8`,y2:`13`,key:`3nzzx3`}],[`line`,{x1:`22`,x2:`17`,y1:`8`,y2:`13`,key:`1swrse`}]]);w();var G=[[`faceGallery`]];function K({identityId:t}){let n=E(),{data:r,isLoading:i}=o({identityId:t}),a=e();function s(e){a.mutate({identityId:t,sampleId:e.id},{onSettled:()=>{n.invalidateQueries({queryKey:G})}})}return i?S(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[D(B,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!r||r.length===0?D(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):D(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:r.map(e=>S(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?D(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):D(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:D(U,{className:`h-6 w-6`})}),D(`button`,{type:`button`,onClick:()=>s(e),disabled:a.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove sample`,children:D(L,{className:`h-4 w-4 text-white`})})]},e.id))})}function q({identity:e,expanded:t,onToggle:n}){let i=E(),[a,o]=x(``),[s,c]=x(!1),[m,b]=x(!1),C=p(),w=r();function k(){o(e.name),c(!0)}function A(){c(!1),o(``)}function j(){let t=a.trim();if(!t||t===e.name){A();return}C.mutate({id:e.id,name:t},{onSettled:()=>{i.invalidateQueries({queryKey:G}),A()}})}function M(){w.mutate({id:e.id},{onSettled:()=>{i.invalidateQueries({queryKey:G}),b(!1)}})}return S(`div`,{className:`rounded-md border border-border bg-surface`,children:[S(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[D(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:e.coverBase64?D(`img`,{src:`data:image/jpeg;base64,${e.coverBase64}`,alt:e.name,className:`h-full w-full object-cover`}):D(`div`,{className:`flex h-full w-full items-center justify-center`,children:D(U,{className:`h-4 w-4 text-foreground-subtle`})})}),D(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:s?S(T,{children:[D(y,{value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j(),e.key===`Escape`&&A()},className:`h-6 text-xs`,autoFocus:!0}),D(`button`,{type:`button`,onClick:j,disabled:C.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:D(P,{className:`h-3.5 w-3.5`})}),D(`button`,{type:`button`,onClick:A,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:D(L,{className:`h-3.5 w-3.5`})})]}):D(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),D(d,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!s&&S(`div`,{className:`flex items-center gap-1`,children:[D(`button`,{type:`button`,onClick:k,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:D(O,{className:`h-3.5 w-3.5`})}),D(`button`,{type:`button`,onClick:()=>b(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:D(z,{className:`h-3.5 w-3.5`})})]}),D(`button`,{type:`button`,onClick:n,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:D(t?I:F,{className:`h-3.5 w-3.5`})})]}),t&&D(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:D(K,{identityId:e.id})}),D(_,{open:m,onOpenChange:e=>!e&&b(!1),children:S(f,{children:[S(v,{children:[D(u,{children:`Delete person`}),S(l,{children:[`Delete `,D(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),S(h,{children:[D(g,{variant:`secondary`,onClick:()=>b(!1),children:`Cancel`}),S(g,{variant:`danger`,onClick:M,disabled:w.isPending,children:[w.isPending?D(B,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function J(){let e=E(),[t,n]=x(``),r=b();function i(){let i=t.trim();i&&r.mutate({name:i},{onSettled:()=>{e.invalidateQueries({queryKey:G}),n(``)}})}return S(`div`,{className:`flex items-center gap-2 pt-2`,children:[D(y,{placeholder:`New person name…`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&i()},className:`h-7 text-xs flex-1`}),S(g,{variant:`primary`,size:`sm`,onClick:i,disabled:r.isPending||!t.trim(),children:[r.isPending?D(B,{className:`h-3.5 w-3.5 animate-spin`}):D(k,{className:`h-3.5 w-3.5`}),`Add`]})]})}function Y(){let{data:e,isLoading:t}=n(),[r,i]=x(null);function a(e){i(t=>t===e?null:e)}return t?S(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[D(B,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):S(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&D(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>D(q,{identity:e,expanded:r===e.id,onToggle:()=>a(e.id)},e.id)),D(J,{})]})}w();var X=[[`faceGallery`]];function Z({faceIds:e,identities:n,onDone:r}){let i=E(),a=t(),o=b(),[s,c]=x(``),[d,p]=x(!1),[m,C]=x(null),w=e!==null&&e.length>0,T=e?.length??0;function O(){p(!1),c(``),C(null)}function k(){O(),r()}function A(t){!e||e.length===0||a.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{i.invalidateQueries({queryKey:X}),k()}})}function j(){!e||!s.trim()||o.mutate({name:s.trim()},{onSuccess:e=>{e?.id&&A(e.id)},onError:()=>{i.invalidateQueries({queryKey:X}),k()}})}let M=a.isPending||o.isPending;return D(_,{open:w,onOpenChange:e=>!e&&k(),children:S(f,{children:[S(v,{children:[D(u,{children:T>1?`Assign ${T} faces to person`:`Assign face to person`}),D(l,{children:`Select an existing person or create a new one.`})]}),D(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:n.map(e=>S(`button`,{type:`button`,onClick:()=>C(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${m===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[D(`span`,{className:`font-medium`,children:e.name}),S(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),d?D(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:D(y,{placeholder:`New person name…`,value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j()},autoFocus:!0,className:`flex-1`})}):D(`button`,{type:`button`,onClick:()=>{C(null),p(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:`+ New person…`}),S(h,{children:[D(g,{variant:`secondary`,onClick:k,disabled:M,children:`Cancel`}),d?S(g,{variant:`primary`,onClick:j,disabled:M||!s.trim(),children:[M&&D(B,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):S(g,{variant:`primary`,onClick:()=>m&&A(m),disabled:M||!m,children:[M&&D(B,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,T>1?` ${T}`:``]})]})]})})}function Q({face:e,selected:t,onToggleSelect:n,onAssign:r}){let i=E(),o=a(),s=c(),l=()=>{i.invalidateQueries({queryKey:X})};return S(`div`,{className:`group relative flex flex-col gap-1 rounded-md border bg-surface overflow-hidden ${t?`border-primary ring-1 ring-primary`:`border-border`}`,children:[S(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?D(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face`,className:`h-full w-full object-cover`}):D(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:D(U,{className:`h-8 w-8`})}),D(`button`,{type:`button`,onClick:()=>n(e.faceId),className:`absolute left-1 top-1 rounded bg-black/40 p-0.5 text-white hover:bg-black/60`,"aria-label":t?`Deselect`:`Select`,children:t?D(j,{className:`h-3.5 w-3.5 text-primary`}):D(M,{className:`h-3.5 w-3.5`})}),S(`div`,{className:`absolute inset-0 flex items-center justify-center gap-2 bg-black/50 opacity-0 transition-opacity group-hover:opacity-100`,children:[e.assigned?D(`button`,{type:`button`,onClick:()=>o.mutate({faceId:e.faceId},{onSettled:l}),disabled:o.isPending,className:`rounded-full bg-warning/80 p-1.5 text-white hover:bg-warning disabled:opacity-50`,title:`Detach`,children:o.isPending?D(B,{className:`h-3.5 w-3.5 animate-spin`}):D(W,{className:`h-3.5 w-3.5`})}):D(`button`,{type:`button`,onClick:()=>r(e.faceId),className:`rounded-full bg-primary/80 p-1.5 text-white hover:bg-primary`,title:`Assign to person`,children:D(H,{className:`h-3.5 w-3.5`})}),D(`button`,{type:`button`,onClick:()=>s.mutate({faceId:e.faceId},{onSettled:l}),disabled:s.isPending,className:`rounded-full bg-danger/80 p-1.5 text-white hover:bg-danger disabled:opacity-50`,title:`Delete face`,children:s.isPending?D(B,{className:`h-3.5 w-3.5 animate-spin`}):D(z,{className:`h-3.5 w-3.5`})})]})]}),S(`div`,{className:`px-2 pb-2 space-y-0.5`,children:[D(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.deviceId}),e.identityName&&D(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]})]})}var $=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function ee(){let e=E(),[r,a]=x(`all`),[o,l]=x(new Set),[u,d]=x(null),[f,p]=x(!1),{data:h,isLoading:_}=m({limit:100,filter:r}),{data:v=[]}=n(),{data:y,isFetching:b}=i({threshold:.5,minClusterSize:2,limit:20},{enabled:f}),w=t(),T=s(),O=c(),k=h??[],j=C(()=>new Map(k.map(e=>[e.faceId,e])),[k]),M=()=>{e.invalidateQueries({queryKey:X})},N=()=>l(new Set);function P(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function F(e){l(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}let I=[...o],R=w.isPending||T.isPending||O.isPending;function V(){I.length!==0&&T.mutate({faceIds:I},{onSettled:()=>{M(),N()}})}function G(){I.length!==0&&Promise.allSettled(I.map(e=>O.mutateAsync({faceId:e}))).then(()=>{M(),N()})}return S(`div`,{className:`space-y-3`,children:[S(`div`,{className:`flex items-center gap-1`,children:[$.map(e=>D(`button`,{type:`button`,onClick:()=>a(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${r===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value)),S(`button`,{type:`button`,onClick:()=>p(e=>!e),className:`ml-2 flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${f?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[D(A,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!_&&S(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[k.length,` face`,k.length===1?``:`s`]})]}),o.size>0&&S(`div`,{className:`flex items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[S(`span`,{className:`text-xs font-medium text-foreground`,children:[o.size,` selected`]}),S(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[S(g,{variant:`primary`,onClick:()=>d(I),disabled:R,children:[D(H,{className:`h-3.5 w-3.5`}),` Assign`]}),S(g,{variant:`secondary`,onClick:V,disabled:R,children:[T.isPending?D(B,{className:`h-3.5 w-3.5 animate-spin`}):D(W,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),S(g,{variant:`secondary`,onClick:G,disabled:R,children:[D(z,{className:`h-3.5 w-3.5`}),` Delete`]}),D(g,{variant:`ghost`,onClick:N,disabled:R,children:D(L,{className:`h-3.5 w-3.5`})})]})]}),f&&S(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:[D(`p`,{className:`mb-2 text-xs font-medium text-foreground`,children:`Look-alike groups`}),b?S(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[D(B,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):!y||y.length===0?D(`p`,{className:`text-xs text-foreground-subtle`,children:`No look-alike groups found among unassigned faces.`}):D(`div`,{className:`space-y-2`,children:y.map(e=>S(`div`,{className:`flex items-center gap-2 rounded-md bg-surface-hover/50 p-2`,children:[D(`div`,{className:`flex -space-x-1.5`,children:e.faceIds.slice(0,6).map(e=>{let t=j.get(e);return D(`div`,{className:`h-8 w-8 overflow-hidden rounded border border-border bg-surface`,children:t?.base64?D(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:``,className:`h-full w-full object-cover`}):D(U,{className:`h-full w-full p-1.5 text-foreground-subtle`})},e)})}),S(`span`,{className:`text-xs text-foreground-subtle`,children:[e.size,` faces · `,Math.round(e.cohesion*100),`% alike`]}),S(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[D(g,{variant:`secondary`,onClick:()=>F(e.faceIds),children:`Select group`}),S(g,{variant:`primary`,onClick:()=>d(e.faceIds),children:[D(H,{className:`h-3.5 w-3.5`}),` Assign all`]})]})]},e.representativeFaceId))})]}),_&&S(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[D(B,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!_&&k.length===0&&D(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No faces found for this filter.`}),!_&&k.length>0&&D(`div`,{className:`grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8 lg:grid-cols-10`,children:k.map(e=>D(Q,{face:e,selected:o.has(e.faceId),onToggleSelect:P,onAssign:e=>d([e])},e.faceId))}),D(Z,{faceIds:u,identities:v,onDone:()=>{d(null),N()}})]})}function te(){return D(V,{icon:R,title:`Detection Intelligence`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:S(`section`,{className:`space-y-3`,children:[S(`div`,{children:[D(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),D(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled identities used for face recognition. Expand a row to view or remove training samples.`}),D(Y,{})]}),S(`div`,{className:`pt-4 border-t border-border`,children:[D(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),D(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`}),D(ee,{})]})]})})}export{te as DetectionIntelligencePage};
1
+ import{An as e,Cn as t,Dn as n,En as r,Mn as i,Nn as a,On as o,Pn as s,Tn as c,aa as l,ca as u,fa as d,ia as f,jn as p,kn as m,oa as h,pa as g,ra as _,sa as v,ua as y,wn as b}from"./src-OU6ujZuo.js";import{K as x,S,W as C,Z as w,b as T,o as E,x as D}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{t as O}from"./pencil-DK4zkTC6.js";import{t as k}from"./plus-BhEoEvZK.js";import{t as A}from"./sparkles-DJtFF7Iu.js";import{t as j}from"./square-check-big-DNbPWX7Q.js";import{t as M}from"./square-xoGtHzHQ.js";import{B as N,F as P,M as F,P as I,i as L,m as R,s as z,x as B}from"./index-BW7XX5wA.js";import{t as V}from"./AdminPage-vtcsGqRq.js";var H=N(`user-check`,[[`path`,{d:`m16 11 2 2 4-4`,key:`9rsbq5`}],[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),U=N(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]),W=N(`user-x`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`17`,x2:`22`,y1:`8`,y2:`13`,key:`3nzzx3`}],[`line`,{x1:`22`,x2:`17`,y1:`8`,y2:`13`,key:`1swrse`}]]);w();var G=[[`faceGallery`]];function K({identityId:t}){let n=E(),{data:r,isLoading:i}=o({identityId:t}),a=e();function s(e){a.mutate({identityId:t,sampleId:e.id},{onSettled:()=>{n.invalidateQueries({queryKey:G})}})}return i?S(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[D(B,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!r||r.length===0?D(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):D(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:r.map(e=>S(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?D(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):D(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:D(U,{className:`h-6 w-6`})}),D(`button`,{type:`button`,onClick:()=>s(e),disabled:a.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove sample`,children:D(L,{className:`h-4 w-4 text-white`})})]},e.id))})}function q({identity:e,expanded:t,onToggle:n}){let i=E(),[a,o]=x(``),[s,c]=x(!1),[m,b]=x(!1),C=p(),w=r();function k(){o(e.name),c(!0)}function A(){c(!1),o(``)}function j(){let t=a.trim();if(!t||t===e.name){A();return}C.mutate({id:e.id,name:t},{onSettled:()=>{i.invalidateQueries({queryKey:G}),A()}})}function M(){w.mutate({id:e.id},{onSettled:()=>{i.invalidateQueries({queryKey:G}),b(!1)}})}return S(`div`,{className:`rounded-md border border-border bg-surface`,children:[S(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[D(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:e.coverBase64?D(`img`,{src:`data:image/jpeg;base64,${e.coverBase64}`,alt:e.name,className:`h-full w-full object-cover`}):D(`div`,{className:`flex h-full w-full items-center justify-center`,children:D(U,{className:`h-4 w-4 text-foreground-subtle`})})}),D(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:s?S(T,{children:[D(y,{value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j(),e.key===`Escape`&&A()},className:`h-6 text-xs`,autoFocus:!0}),D(`button`,{type:`button`,onClick:j,disabled:C.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:D(P,{className:`h-3.5 w-3.5`})}),D(`button`,{type:`button`,onClick:A,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:D(L,{className:`h-3.5 w-3.5`})})]}):D(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),D(d,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!s&&S(`div`,{className:`flex items-center gap-1`,children:[D(`button`,{type:`button`,onClick:k,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:D(O,{className:`h-3.5 w-3.5`})}),D(`button`,{type:`button`,onClick:()=>b(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:D(z,{className:`h-3.5 w-3.5`})})]}),D(`button`,{type:`button`,onClick:n,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:D(t?I:F,{className:`h-3.5 w-3.5`})})]}),t&&D(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:D(K,{identityId:e.id})}),D(_,{open:m,onOpenChange:e=>!e&&b(!1),children:S(f,{children:[S(v,{children:[D(u,{children:`Delete person`}),S(l,{children:[`Delete `,D(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),S(h,{children:[D(g,{variant:`secondary`,onClick:()=>b(!1),children:`Cancel`}),S(g,{variant:`danger`,onClick:M,disabled:w.isPending,children:[w.isPending?D(B,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function J(){let e=E(),[t,n]=x(``),r=b();function i(){let i=t.trim();i&&r.mutate({name:i},{onSettled:()=>{e.invalidateQueries({queryKey:G}),n(``)}})}return S(`div`,{className:`flex items-center gap-2 pt-2`,children:[D(y,{placeholder:`New person name…`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&i()},className:`h-7 text-xs flex-1`}),S(g,{variant:`primary`,size:`sm`,onClick:i,disabled:r.isPending||!t.trim(),children:[r.isPending?D(B,{className:`h-3.5 w-3.5 animate-spin`}):D(k,{className:`h-3.5 w-3.5`}),`Add`]})]})}function Y(){let{data:e,isLoading:t}=n(),[r,i]=x(null);function a(e){i(t=>t===e?null:e)}return t?S(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[D(B,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):S(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&D(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>D(q,{identity:e,expanded:r===e.id,onToggle:()=>a(e.id)},e.id)),D(J,{})]})}w();var X=[[`faceGallery`]];function Z({faceIds:e,identities:n,onDone:r}){let i=E(),a=t(),o=b(),[s,c]=x(``),[d,p]=x(!1),[m,C]=x(null),w=e!==null&&e.length>0,T=e?.length??0;function O(){p(!1),c(``),C(null)}function k(){O(),r()}function A(t){!e||e.length===0||a.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{i.invalidateQueries({queryKey:X}),k()}})}function j(){!e||!s.trim()||o.mutate({name:s.trim()},{onSuccess:e=>{e?.id&&A(e.id)},onError:()=>{i.invalidateQueries({queryKey:X}),k()}})}let M=a.isPending||o.isPending;return D(_,{open:w,onOpenChange:e=>!e&&k(),children:S(f,{children:[S(v,{children:[D(u,{children:T>1?`Assign ${T} faces to person`:`Assign face to person`}),D(l,{children:`Select an existing person or create a new one.`})]}),D(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:n.map(e=>S(`button`,{type:`button`,onClick:()=>C(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${m===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[D(`span`,{className:`font-medium`,children:e.name}),S(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),d?D(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:D(y,{placeholder:`New person name…`,value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j()},autoFocus:!0,className:`flex-1`})}):D(`button`,{type:`button`,onClick:()=>{C(null),p(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:`+ New person…`}),S(h,{children:[D(g,{variant:`secondary`,onClick:k,disabled:M,children:`Cancel`}),d?S(g,{variant:`primary`,onClick:j,disabled:M||!s.trim(),children:[M&&D(B,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):S(g,{variant:`primary`,onClick:()=>m&&A(m),disabled:M||!m,children:[M&&D(B,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,T>1?` ${T}`:``]})]})]})})}function Q({face:e,selected:t,onToggleSelect:n,onAssign:r}){let i=E(),o=a(),s=c(),l=()=>{i.invalidateQueries({queryKey:X})};return S(`div`,{className:`group relative flex flex-col gap-1 rounded-md border bg-surface overflow-hidden ${t?`border-primary ring-1 ring-primary`:`border-border`}`,children:[S(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?D(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face`,className:`h-full w-full object-cover`}):D(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:D(U,{className:`h-8 w-8`})}),D(`button`,{type:`button`,onClick:()=>n(e.faceId),className:`absolute left-1 top-1 rounded bg-black/40 p-0.5 text-white hover:bg-black/60`,"aria-label":t?`Deselect`:`Select`,children:t?D(j,{className:`h-3.5 w-3.5 text-primary`}):D(M,{className:`h-3.5 w-3.5`})}),S(`div`,{className:`absolute inset-0 flex items-center justify-center gap-2 bg-black/50 opacity-0 transition-opacity group-hover:opacity-100`,children:[e.assigned?D(`button`,{type:`button`,onClick:()=>o.mutate({faceId:e.faceId},{onSettled:l}),disabled:o.isPending,className:`rounded-full bg-warning/80 p-1.5 text-white hover:bg-warning disabled:opacity-50`,title:`Detach`,children:o.isPending?D(B,{className:`h-3.5 w-3.5 animate-spin`}):D(W,{className:`h-3.5 w-3.5`})}):D(`button`,{type:`button`,onClick:()=>r(e.faceId),className:`rounded-full bg-primary/80 p-1.5 text-white hover:bg-primary`,title:`Assign to person`,children:D(H,{className:`h-3.5 w-3.5`})}),D(`button`,{type:`button`,onClick:()=>s.mutate({faceId:e.faceId},{onSettled:l}),disabled:s.isPending,className:`rounded-full bg-danger/80 p-1.5 text-white hover:bg-danger disabled:opacity-50`,title:`Delete face`,children:s.isPending?D(B,{className:`h-3.5 w-3.5 animate-spin`}):D(z,{className:`h-3.5 w-3.5`})})]})]}),S(`div`,{className:`px-2 pb-2 space-y-0.5`,children:[D(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.deviceId}),e.identityName&&D(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]})]})}var $=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function ee(){let e=E(),[r,a]=x(`all`),[o,l]=x(new Set),[u,d]=x(null),[f,p]=x(!1),{data:h,isLoading:_}=m({limit:100,filter:r}),{data:v=[]}=n(),{data:y,isFetching:b}=i({threshold:.5,minClusterSize:2,limit:20},{enabled:f}),w=t(),T=s(),O=c(),k=h??[],j=C(()=>new Map(k.map(e=>[e.faceId,e])),[k]),M=()=>{e.invalidateQueries({queryKey:X})},N=()=>l(new Set);function P(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function F(e){l(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}let I=[...o],R=w.isPending||T.isPending||O.isPending;function V(){I.length!==0&&T.mutate({faceIds:I},{onSettled:()=>{M(),N()}})}function G(){I.length!==0&&Promise.allSettled(I.map(e=>O.mutateAsync({faceId:e}))).then(()=>{M(),N()})}return S(`div`,{className:`space-y-3`,children:[S(`div`,{className:`flex items-center gap-1`,children:[$.map(e=>D(`button`,{type:`button`,onClick:()=>a(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${r===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value)),S(`button`,{type:`button`,onClick:()=>p(e=>!e),className:`ml-2 flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${f?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[D(A,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!_&&S(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[k.length,` face`,k.length===1?``:`s`]})]}),o.size>0&&S(`div`,{className:`flex items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[S(`span`,{className:`text-xs font-medium text-foreground`,children:[o.size,` selected`]}),S(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[S(g,{variant:`primary`,onClick:()=>d(I),disabled:R,children:[D(H,{className:`h-3.5 w-3.5`}),` Assign`]}),S(g,{variant:`secondary`,onClick:V,disabled:R,children:[T.isPending?D(B,{className:`h-3.5 w-3.5 animate-spin`}):D(W,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),S(g,{variant:`secondary`,onClick:G,disabled:R,children:[D(z,{className:`h-3.5 w-3.5`}),` Delete`]}),D(g,{variant:`ghost`,onClick:N,disabled:R,children:D(L,{className:`h-3.5 w-3.5`})})]})]}),f&&S(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:[D(`p`,{className:`mb-2 text-xs font-medium text-foreground`,children:`Look-alike groups`}),b?S(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[D(B,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):!y||y.length===0?D(`p`,{className:`text-xs text-foreground-subtle`,children:`No look-alike groups found among unassigned faces.`}):D(`div`,{className:`space-y-2`,children:y.map(e=>S(`div`,{className:`flex items-center gap-2 rounded-md bg-surface-hover/50 p-2`,children:[D(`div`,{className:`flex -space-x-1.5`,children:e.faceIds.slice(0,6).map(e=>{let t=j.get(e);return D(`div`,{className:`h-8 w-8 overflow-hidden rounded border border-border bg-surface`,children:t?.base64?D(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:``,className:`h-full w-full object-cover`}):D(U,{className:`h-full w-full p-1.5 text-foreground-subtle`})},e)})}),S(`span`,{className:`text-xs text-foreground-subtle`,children:[e.size,` faces · `,Math.round(e.cohesion*100),`% alike`]}),S(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[D(g,{variant:`secondary`,onClick:()=>F(e.faceIds),children:`Select group`}),S(g,{variant:`primary`,onClick:()=>d(e.faceIds),children:[D(H,{className:`h-3.5 w-3.5`}),` Assign all`]})]})]},e.representativeFaceId))})]}),_&&S(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[D(B,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!_&&k.length===0&&D(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No faces found for this filter.`}),!_&&k.length>0&&D(`div`,{className:`grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8 lg:grid-cols-10`,children:k.map(e=>D(Q,{face:e,selected:o.has(e.faceId),onToggleSelect:P,onAssign:e=>d([e])},e.faceId))}),D(Z,{faceIds:u,identities:v,onDone:()=>{d(null),N()}})]})}function te(){return D(V,{icon:R,title:`Detection Intelligence`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:S(`section`,{className:`space-y-3`,children:[S(`div`,{children:[D(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),D(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled identities used for face recognition. Expand a row to view or remove training samples.`}),D(Y,{})]}),S(`div`,{className:`pt-4 border-t border-border`,children:[D(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),D(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`}),D(ee,{})]})]})})}export{te as DetectionIntelligencePage};