@camstack/addon-admin-ui 1.2.11 → 1.2.12

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 (93) hide show
  1. package/dist/assets/{AddLocationWizard-lNJZEC5r.js → AddLocationWizard-C6UBIuTS.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-CmX8_tau.js → AddonCollectionPage-DxnZh-wM.js} +1 -1
  3. package/dist/assets/{Addons-CCkQBp0x.js → Addons-Dn0jxzQ7.js} +1 -1
  4. package/dist/assets/AdminPage-Dq33XE9j.js +1 -0
  5. package/dist/assets/AdminTabs-CeRplgux.js +1 -0
  6. package/dist/assets/{AiProfiles-D0Xb7IZR.js → AiProfiles-vFylxSBU.js} +1 -1
  7. package/dist/assets/{BrokerForm-DUo01U9W.js → BrokerForm-DhANF6Wd.js} +1 -1
  8. package/dist/assets/{Capabilities-CDNLc6Cy.js → Capabilities-CMV01ZVD.js} +1 -1
  9. package/dist/assets/{CapabilityBadges-CFXH3e_K.js → CapabilityBadges-DqFfBMW6.js} +1 -1
  10. package/dist/assets/{Cluster-C9Mo5XOG.js → Cluster-DSOvI81b.js} +1 -1
  11. package/dist/assets/{ClusterRecordingTab-BrTzRejO.js → ClusterRecordingTab-mup7LvHp.js} +1 -1
  12. package/dist/assets/{Dashboard-uC8ffATh.js → Dashboard-DuRdTnRQ.js} +1 -1
  13. package/dist/assets/Data-DdP-f-0d.js +1 -0
  14. package/dist/assets/{DetectionIntelligence-dP3iSihl.js → DetectionIntelligence-DTHmzxch.js} +1 -1
  15. package/dist/assets/DeviceDetail-DjhD0mmA.js +2 -0
  16. package/dist/assets/{Devices-CxfIJAOH.js → Devices-BBpYNQ1S.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-C5cjRT3R.js → EmbedPlayerPage-B70EA1V7.js} +1 -1
  18. package/dist/assets/Events-BKm8l7EL.js +1 -0
  19. package/dist/assets/{FormBuilder-D1QARnB7.js → FormBuilder-BO4hp-td.js} +1 -1
  20. package/dist/assets/{Identity-Gvc5rieL.js → Identity-COkB1mNz.js} +1 -1
  21. package/dist/assets/{IntegrationDetail-DCZxO17-.js → IntegrationDetail-DISQP0-J.js} +1 -1
  22. package/dist/assets/{Integrations-tU1rRoAC.js → Integrations-CT-TwpYe.js} +1 -1
  23. package/dist/assets/{Integrations-2NKcIygs.js → Integrations-xL8Sw-B2.js} +1 -1
  24. package/dist/assets/{Logs-BYdTwtAG.js → Logs-iF5yw4kk.js} +1 -1
  25. package/dist/assets/{MotionZonesSettings-WsP8vtl5.js → MotionZonesSettings-DbtzjXBB.js} +1 -1
  26. package/dist/assets/{MyAccess-DRw7SGmu.js → MyAccess-Cxv37Ydj.js} +1 -1
  27. package/dist/assets/{Network-C-Iu9BwS.js → Network-ysqdS6H9.js} +1 -1
  28. package/dist/assets/NodeAddonsSettingsPanel-kzKacAc9.js +1 -0
  29. package/dist/assets/{NodeInferenceDevices-LlOza8Nn.js → NodeInferenceDevices-Duvz2F5-.js} +1 -1
  30. package/dist/assets/{Notifications-BNLOWYmI.js → Notifications-CqpHn6IU.js} +1 -1
  31. package/dist/assets/{Pipeline-DYm6EGaM.js → Pipeline-24MT1671.js} +1 -1
  32. package/dist/assets/{Plates-Brp8Sky4.js → Plates-BF6kXGu7.js} +1 -1
  33. package/dist/assets/{PrivacyMaskSettings-H2Rkbk7c.js → PrivacyMaskSettings-KbJFhqDF.js} +1 -1
  34. package/dist/assets/{ProviderIcon-DXgA2hhx.js → ProviderIcon-Ejsx9Qri.js} +1 -1
  35. package/dist/assets/{Recordings-DgRemOeM.js → Recordings-CqGvJLMO.js} +1 -1
  36. package/dist/assets/{ScanNetworkModal-bvZcyQmN.js → ScanNetworkModal-C0zKHDc-.js} +1 -1
  37. package/dist/assets/{SchemaTabBar-DhsmEGyn.js → SchemaTabBar-BrF8ZUiR.js} +1 -1
  38. package/dist/assets/{Settings-CQY0jRsh.js → Settings-DQTlqVwO.js} +1 -1
  39. package/dist/assets/{Showroom-eQndIGwh.js → Showroom-CRSyuPSB.js} +1 -1
  40. package/dist/assets/StableTabPanel-p16epZGa.js +1 -0
  41. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DNJ_bxKM.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DTcyCN0S.js} +1 -1
  42. package/dist/assets/{build-cluster-graph-Bd_hKHe9.js → build-cluster-graph-BMyt97X4.js} +1 -1
  43. package/dist/assets/circle-check-big-JLMft88R.js +1 -0
  44. package/dist/assets/clock-Dw80Sj_B.js +1 -0
  45. package/dist/assets/{copy-rSmbE4lY.js → copy-Cl11AFcW.js} +1 -1
  46. package/dist/assets/{debounced-invalidate-D-KI_sbM.js → debounced-invalidate-Dg1JokGS.js} +1 -1
  47. package/dist/assets/{dist-6bufrn_9.js → dist-DO_uCRhe.js} +1 -1
  48. package/dist/assets/dist-hhplA-xw.js +7 -0
  49. package/dist/assets/{download-kMQadv8x.js → download-CAa1eJdo.js} +1 -1
  50. package/dist/assets/{face-bbox-D8rphF63.js → face-bbox-U4Diy0fI.js} +1 -1
  51. package/dist/assets/{hostInit-DNYnPeaE.js → hostInit-qqUtSacr.js} +1 -1
  52. package/dist/assets/{index-BUv7lIS6.js → index-BWLF0UML.js} +3 -3
  53. package/dist/assets/index-DO10ga5L.css +2 -0
  54. package/dist/assets/{key-round-DDCVKuV3.js → key-round-D1xbTl3Z.js} +1 -1
  55. package/dist/assets/{mf-entry-bootstrap-0-9ab476d9.js → mf-entry-bootstrap-0-88cc77ad.js} +2 -2
  56. package/dist/assets/{pencil-BkLlKSmd.js → pencil-QENELNzs.js} +1 -1
  57. package/dist/assets/{player-overlays-BlOdAA3b.js → player-overlays-Z3KIJoY4.js} +1 -1
  58. package/dist/assets/plus-CPeKYQLF.js +1 -0
  59. package/dist/assets/{radio-Cb3DZTeZ.js → radio-C5ln0U76.js} +1 -1
  60. package/dist/assets/{refresh-cw-BdQgnZ_R.js → refresh-cw-B3fSkJoP.js} +1 -1
  61. package/dist/assets/remoteEntry-9UljUbRB.js +1 -0
  62. package/dist/assets/{rotate-ccw-BUBHUP5u.js → rotate-ccw-Cle1bD36.js} +1 -1
  63. package/dist/assets/rotate-cw-DacWausQ.js +1 -0
  64. package/dist/assets/search-tdJngvjG.js +1 -0
  65. package/dist/assets/{send-Clgsyxpt.js → send-D8smQ43f.js} +1 -1
  66. package/dist/assets/{server-CzYwfD_W.js → server-C-VRAKCf.js} +1 -1
  67. package/dist/assets/square-CcV1_Dk6.js +1 -0
  68. package/dist/assets/{square-check-big-CA6GbSkt.js → square-check-big-CGX9b-bD.js} +1 -1
  69. package/dist/assets/{src-GxiMH1Sc.js → src-4xaQB5RZ.js} +4 -4
  70. package/dist/assets/{src-DvkErVKO.js → src-C56sOV8c.js} +4 -4
  71. package/dist/assets/{upload-R08A9D4v.js → upload-BEZ6ak-p.js} +1 -1
  72. package/dist/assets/{useEventInvalidation-DNKOmbzS.js → useEventInvalidation-DTNJk88L.js} +1 -1
  73. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DPVzZjZM.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BPfcWk4T.js} +2 -2
  74. package/dist/assets/{wifi-DAhrJCbP.js → wifi-s_m98gca.js} +1 -1
  75. package/dist/assets/{zap-BNRSlFBx.js → zap-Wb2C7zwo.js} +1 -1
  76. package/dist/index.html +6 -6
  77. package/dist/server/addon.js +1 -1
  78. package/package.json +1 -1
  79. package/dist/assets/AdminPage-BwmGKnRf.js +0 -1
  80. package/dist/assets/AdminTabs-DfEwwmUW.js +0 -1
  81. package/dist/assets/Data-C0AfErba.js +0 -1
  82. package/dist/assets/DeviceDetail-D4bbnDqR.js +0 -2
  83. package/dist/assets/Events-BBGuUyXJ.js +0 -1
  84. package/dist/assets/NodeAddonsSettingsPanel-Djus4pp9.js +0 -1
  85. package/dist/assets/circle-check-big-DT7FhybM.js +0 -1
  86. package/dist/assets/clock-CiftjjTL.js +0 -1
  87. package/dist/assets/dist-D5Idz-si.js +0 -7
  88. package/dist/assets/index-BTiaHVM4.css +0 -2
  89. package/dist/assets/plus-Bh3p9eWS.js +0 -1
  90. package/dist/assets/remoteEntry-D6COYK6a.js +0 -1
  91. package/dist/assets/rotate-cw-CIsnIezL.js +0 -1
  92. package/dist/assets/search-B6SrbQqA.js +0 -1
  93. package/dist/assets/square-CcjBMK42.js +0 -1
@@ -1 +1 @@
1
- import{Ai as e,Ar as t,Br as n,Hr as r,Ia as i,Ir as a,Lr as o,Rr as s,Ua as c,Va as l,Vr as u,aa as d,co as f,g as p,ia as m,kr as h,lo as g,m as _,oa as v,oo as y,pi as b,sa as x,so as S,zr as C}from"./src-DvkErVKO.js";import{I as w,K as T,Q as E,S as D,W as O,o as k,q 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-DTufy7Ue.js";import{p as N}from"./player-overlays-BlOdAA3b.js";import{t as P}from"./pencil-BkLlKSmd.js";import{t as ee}from"./radio-Cb3DZTeZ.js";import{t as F}from"./refresh-cw-BdQgnZ_R.js";import{t as I}from"./rotate-cw-CIsnIezL.js";import{t as te}from"./server-CzYwfD_W.js";import{t as L}from"./upload-R08A9D4v.js";import{B as R,I as z,L as ne,P as re,S as B,W as V,i as ie,j as ae,m as H,o as U,s as W,t as G}from"./index-BUv7lIS6.js";import{n as K,t as q}from"./build-cluster-graph-Bd_hKHe9.js";import{t as J}from"./format-size-CO9d3C3-.js";import{t as oe}from"./NodeAddonsSettingsPanel-Djus4pp9.js";var Y=V(`arrow-down-to-line`,[[`path`,{d:`M12 17V3`,key:`1cwfxf`}],[`path`,{d:`m6 11 6 6 6-6`,key:`12ii2o`}],[`path`,{d:`M19 21H5`,key:`150jfl`}]]),se=V(`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`}]]),ce=V(`hard-drive-download`,[[`path`,{d:`M12 2v8`,key:`1q4o3n`}],[`path`,{d:`m16 6-4 4-4-4`,key:`6wukr`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,key:`w68u3i`}],[`path`,{d:`M6 18h.01`,key:`uhywen`}],[`path`,{d:`M10 18h.01`,key:`h775k`}]]),le=V(`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`}]]),X=V(`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`}]]),ue=V(`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`}]]);E();function de(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 fe({nodeId:e,addons:t,isHub:n}){let o=k(),c=i(),[l,u]=A(null),[d,f]=A(null),[p,m]=A(!1),[h,g]=A(null),[_,v]=A(0),y=T(null),b=s(),x=r(),S=a({nodeId:e}),C=S.data??[],w=new Map(t.map(e=>[e.id,e.capabilities])),E=C.length>0?C.map(e=>({id:e.id,status:e.status,capabilities:w.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})),O=()=>{o.invalidateQueries({queryKey:[[`nodes`,`topology`]]}),S.refetch()},M=async t=>{u(t);try{await b.mutateAsync({nodeId:e,addonId:t}),O()}catch(e){console.error(`Failed to restart addon:`,e)}finally{u(null)}},N=async t=>{if(await c({title:`Uninstall addon`,message:`Remove "${t}" from ${e}? The addon directory will be deleted on disk.`,confirmLabel:`Uninstall`,variant:`danger`})){f(t);try{await x.mutateAsync({nodeId:e,addonId:t}),O()}catch(e){console.error(`Failed to uninstall addon:`,e)}finally{f(null)}}},P=D(`div`,{className:`flex items-center gap-2 mb-2`,children:[j(`input`,{ref:y,type:`file`,accept:`.tgz,.tar.gz`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(n){t.target.value=``,g(null),m(!0),v(0);try{await de({file:n,nodeId:e,token:localStorage.getItem(`camstack_admin_token`),onProgress:v}),O()}catch(e){g(e instanceof Error?e.message:String(e))}finally{m(!1),v(0)}}}}),D(`button`,{onClick:()=>y.current?.click(),disabled:p,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:[p?j(B,{className:`h-3 w-3 animate-spin`}):j(L,{className:`h-3 w-3`}),p?`Uploading… ${_}%`:`Upload addon (.tgz)`]}),p&&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:`${_}%`}})}),h&&j(`span`,{className:`text-[10px] text-destructive`,children:h})]});return E.length===0?D(`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`})]}):D(`div`,{children:[P,j(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:D(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:D(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`px-3 py-2 font-medium`,children:`Addon`}),j(`th`,{className:`px-3 py-2 font-medium`,children:`Version`}),j(`th`,{className:`px-3 py-2 font-medium`,children:`Capabilities`}),j(`th`,{className:`px-3 py-2 font-medium`,children:`Status`}),j(`th`,{className:`px-3 py-2 font-medium w-16`})]})}),j(`tbody`,{children:E.map(e=>D(`tr`,{className:`border-t border-border/50`,children:[D(`td`,{className:`px-3 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:`px-3 py-2 text-muted-foreground`,children:e.version??`—`}),j(`td`,{className:`px-3 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:`px-3 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:`px-3 py-2`,children:D(`div`,{className:`flex items-center gap-1 justify-end`,children:[j(`button`,{onClick:()=>M(e.id),disabled:l===e.id||d===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(I,{className:`h-3 w-3 ${l===e.id?`animate-spin`:``}`})}),j(`button`,{onClick:()=>N(e.id),disabled:l===e.id||d===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:d===e.id?j(B,{className:`h-3 w-3 animate-spin`}):j(W,{className:`h-3 w-3`})})]})})]},e.id))})]})})]})}E();function pe(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 me({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 he=[`trace`,`debug`,`info`,`warn`,`error`];function ge({proc:e,nodeId:t,defaultExpanded:r,activePanel:i,onTogglePanel:a}){let o=e.services??[],c=o.length===1,[l,u]=A(c||r),[d,m]=A(null),[h,v]=A(`info`),b=e.name.includes(`(core)`),x=s(),w=C(),T=n(),E=async e=>{m(e);try{await x.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{m(null)}},O=async()=>{m(e.name);try{await w.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{m(null)}},k=async n=>{let r=`${t}/${e.name}`;try{await T.mutateAsync({nodeId:r,level:n}),v(n)}catch(e){console.error(`Failed to set log level:`,e)}};return D(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[D(`div`,{role:c?void 0:`button`,tabIndex:c?void 0:0,onClick:c?void 0:()=>u(!l),onKeyDown:c?void 0:e=>{(e.key===`Enter`||e.key===` `)&&u(!l)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${c?``:`hover:bg-muted/40 cursor-pointer`}`,children:[c?j(`span`,{className:`h-3 w-3 shrink-0`}):j(l?z:re,{className:`h-3 w-3 text-muted-foreground shrink-0`}),b?j(te,{className:`h-3.5 w-3.5 text-primary shrink-0`}):j(R,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),j(`span`,{className:`text-xs font-semibold flex-1`,children:e.name}),D(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,e.pid]}),j(me,{state:e.state}),D(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[e.cpuPercent,`% CPU`]}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:J(e.memoryRss)}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:pe(e.uptimeSeconds)}),!b&&D(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[D(y,{children:[j(g,{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:h}),j(S,{align:`end`,className:`min-w-[70px] py-0.5`,children:he.map(e=>j(f,{onClick:()=>k(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===h?`text-primary font-semibold`:``}`,children:e},e))})]}),j(`button`,{onClick:O,disabled:d===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:j(I,{className:`h-3 w-3 ${d===e.name?`animate-spin`:``}`})})]})]}),l&&o.length>0&&j(`div`,{className:`divide-y divide-border/30`,children:o.map(e=>D(`div`,{children:[D(`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&&D(`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&&D(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),D(`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(ee,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>E(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(I,{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(p,{addonId:e.addonId,agentId:t,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))}),l&&o.length===0&&j(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function _e({nodeId:e,processes:t}){let[n,r]=A(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(ge,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}E();function ve(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 ye(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function be({nodeId:e}){let n=k(),r=i(),[a,o]=A(`all`),s=l(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:c}=t({nodeId:e}),u=s?.processes??c,d=O(()=>u?[...u]:[],[u]),f=O(()=>a===`ghost`?d.filter(e=>e.classification===`ghost`):d,[d,a]),p=O(()=>{let e=d.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)},[d]),m=h({onSettled:()=>{n.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]})}}),g=O(()=>{let e=new Map;for(let t of d)e.set(t.pid,t.classification);return e},[d]),_=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`})&&m.mutate({nodeId:e,pid:t.pid,force:n})},v=async(t,n)=>{try{await m.mutateAsync({nodeId:e,pid:t,force:n})}catch{}},y=async t=>{let i=g.get(t.ppid);if(i===`root`||i===`system`){await r({title:`Cannot kill protected ancestor`,message:i===`root`?`pid ${t.ppid} is the current node supervisor. Restart the node via the cluster page instead.`:`pid ${t.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 + ${t.children.length} child(ren)?`,message:`SIGKILL parent pid ${t.ppid} and SIGTERM ${t.children.length} ghost child(ren) on node ${e}.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all([v(t.ppid,!0),...t.children.map(e=>v(e.pid,!1))]),n.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},b=async()=>{let t=d.filter(e=>e.classification===`ghost`);t.length!==0&&await r({title:`Kill all ${t.length} ghost process(es)?`,message:`SIGKILL ${t.length} ghost process(es) on node ${e}. This is irreversible.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all(t.map(e=>v(e.pid,!0))),n.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},x=d.filter(e=>e.classification===`ghost`).length,S=d.filter(e=>e.classification===`managed`).length,C=d.filter(e=>e.classification===`root`).length,w=d.filter(e=>e.classification===`system`).length;return D(`div`,{className:`space-y-4`,children:[D(`div`,{className:`flex items-start justify-between gap-4`,children:[D(`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."]}),D(`button`,{type:`button`,onClick:()=>n.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(F,{className:`h-3 w-3`}),` Refresh`]})]}),D(`div`,{className:`grid grid-cols-4 gap-3`,children:[D(`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})]}),D(`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:S})]}),D(`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})]}),D(`div`,{className:`rounded-lg border p-3 ${x>0?`border-destructive/40 bg-destructive/5`:`border-border`}`,children:[D(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle flex items-center gap-1`,children:[x>0&&j(X,{className:`h-3 w-3 text-destructive`}),` Ghosts`]}),j(`div`,{className:`text-xl font-semibold ${x>0?`text-destructive`:`text-foreground`}`,children:x})]})]}),p.length>0&&D(`div`,{className:`rounded-lg border border-amber-500/40 bg-amber-500/5 p-3`,children:[D(`div`,{className:`flex items-center gap-1 text-[11px] font-semibold text-amber-400 mb-2`,children:[j(U,{className:`h-3 w-3`}),` Recurring ghost parents (`,p.length,`)`]}),j(`div`,{className:`space-y-1.5`,children:p.map(e=>D(`div`,{className:`text-[11px] text-foreground flex items-center justify-between gap-2`,children:[D(`div`,{className:`flex items-center gap-2`,children:[D(`span`,{className:`font-mono text-foreground-subtle`,children:[`ppid `,e.ppid]}),D(`span`,{children:[`→ `,e.children.length,` ghost(s)`]})]}),D(`button`,{type:`button`,disabled:m.isPending,onClick:()=>{y(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(X,{className:`h-3 w-3`}),` Kill parent + `,e.children.length]})]},e.ppid))})]}),D(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[D(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Filter:`}),D(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${a===`all`?`bg-primary text-primary-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>o(`all`),children:[`All (`,d.length,`)`]}),D(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${a===`ghost`?`bg-destructive text-destructive-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>o(`ghost`),children:[`Ghost only (`,x,`)`]})]}),x>0&&D(`button`,{type:`button`,disabled:m.isPending,onClick:()=>{b()},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(X,{className:`h-3 w-3`}),` Kill all `,x,` ghost(s)`]})]}),j(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:D(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:D(`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`})]})}),D(`tbody`,{children:[f.length===0&&j(`tr`,{children:j(`td`,{colSpan:9,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:a===`ghost`?`No ghost processes detected.`:`Scanning…`})}),f.map(e=>D(`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}),D(`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:ye(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:J(e.memoryRssBytes)}),j(`td`,{className:`px-3 py-2 text-right text-foreground-subtle`,children:ve(e.uptimeSec)}),j(`td`,{className:`px-3 py-2 text-right`,children:D(`div`,{className:`inline-flex gap-1`,children:[D(`button`,{type:`button`,disabled:m.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{_(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(W,{className:`h-3 w-3`}),` Term`]}),D(`button`,{type:`button`,disabled:m.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{_(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(X,{className:`h-3 w-3`}),` Kill`]})]})})]},e.pid))]})]})}),m.isError&&D(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,m.error instanceof Error?m.error.message:`unknown`]})]})}function xe({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(oe,{nodeId:e,addonIds:t,level:`global`,selfTabbed:!0})})}E();function Se({nodeId:t,addons:n}){let r=k(),{data:i,isLoading:a}=b({nodeId:t}),o=O(()=>{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]),s=e({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return o.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No capabilities on this node`}):j(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:D(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:D(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`px-3 py-2 font-medium w-1/2`,children:`Capability`}),j(`th`,{className:`px-3 py-2 font-medium`,children:`Bound provider`})]})}),j(`tbody`,{children:o.map(({capName:e,providers:n})=>{let r=i?.[e]??n[0]??``,o=n.length===1;return D(`tr`,{className:`border-t border-border/50`,children:[j(`td`,{className:`px-3 py-2 font-medium`,children:e}),j(`td`,{className:`px-3 py-2`,children:j(`select`,{value:r,onChange:n=>s.mutate({nodeId:t,capName:e,addonId:n.target.value}),disabled:o||s.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))})})]},e)})})]})})}E();function Z(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 Ce(e){let[t,n]=A(!1),[r,i]=A(e.name),a=k(),s=o({onSuccess:()=>{a.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),c=(e.localIps??[]).filter(e=>!e.includes(`:`)),l=(e.localIps??[]).filter(e=>e.includes(`:`)),u=async()=>{if(!r.trim()||r===e.name){n(!1);return}try{await s.mutateAsync({nodeId:e.nodeId,name:r.trim()}),n(!1)}catch(e){console.error(`Rename failed:`,e)}},d=[[`Node ID`,j(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,t?D(`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`&&u(),e.key===`Escape`&&n(!1)},disabled:s.isPending,autoFocus:!0}),j(`button`,{onClick:()=>void u(),disabled:s.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:`Save`,children:j(ne,{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(ie,{className:`h-3.5 w-3.5`})})]}):D(`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(P,{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`})],[`Root Package`,e.rootPackage?D(`span`,{className:`font-mono text-xs`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}):j(`span`,{className:`text-xs text-muted-foreground`,children:`—`})],[`Platform`,D(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,D(`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:Z(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 c.length>0&&d.push([`IPv4`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map((e,t)=>j(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),l.length>0&&d.push([`IPv6`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:l.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:d.map(([e,t],n)=>D(`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))})})})}E();var we=[[`serverManagement`,`getServerPackageStatus`]];function Q({label:e,tone:t}){return j(`span`,{className:`inline-flex items-center rounded px-2 py-0.5 text-[11px] font-medium ${{neutral:`bg-surface-muted text-foreground-subtle`,ok:`bg-emerald-500/15 text-emerald-500`,info:`bg-sky-500/15 text-sky-500`,warn:`bg-amber-500/15 text-amber-500`,error:`bg-red-500/15 text-red-500`}[t]}`,children:e})}function $({label:e,value:t}){return D(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[j(`span`,{className:`text-foreground-subtle`,children:e}),j(`span`,{className:`font-mono text-foreground`,children:t??`—`})]})}function Te({node:e}){let{t}=G(),n=k(),r=i(),[a,o]=A(!1),s=e.isHub?void 0:{nodeId:e.id},c=v(s,{refetchInterval:1e4,enabled:e.isOnline,retry:1}),l=c.data??null,u=w(()=>{n.invalidateQueries({queryKey:we})},[n]),f=d({onSettled:u}),p=m({onSettled:u}),h=x({onSettled:u}),g=w(async()=>{l?.latestVersion!=null&&await r({title:t(`serverManagement.confirmUpdateTitle`,`Update node root package`),message:t(`serverManagement.confirmUpdateBody`,`Install {{pkg}}@{{version}} on "{{node}}" and restart to apply.`,{pkg:l.packageName,version:l.latestVersion,node:e.name}),confirmLabel:t(`serverManagement.confirmUpdateAction`,`Update & restart`)})&&(await p.mutateAsync({version:l.latestVersion,...s})).restarting&&o(!0)},[p,r,e.name,s,l,t]),_=w(async()=>{await r({title:t(`serverManagement.confirmRestartTitle`,`Restart node`),message:t(`serverManagement.confirmRestartBody`,`Restart "{{node}}"? In-flight requests to this node are dropped.`,{node:e.name}),confirmLabel:t(`serverManagement.confirmRestartAction`,`Restart`),variant:`warning`})&&(await h.mutateAsync(s)).restarting&&o(!0)},[r,e.name,h,s,t]),y=()=>{switch(l?.bootMode){case`data-root`:return{label:t(`serverManagement.bootDataRoot`,`runtime-updatable`),tone:`ok`};case`workspace`:return{label:t(`serverManagement.bootWorkspace`,`dev workspace`),tone:`info`};default:return{label:t(`serverManagement.bootBaked`,`baked image seed`),tone:`neutral`}}},b=()=>{if(l==null)return null;switch(l.updateState){case`checking`:return{label:t(`serverManagement.stateChecking`,`checking…`),tone:`info`};case`staging`:return{label:t(`serverManagement.stateStaging`,`updating…`),tone:`info`};case`pending-restart`:return{label:t(`serverManagement.statePending`,`restart pending`),tone:`warn`};default:return l.updateAvailable?{label:t(`serverManagement.stateUpdateAvailable`,`update available`),tone:`warn`}:{label:t(`serverManagement.stateUpToDate`,`up to date`),tone:`ok`}}},S=l?.bootMode===`workspace`,C=e.isOnline&&l!=null&&!S&&l.updateAvailable&&l.updateState===`idle`&&!p.isPending,T=e.isOnline&&l!=null&&l.updateState===`idle`&&!h.isPending,E=e.isOnline?b():null;return D(`div`,{className:`space-y-4 py-2`,children:[D(`div`,{className:`flex items-center justify-between gap-3`,children:[D(`div`,{className:`flex items-center gap-2 min-w-0`,children:[j(`span`,{className:`font-mono text-xs text-foreground-subtle truncate`,children:l?.packageName??e.rootPackage?.name??`@camstack/server`}),e.isOnline&&l!=null&&j(Q,{...y()})]}),E!=null&&j(Q,{...E})]}),!e.isOnline&&j($,{label:t(`serverManagement.lastReportedVersion`,`Last reported version`),value:e.rootPackage?.version??null}),e.isOnline&&c.isLoading&&D(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[j(B,{className:`h-4 w-4 animate-spin`}),t(`common.loading`,`Loading…`)]}),e.isOnline&&c.isError&&D(`div`,{className:`space-y-1.5`,children:[j(`p`,{className:`text-sm text-red-500`,children:t(`serverManagement.loadError`,`Could not load the node root-package status.`)}),e.rootPackage!=null&&j($,{label:t(`serverManagement.lastReportedVersion`,`Last reported version`),value:e.rootPackage.version})]}),e.isOnline&&l!=null&&D(`div`,{className:`space-y-1.5`,children:[j($,{label:t(`serverManagement.runningVersion`,`Running version`),value:l.runningVersion}),j($,{label:t(`serverManagement.latestVersion`,`Latest on registry`),value:l.latestVersion}),j($,{label:t(`serverManagement.nodeRuntimeVersion`,`Node.js runtime`),value:l.nodeRuntimeVersion}),l.pendingVersion!=null&&j($,{label:t(`serverManagement.pendingVersion`,`Staged (applies on restart)`),value:l.pendingVersion})]}),e.isOnline&&S&&j(`p`,{className:`text-xs text-foreground-subtle`,children:t(`serverManagement.workspaceNote`,`Development workspace detected — runtime updates are disabled (the dev loop resolves code from the workspace).`)}),a&&D(`div`,{className:`flex items-center gap-2 text-sm text-amber-500`,children:[j(B,{className:`h-4 w-4 animate-spin`}),t(`serverManagement.nodeRestarting`,`The node is restarting to apply the change…`)]}),e.isOnline&&D(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[D(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:f.isPending||l?.updateState===`staging`,onClick:()=>f.mutate(s),children:[f.isPending?j(B,{className:`h-3.5 w-3.5 animate-spin`}):j(F,{className:`h-3.5 w-3.5`}),t(`serverManagement.checkForUpdate`,`Check for update`)]}),C&&D(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,onClick:()=>void g(),children:[p.isPending?j(B,{className:`h-3.5 w-3.5 animate-spin`}):j(Y,{className:`h-3.5 w-3.5`}),t(`serverManagement.updateTo`,`Update to {{version}}`,{version:l?.latestVersion??``})]}),D(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:!T,onClick:()=>void _(),children:[h.isPending?j(B,{className:`h-3.5 w-3.5 animate-spin`}):j(I,{className:`h-3.5 w-3.5`}),t(`serverManagement.restart`,`Restart`)]})]}),e.isOnline&&l?.lastCheckedAtMs!=null&&D(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[j(ce,{className:`h-3 w-3`}),t(`serverManagement.lastChecked`,`Last checked: {{when}}`,{when:new Date(l.lastCheckedAtMs).toLocaleString()})]})]})}E();function Ee({node:e}){let t=N(),[n,r]=A(`info`),[i,a]=A(!1),o=e.processes??[],s=e.addons.map(e=>e.id),c=async()=>{if(!i){a(!0);try{await Promise.allSettled([t.trpcClient.pipelineOrchestrator.removeAgentSettings.mutate({agentNodeId:e.id}),t.trpcClient.clusterNodes.forgetNode.mutate({nodeId:e.id})])}finally{a(!1)}}};return e.isOnline?D(`div`,{className:`border border-border rounded-xl`,children:[D(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border rounded-t-xl`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),D(`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)),D(`div`,{className:`ml-auto flex gap-3 text-xs text-muted-foreground`,children:[D(`span`,{className:`flex items-center gap-1`,children:[j(ae,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),D(`span`,{className:`flex items-center gap-1`,children:[j(le,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),j(`div`,{className:`sticky top-0 z-20 flex border-b border-border px-4 bg-background overflow-x-auto`,children:[`info`,`addons`,`forks`,`processes`,`settings`,`capabilities`].map(t=>j(`button`,{onClick:()=>r(t),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${n===t?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:t===`info`?`General`:t===`addons`?`Addons (${e.addons.length})`:t===`forks`?`Forks (${o.length})`:t===`processes`?`Processes`:t===`settings`?`Settings`:`Capabilities`},t))}),D(`div`,{className:`px-4 py-2`,children:[n===`info`&&D(`div`,{className:`space-y-3`,children:[j(Ce,{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,rootPackage:e.rootPackage}),j(`div`,{className:`border-t border-border pt-1`,children:j(Te,{node:{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,rootPackage:e.rootPackage??null}})})]}),n===`addons`&&j(fe,{nodeId:e.id,addons:e.addons,isHub:e.isHub}),n===`forks`&&j(_e,{nodeId:e.id,processes:o}),n===`processes`&&j(be,{nodeId:e.id}),n===`settings`&&j(xe,{nodeId:e.id,addonIds:s}),n===`capabilities`&&j(Se,{nodeId:e.id,addons:e.addons})]})]}):D(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[D(`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}),D(`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.rootPackage&&D(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}),j(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`})]}),D(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[D(`span`,{className:`text-xs text-muted-foreground`,children:[e.lastSeen?`Last seen ${new Date(e.lastSeen).toLocaleString()} — `:``,e.addons.length,` addon`,e.addons.length===1?``:`s`,` assigned; will resume when node reconnects`]}),D(`button`,{type:`button`,onClick:()=>void c(),disabled:i,title:`Forget this node — removes its saved history and pipeline assignments`,className:`flex items-center gap-1 text-xs px-2 py-1 rounded-md border border-border text-muted-foreground hover:text-destructive hover:border-destructive/50 disabled:opacity-50 transition-colors`,children:[j(W,{className:`h-3 w-3`}),i?`Forgetting…`:`Forget node`]})]})]})}E();function De({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=T(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(Ee,{node:e})},e.id))})}E();function Oe(e){let[t,n]=A(()=>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 ke(){let{data:e,isLoading:t}=u(void 0,{staleTime:1/0}),[n,r]=A(null);return c(`cluster.topology-snapshot`,e=>{let t=e.data?.nodes;Array.isArray(t)&&r(t)}),{nodes:O(()=>n??e??[],[n,e]),isLoading:t&&!n}}function Ae(){let{t:e}=G(),t=i(),[n,r]=A(`table`),[a,o]=A(void 0),[s,c]=A(0),l=Oe(`(max-width: 767px)`),u=l&&n===`graph`?`table`:n,{nodes:d,isLoading:f}=ke(),p=O(()=>q(d),[d]),h=O(()=>d.filter(e=>e.isOnline),[d]),g=h.length,_=d.filter(e=>!e.isOnline).length,v=m(),[y,b]=A(!1),x=w(async()=>{let n=[...h].sort((e,t)=>e.isHub===t.isHub?0:e.isHub?1:-1);if(await t({title:e(`serverManagement.confirmUpdateAllTitle`,`Update all nodes`),message:e(`serverManagement.confirmUpdateAllBody`,`Update and restart every online node, agents first, hub last. Up-to-date nodes are skipped; this page reconnects when the hub comes back.`),confirmLabel:e(`serverManagement.confirmUpdateAllAction`,`Update all & restart`),variant:`warning`})){b(!0);try{for(let e of n)try{await v.mutateAsync(e.isHub?{}:{nodeId:e.id})}catch{}}finally{b(!1)}}},[v,t,h,e]),S=w(e=>{r(`table`),o(e),c(e=>e+1)},[]),C=(e,t,i)=>D(`button`,{onClick:()=>r(e),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${n===e?`bg-primary text-primary-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[j(i,{className:`h-3.5 w-3.5`}),t]});return D(`div`,{className:`flex flex-col h-full gap-4 p-4`,children:[D(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[D(`div`,{className:`flex items-center gap-2`,children:[g>0&&D(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-success/10 text-success`,children:[g,` online`]}),_>0&&D(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:[_,` offline`]})]}),D(`div`,{className:`flex items-center gap-2`,children:[g>1&&D(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,disabled:y,title:e(`serverManagement.updateAllHint`,`Sequenced agents-first, hub-last — up-to-date nodes are skipped.`),onClick:()=>void x(),children:[y?j(B,{className:`h-3.5 w-3.5 animate-spin`}):j(Y,{className:`h-3.5 w-3.5`}),e(`serverManagement.updateAll`,`Update all nodes`)]}),D(`div`,{className:`flex gap-0.5 p-1 rounded-lg bg-muted`,children:[C(`table`,`Table`,ue),!l&&C(`graph`,`Graph`,se)]})]})]}),f?j(`div`,{className:`flex items-center justify-center flex-1 text-muted-foreground`,children:`Loading cluster topology...`}):u===`graph`?j(K,{graph:p,onOpenNodeDetail:S}):j(`div`,{className:`flex-1 overflow-auto`,children:j(De,{nodes:d,focusNodeId:a,focusNonce:s})})]})}export{Ae as ClusterPage};
1
+ import{Ai as e,Ar as t,Br as n,Hr as r,Ia as i,Ir as a,Lr as o,Rr as s,Ua as c,Va as l,Vr as u,aa as d,co as f,g as p,ia as m,kr as h,lo as g,m as _,oa as v,oo as y,pi as b,sa as x,so as S,zr as C}from"./src-C56sOV8c.js";import{I as w,K as T,Q as E,S as D,W as O,o as k,q 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-DTufy7Ue.js";import{p as N}from"./player-overlays-Z3KIJoY4.js";import{t as P}from"./pencil-QENELNzs.js";import{t as ee}from"./radio-C5ln0U76.js";import{t as F}from"./refresh-cw-B3fSkJoP.js";import{t as I}from"./rotate-cw-DacWausQ.js";import{t as te}from"./server-C-VRAKCf.js";import{t as L}from"./upload-BEZ6ak-p.js";import{B as R,I as z,L as ne,P as re,S as B,W as V,i as ie,j as ae,m as H,o as U,s as W,t as G}from"./index-BWLF0UML.js";import{n as K,t as q}from"./build-cluster-graph-BMyt97X4.js";import{t as J}from"./format-size-CO9d3C3-.js";import{t as oe}from"./NodeAddonsSettingsPanel-kzKacAc9.js";var Y=V(`arrow-down-to-line`,[[`path`,{d:`M12 17V3`,key:`1cwfxf`}],[`path`,{d:`m6 11 6 6 6-6`,key:`12ii2o`}],[`path`,{d:`M19 21H5`,key:`150jfl`}]]),se=V(`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`}]]),ce=V(`hard-drive-download`,[[`path`,{d:`M12 2v8`,key:`1q4o3n`}],[`path`,{d:`m16 6-4 4-4-4`,key:`6wukr`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,key:`w68u3i`}],[`path`,{d:`M6 18h.01`,key:`uhywen`}],[`path`,{d:`M10 18h.01`,key:`h775k`}]]),le=V(`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`}]]),X=V(`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`}]]),ue=V(`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`}]]);E();function de(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 fe({nodeId:e,addons:t,isHub:n}){let o=k(),c=i(),[l,u]=A(null),[d,f]=A(null),[p,m]=A(!1),[h,g]=A(null),[_,v]=A(0),y=T(null),b=s(),x=r(),S=a({nodeId:e}),C=S.data??[],w=new Map(t.map(e=>[e.id,e.capabilities])),E=C.length>0?C.map(e=>({id:e.id,status:e.status,capabilities:w.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})),O=()=>{o.invalidateQueries({queryKey:[[`nodes`,`topology`]]}),S.refetch()},M=async t=>{u(t);try{await b.mutateAsync({nodeId:e,addonId:t}),O()}catch(e){console.error(`Failed to restart addon:`,e)}finally{u(null)}},N=async t=>{if(await c({title:`Uninstall addon`,message:`Remove "${t}" from ${e}? The addon directory will be deleted on disk.`,confirmLabel:`Uninstall`,variant:`danger`})){f(t);try{await x.mutateAsync({nodeId:e,addonId:t}),O()}catch(e){console.error(`Failed to uninstall addon:`,e)}finally{f(null)}}},P=D(`div`,{className:`flex items-center gap-2 mb-2`,children:[j(`input`,{ref:y,type:`file`,accept:`.tgz,.tar.gz`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(n){t.target.value=``,g(null),m(!0),v(0);try{await de({file:n,nodeId:e,token:localStorage.getItem(`camstack_admin_token`),onProgress:v}),O()}catch(e){g(e instanceof Error?e.message:String(e))}finally{m(!1),v(0)}}}}),D(`button`,{onClick:()=>y.current?.click(),disabled:p,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:[p?j(B,{className:`h-3 w-3 animate-spin`}):j(L,{className:`h-3 w-3`}),p?`Uploading… ${_}%`:`Upload addon (.tgz)`]}),p&&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:`${_}%`}})}),h&&j(`span`,{className:`text-[10px] text-destructive`,children:h})]});return E.length===0?D(`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`})]}):D(`div`,{children:[P,j(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:D(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:D(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`px-3 py-2 font-medium`,children:`Addon`}),j(`th`,{className:`px-3 py-2 font-medium`,children:`Version`}),j(`th`,{className:`px-3 py-2 font-medium`,children:`Capabilities`}),j(`th`,{className:`px-3 py-2 font-medium`,children:`Status`}),j(`th`,{className:`px-3 py-2 font-medium w-16`})]})}),j(`tbody`,{children:E.map(e=>D(`tr`,{className:`border-t border-border/50`,children:[D(`td`,{className:`px-3 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:`px-3 py-2 text-muted-foreground`,children:e.version??`—`}),j(`td`,{className:`px-3 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:`px-3 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:`px-3 py-2`,children:D(`div`,{className:`flex items-center gap-1 justify-end`,children:[j(`button`,{onClick:()=>M(e.id),disabled:l===e.id||d===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(I,{className:`h-3 w-3 ${l===e.id?`animate-spin`:``}`})}),j(`button`,{onClick:()=>N(e.id),disabled:l===e.id||d===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:d===e.id?j(B,{className:`h-3 w-3 animate-spin`}):j(W,{className:`h-3 w-3`})})]})})]},e.id))})]})})]})}E();function pe(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 me({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 he=[`trace`,`debug`,`info`,`warn`,`error`];function ge({proc:e,nodeId:t,defaultExpanded:r,activePanel:i,onTogglePanel:a}){let o=e.services??[],c=o.length===1,[l,u]=A(c||r),[d,m]=A(null),[h,v]=A(`info`),b=e.name.includes(`(core)`),x=s(),w=C(),T=n(),E=async e=>{m(e);try{await x.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{m(null)}},O=async()=>{m(e.name);try{await w.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{m(null)}},k=async n=>{let r=`${t}/${e.name}`;try{await T.mutateAsync({nodeId:r,level:n}),v(n)}catch(e){console.error(`Failed to set log level:`,e)}};return D(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[D(`div`,{role:c?void 0:`button`,tabIndex:c?void 0:0,onClick:c?void 0:()=>u(!l),onKeyDown:c?void 0:e=>{(e.key===`Enter`||e.key===` `)&&u(!l)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${c?``:`hover:bg-muted/40 cursor-pointer`}`,children:[c?j(`span`,{className:`h-3 w-3 shrink-0`}):j(l?z:re,{className:`h-3 w-3 text-muted-foreground shrink-0`}),b?j(te,{className:`h-3.5 w-3.5 text-primary shrink-0`}):j(R,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),j(`span`,{className:`text-xs font-semibold flex-1`,children:e.name}),D(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,e.pid]}),j(me,{state:e.state}),D(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[e.cpuPercent,`% CPU`]}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:J(e.memoryRss)}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:pe(e.uptimeSeconds)}),!b&&D(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[D(y,{children:[j(g,{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:h}),j(S,{align:`end`,className:`min-w-[70px] py-0.5`,children:he.map(e=>j(f,{onClick:()=>k(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===h?`text-primary font-semibold`:``}`,children:e},e))})]}),j(`button`,{onClick:O,disabled:d===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:j(I,{className:`h-3 w-3 ${d===e.name?`animate-spin`:``}`})})]})]}),l&&o.length>0&&j(`div`,{className:`divide-y divide-border/30`,children:o.map(e=>D(`div`,{children:[D(`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&&D(`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&&D(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),D(`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(ee,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>E(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(I,{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(p,{addonId:e.addonId,agentId:t,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))}),l&&o.length===0&&j(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function _e({nodeId:e,processes:t}){let[n,r]=A(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(ge,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}E();function ve(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 ye(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function be({nodeId:e}){let n=k(),r=i(),[a,o]=A(`all`),s=l(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:c}=t({nodeId:e}),u=s?.processes??c,d=O(()=>u?[...u]:[],[u]),f=O(()=>a===`ghost`?d.filter(e=>e.classification===`ghost`):d,[d,a]),p=O(()=>{let e=d.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)},[d]),m=h({onSettled:()=>{n.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]})}}),g=O(()=>{let e=new Map;for(let t of d)e.set(t.pid,t.classification);return e},[d]),_=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`})&&m.mutate({nodeId:e,pid:t.pid,force:n})},v=async(t,n)=>{try{await m.mutateAsync({nodeId:e,pid:t,force:n})}catch{}},y=async t=>{let i=g.get(t.ppid);if(i===`root`||i===`system`){await r({title:`Cannot kill protected ancestor`,message:i===`root`?`pid ${t.ppid} is the current node supervisor. Restart the node via the cluster page instead.`:`pid ${t.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 + ${t.children.length} child(ren)?`,message:`SIGKILL parent pid ${t.ppid} and SIGTERM ${t.children.length} ghost child(ren) on node ${e}.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all([v(t.ppid,!0),...t.children.map(e=>v(e.pid,!1))]),n.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},b=async()=>{let t=d.filter(e=>e.classification===`ghost`);t.length!==0&&await r({title:`Kill all ${t.length} ghost process(es)?`,message:`SIGKILL ${t.length} ghost process(es) on node ${e}. This is irreversible.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all(t.map(e=>v(e.pid,!0))),n.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},x=d.filter(e=>e.classification===`ghost`).length,S=d.filter(e=>e.classification===`managed`).length,C=d.filter(e=>e.classification===`root`).length,w=d.filter(e=>e.classification===`system`).length;return D(`div`,{className:`space-y-4`,children:[D(`div`,{className:`flex items-start justify-between gap-4`,children:[D(`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."]}),D(`button`,{type:`button`,onClick:()=>n.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(F,{className:`h-3 w-3`}),` Refresh`]})]}),D(`div`,{className:`grid grid-cols-4 gap-3`,children:[D(`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})]}),D(`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:S})]}),D(`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})]}),D(`div`,{className:`rounded-lg border p-3 ${x>0?`border-destructive/40 bg-destructive/5`:`border-border`}`,children:[D(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle flex items-center gap-1`,children:[x>0&&j(X,{className:`h-3 w-3 text-destructive`}),` Ghosts`]}),j(`div`,{className:`text-xl font-semibold ${x>0?`text-destructive`:`text-foreground`}`,children:x})]})]}),p.length>0&&D(`div`,{className:`rounded-lg border border-amber-500/40 bg-amber-500/5 p-3`,children:[D(`div`,{className:`flex items-center gap-1 text-[11px] font-semibold text-amber-400 mb-2`,children:[j(U,{className:`h-3 w-3`}),` Recurring ghost parents (`,p.length,`)`]}),j(`div`,{className:`space-y-1.5`,children:p.map(e=>D(`div`,{className:`text-[11px] text-foreground flex items-center justify-between gap-2`,children:[D(`div`,{className:`flex items-center gap-2`,children:[D(`span`,{className:`font-mono text-foreground-subtle`,children:[`ppid `,e.ppid]}),D(`span`,{children:[`→ `,e.children.length,` ghost(s)`]})]}),D(`button`,{type:`button`,disabled:m.isPending,onClick:()=>{y(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(X,{className:`h-3 w-3`}),` Kill parent + `,e.children.length]})]},e.ppid))})]}),D(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[D(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Filter:`}),D(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${a===`all`?`bg-primary text-primary-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>o(`all`),children:[`All (`,d.length,`)`]}),D(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${a===`ghost`?`bg-destructive text-destructive-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>o(`ghost`),children:[`Ghost only (`,x,`)`]})]}),x>0&&D(`button`,{type:`button`,disabled:m.isPending,onClick:()=>{b()},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(X,{className:`h-3 w-3`}),` Kill all `,x,` ghost(s)`]})]}),j(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:D(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:D(`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`})]})}),D(`tbody`,{children:[f.length===0&&j(`tr`,{children:j(`td`,{colSpan:9,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:a===`ghost`?`No ghost processes detected.`:`Scanning…`})}),f.map(e=>D(`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}),D(`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:ye(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:J(e.memoryRssBytes)}),j(`td`,{className:`px-3 py-2 text-right text-foreground-subtle`,children:ve(e.uptimeSec)}),j(`td`,{className:`px-3 py-2 text-right`,children:D(`div`,{className:`inline-flex gap-1`,children:[D(`button`,{type:`button`,disabled:m.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{_(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(W,{className:`h-3 w-3`}),` Term`]}),D(`button`,{type:`button`,disabled:m.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{_(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(X,{className:`h-3 w-3`}),` Kill`]})]})})]},e.pid))]})]})}),m.isError&&D(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,m.error instanceof Error?m.error.message:`unknown`]})]})}function xe({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(oe,{nodeId:e,addonIds:t,level:`global`,selfTabbed:!0})})}E();function Se({nodeId:t,addons:n}){let r=k(),{data:i,isLoading:a}=b({nodeId:t}),o=O(()=>{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]),s=e({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return o.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No capabilities on this node`}):j(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:D(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:D(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`px-3 py-2 font-medium w-1/2`,children:`Capability`}),j(`th`,{className:`px-3 py-2 font-medium`,children:`Bound provider`})]})}),j(`tbody`,{children:o.map(({capName:e,providers:n})=>{let r=i?.[e]??n[0]??``,o=n.length===1;return D(`tr`,{className:`border-t border-border/50`,children:[j(`td`,{className:`px-3 py-2 font-medium`,children:e}),j(`td`,{className:`px-3 py-2`,children:j(`select`,{value:r,onChange:n=>s.mutate({nodeId:t,capName:e,addonId:n.target.value}),disabled:o||s.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))})})]},e)})})]})})}E();function Z(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 Ce(e){let[t,n]=A(!1),[r,i]=A(e.name),a=k(),s=o({onSuccess:()=>{a.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),c=(e.localIps??[]).filter(e=>!e.includes(`:`)),l=(e.localIps??[]).filter(e=>e.includes(`:`)),u=async()=>{if(!r.trim()||r===e.name){n(!1);return}try{await s.mutateAsync({nodeId:e.nodeId,name:r.trim()}),n(!1)}catch(e){console.error(`Rename failed:`,e)}},d=[[`Node ID`,j(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,t?D(`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`&&u(),e.key===`Escape`&&n(!1)},disabled:s.isPending,autoFocus:!0}),j(`button`,{onClick:()=>void u(),disabled:s.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:`Save`,children:j(ne,{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(ie,{className:`h-3.5 w-3.5`})})]}):D(`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(P,{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`})],[`Root Package`,e.rootPackage?D(`span`,{className:`font-mono text-xs`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}):j(`span`,{className:`text-xs text-muted-foreground`,children:`—`})],[`Platform`,D(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,D(`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:Z(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 c.length>0&&d.push([`IPv4`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map((e,t)=>j(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),l.length>0&&d.push([`IPv6`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:l.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:d.map(([e,t],n)=>D(`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))})})})}E();var we=[[`serverManagement`,`getServerPackageStatus`]];function Q({label:e,tone:t}){return j(`span`,{className:`inline-flex items-center rounded px-2 py-0.5 text-[11px] font-medium ${{neutral:`bg-surface-muted text-foreground-subtle`,ok:`bg-emerald-500/15 text-emerald-500`,info:`bg-sky-500/15 text-sky-500`,warn:`bg-amber-500/15 text-amber-500`,error:`bg-red-500/15 text-red-500`}[t]}`,children:e})}function $({label:e,value:t}){return D(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[j(`span`,{className:`text-foreground-subtle`,children:e}),j(`span`,{className:`font-mono text-foreground`,children:t??`—`})]})}function Te({node:e}){let{t}=G(),n=k(),r=i(),[a,o]=A(!1),s=e.isHub?void 0:{nodeId:e.id},c=v(s,{refetchInterval:1e4,enabled:e.isOnline,retry:1}),l=c.data??null,u=w(()=>{n.invalidateQueries({queryKey:we})},[n]),f=d({onSettled:u}),p=m({onSettled:u}),h=x({onSettled:u}),g=w(async()=>{l?.latestVersion!=null&&await r({title:t(`serverManagement.confirmUpdateTitle`,`Update node root package`),message:t(`serverManagement.confirmUpdateBody`,`Install {{pkg}}@{{version}} on "{{node}}" and restart to apply.`,{pkg:l.packageName,version:l.latestVersion,node:e.name}),confirmLabel:t(`serverManagement.confirmUpdateAction`,`Update & restart`)})&&(await p.mutateAsync({version:l.latestVersion,...s})).restarting&&o(!0)},[p,r,e.name,s,l,t]),_=w(async()=>{await r({title:t(`serverManagement.confirmRestartTitle`,`Restart node`),message:t(`serverManagement.confirmRestartBody`,`Restart "{{node}}"? In-flight requests to this node are dropped.`,{node:e.name}),confirmLabel:t(`serverManagement.confirmRestartAction`,`Restart`),variant:`warning`})&&(await h.mutateAsync(s)).restarting&&o(!0)},[r,e.name,h,s,t]),y=()=>{switch(l?.bootMode){case`data-root`:return{label:t(`serverManagement.bootDataRoot`,`runtime-updatable`),tone:`ok`};case`workspace`:return{label:t(`serverManagement.bootWorkspace`,`dev workspace`),tone:`info`};default:return{label:t(`serverManagement.bootBaked`,`baked image seed`),tone:`neutral`}}},b=()=>{if(l==null)return null;switch(l.updateState){case`checking`:return{label:t(`serverManagement.stateChecking`,`checking…`),tone:`info`};case`staging`:return{label:t(`serverManagement.stateStaging`,`updating…`),tone:`info`};case`pending-restart`:return{label:t(`serverManagement.statePending`,`restart pending`),tone:`warn`};default:return l.updateAvailable?{label:t(`serverManagement.stateUpdateAvailable`,`update available`),tone:`warn`}:{label:t(`serverManagement.stateUpToDate`,`up to date`),tone:`ok`}}},S=l?.bootMode===`workspace`,C=e.isOnline&&l!=null&&!S&&l.updateAvailable&&l.updateState===`idle`&&!p.isPending,T=e.isOnline&&l!=null&&l.updateState===`idle`&&!h.isPending,E=e.isOnline?b():null;return D(`div`,{className:`space-y-4 py-2`,children:[D(`div`,{className:`flex items-center justify-between gap-3`,children:[D(`div`,{className:`flex items-center gap-2 min-w-0`,children:[j(`span`,{className:`font-mono text-xs text-foreground-subtle truncate`,children:l?.packageName??e.rootPackage?.name??`@camstack/server`}),e.isOnline&&l!=null&&j(Q,{...y()})]}),E!=null&&j(Q,{...E})]}),!e.isOnline&&j($,{label:t(`serverManagement.lastReportedVersion`,`Last reported version`),value:e.rootPackage?.version??null}),e.isOnline&&c.isLoading&&D(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[j(B,{className:`h-4 w-4 animate-spin`}),t(`common.loading`,`Loading…`)]}),e.isOnline&&c.isError&&D(`div`,{className:`space-y-1.5`,children:[j(`p`,{className:`text-sm text-red-500`,children:t(`serverManagement.loadError`,`Could not load the node root-package status.`)}),e.rootPackage!=null&&j($,{label:t(`serverManagement.lastReportedVersion`,`Last reported version`),value:e.rootPackage.version})]}),e.isOnline&&l!=null&&D(`div`,{className:`space-y-1.5`,children:[j($,{label:t(`serverManagement.runningVersion`,`Running version`),value:l.runningVersion}),j($,{label:t(`serverManagement.latestVersion`,`Latest on registry`),value:l.latestVersion}),j($,{label:t(`serverManagement.nodeRuntimeVersion`,`Node.js runtime`),value:l.nodeRuntimeVersion}),l.pendingVersion!=null&&j($,{label:t(`serverManagement.pendingVersion`,`Staged (applies on restart)`),value:l.pendingVersion})]}),e.isOnline&&S&&j(`p`,{className:`text-xs text-foreground-subtle`,children:t(`serverManagement.workspaceNote`,`Development workspace detected — runtime updates are disabled (the dev loop resolves code from the workspace).`)}),a&&D(`div`,{className:`flex items-center gap-2 text-sm text-amber-500`,children:[j(B,{className:`h-4 w-4 animate-spin`}),t(`serverManagement.nodeRestarting`,`The node is restarting to apply the change…`)]}),e.isOnline&&D(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[D(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:f.isPending||l?.updateState===`staging`,onClick:()=>f.mutate(s),children:[f.isPending?j(B,{className:`h-3.5 w-3.5 animate-spin`}):j(F,{className:`h-3.5 w-3.5`}),t(`serverManagement.checkForUpdate`,`Check for update`)]}),C&&D(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,onClick:()=>void g(),children:[p.isPending?j(B,{className:`h-3.5 w-3.5 animate-spin`}):j(Y,{className:`h-3.5 w-3.5`}),t(`serverManagement.updateTo`,`Update to {{version}}`,{version:l?.latestVersion??``})]}),D(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:!T,onClick:()=>void _(),children:[h.isPending?j(B,{className:`h-3.5 w-3.5 animate-spin`}):j(I,{className:`h-3.5 w-3.5`}),t(`serverManagement.restart`,`Restart`)]})]}),e.isOnline&&l?.lastCheckedAtMs!=null&&D(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[j(ce,{className:`h-3 w-3`}),t(`serverManagement.lastChecked`,`Last checked: {{when}}`,{when:new Date(l.lastCheckedAtMs).toLocaleString()})]})]})}E();function Ee({node:e}){let t=N(),[n,r]=A(`info`),[i,a]=A(!1),o=e.processes??[],s=e.addons.map(e=>e.id),c=async()=>{if(!i){a(!0);try{await Promise.allSettled([t.trpcClient.pipelineOrchestrator.removeAgentSettings.mutate({agentNodeId:e.id}),t.trpcClient.clusterNodes.forgetNode.mutate({nodeId:e.id})])}finally{a(!1)}}};return e.isOnline?D(`div`,{className:`border border-border rounded-xl`,children:[D(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border rounded-t-xl`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),D(`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)),D(`div`,{className:`ml-auto flex gap-3 text-xs text-muted-foreground`,children:[D(`span`,{className:`flex items-center gap-1`,children:[j(ae,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),D(`span`,{className:`flex items-center gap-1`,children:[j(le,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),j(`div`,{className:`sticky top-0 z-20 flex border-b border-border px-4 bg-background overflow-x-auto`,children:[`info`,`addons`,`forks`,`processes`,`settings`,`capabilities`].map(t=>j(`button`,{onClick:()=>r(t),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${n===t?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:t===`info`?`General`:t===`addons`?`Addons (${e.addons.length})`:t===`forks`?`Forks (${o.length})`:t===`processes`?`Processes`:t===`settings`?`Settings`:`Capabilities`},t))}),D(`div`,{className:`px-4 py-2`,children:[n===`info`&&D(`div`,{className:`space-y-3`,children:[j(Ce,{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,rootPackage:e.rootPackage}),j(`div`,{className:`border-t border-border pt-1`,children:j(Te,{node:{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,rootPackage:e.rootPackage??null}})})]}),n===`addons`&&j(fe,{nodeId:e.id,addons:e.addons,isHub:e.isHub}),n===`forks`&&j(_e,{nodeId:e.id,processes:o}),n===`processes`&&j(be,{nodeId:e.id}),n===`settings`&&j(xe,{nodeId:e.id,addonIds:s}),n===`capabilities`&&j(Se,{nodeId:e.id,addons:e.addons})]})]}):D(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[D(`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}),D(`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.rootPackage&&D(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}),j(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`})]}),D(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[D(`span`,{className:`text-xs text-muted-foreground`,children:[e.lastSeen?`Last seen ${new Date(e.lastSeen).toLocaleString()} — `:``,e.addons.length,` addon`,e.addons.length===1?``:`s`,` assigned; will resume when node reconnects`]}),D(`button`,{type:`button`,onClick:()=>void c(),disabled:i,title:`Forget this node — removes its saved history and pipeline assignments`,className:`flex items-center gap-1 text-xs px-2 py-1 rounded-md border border-border text-muted-foreground hover:text-destructive hover:border-destructive/50 disabled:opacity-50 transition-colors`,children:[j(W,{className:`h-3 w-3`}),i?`Forgetting…`:`Forget node`]})]})]})}E();function De({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=T(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(Ee,{node:e})},e.id))})}E();function Oe(e){let[t,n]=A(()=>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 ke(){let{data:e,isLoading:t}=u(void 0,{staleTime:1/0}),[n,r]=A(null);return c(`cluster.topology-snapshot`,e=>{let t=e.data?.nodes;Array.isArray(t)&&r(t)}),{nodes:O(()=>n??e??[],[n,e]),isLoading:t&&!n}}function Ae(){let{t:e}=G(),t=i(),[n,r]=A(`table`),[a,o]=A(void 0),[s,c]=A(0),l=Oe(`(max-width: 767px)`),u=l&&n===`graph`?`table`:n,{nodes:d,isLoading:f}=ke(),p=O(()=>q(d),[d]),h=O(()=>d.filter(e=>e.isOnline),[d]),g=h.length,_=d.filter(e=>!e.isOnline).length,v=m(),[y,b]=A(!1),x=w(async()=>{let n=[...h].sort((e,t)=>e.isHub===t.isHub?0:e.isHub?1:-1);if(await t({title:e(`serverManagement.confirmUpdateAllTitle`,`Update all nodes`),message:e(`serverManagement.confirmUpdateAllBody`,`Update and restart every online node, agents first, hub last. Up-to-date nodes are skipped; this page reconnects when the hub comes back.`),confirmLabel:e(`serverManagement.confirmUpdateAllAction`,`Update all & restart`),variant:`warning`})){b(!0);try{for(let e of n)try{await v.mutateAsync(e.isHub?{}:{nodeId:e.id})}catch{}}finally{b(!1)}}},[v,t,h,e]),S=w(e=>{r(`table`),o(e),c(e=>e+1)},[]),C=(e,t,i)=>D(`button`,{onClick:()=>r(e),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${n===e?`bg-primary text-primary-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[j(i,{className:`h-3.5 w-3.5`}),t]});return D(`div`,{className:`flex flex-col h-full gap-4 p-4`,children:[D(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[D(`div`,{className:`flex items-center gap-2`,children:[g>0&&D(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-success/10 text-success`,children:[g,` online`]}),_>0&&D(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:[_,` offline`]})]}),D(`div`,{className:`flex items-center gap-2`,children:[g>1&&D(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,disabled:y,title:e(`serverManagement.updateAllHint`,`Sequenced agents-first, hub-last — up-to-date nodes are skipped.`),onClick:()=>void x(),children:[y?j(B,{className:`h-3.5 w-3.5 animate-spin`}):j(Y,{className:`h-3.5 w-3.5`}),e(`serverManagement.updateAll`,`Update all nodes`)]}),D(`div`,{className:`flex gap-0.5 p-1 rounded-lg bg-muted`,children:[C(`table`,`Table`,ue),!l&&C(`graph`,`Graph`,se)]})]})]}),f?j(`div`,{className:`flex items-center justify-center flex-1 text-muted-foreground`,children:`Loading cluster topology...`}):u===`graph`?j(K,{graph:p,onOpenNodeDetail:S}):j(`div`,{className:`flex-1 overflow-auto`,children:j(De,{nodes:d,focusNodeId:a,focusNonce:s})})]})}export{Ae as ClusterPage};
@@ -1 +1 @@
1
- import{Ia as e,Vr as t,ca as n,fa as r,ft as i,la as a,ua as o,ut as s}from"./src-DvkErVKO.js";import{Q as c,S as l,W as u,o as d,q as f,x as p}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{n as m,r as h,t as g}from"./AddLocationWizard-lNJZEC5r.js";import{S as _}from"./index-BUv7lIS6.js";c();function v({types:t}){let i=d(),s=e(),{data:c}=o({}),_=a(),v=u(()=>_.data??[],[_.data]),[y,b]=f(null),[x,S]=f(null),C=()=>{i.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})},w=r({onSuccess:C}),T=n({onSuccess:C}),E=u(()=>{let e=new Map;for(let t of c??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[c]),D=e=>{e.isDefault||w.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},O=async e=>{if(e.isDefault){await s({title:`Cannot delete default location`,message:`"${e.displayName}" is the default for type "${e.type}". Mark another as default first.`,confirmLabel:`OK`,variant:`warning`});return}await s({title:`Delete location "${e.displayName}"?`,message:`Removes the record; files on disk are untouched.`,confirmLabel:`Delete`,variant:`danger`})&&T.mutate({id:e.id})},k=t.map(e=>v.find(t=>t.id===e)).filter(e=>e!==void 0);return l(`div`,{className:`space-y-3`,children:[k.length===0?p(`p`,{className:`text-[11px] text-foreground-subtle italic`,children:`No storage locations declared for this purpose.`}):k.map(e=>p(h,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:E.get(e.id)??[],onAdd:e=>b(e),onEdit:e=>S(e),onDelete:e=>{O(e)},onSetDefault:e=>D(e)},e.id)),y!==null&&p(g,{initialType:y,onClose:()=>b(null),onCreated:()=>{C(),b(null)}}),x!==null&&p(m,{location:x,onClose:()=>S(null),onSaved:()=>{C(),S(null)}})]})}c();var y=`recorder`;function b(e,t,n){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t&&typeof e.value==`string`)return e.value;return n}function x(){let e=d(),{data:n}=t(void 0),{data:r,isLoading:a}=s({addonId:y}),o=b(r,`recordingNodeId`,`hub`),c=i({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),f=u(()=>{let e=(n??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,o,...e])].filter(Boolean)},[n,o]);return l(`div`,{className:`flex flex-col gap-6`,children:[l(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[p(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Recording node`}),p(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that records (continuous & events) and serves playback. Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),l(`div`,{className:`mt-3 flex items-center gap-2`,children:[a?p(_,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):p(`select`,{value:o,onChange:e=>{e.target.value!==o&&c.mutate({addonId:y,patch:{recordingNodeId:e.target.value}})},disabled:c.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:f.map(e=>p(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),c.isPending&&p(_,{className:`h-4 w-4 animate-spin text-primary`})]}),o!==`hub`&&l(`p`,{className:`mt-2 text-[11px] text-amber-500`,children:[`The stream-broker is hub-only — an agent recorder pulls streams from the hub over the network. The hub's RTSP restream port must be reachable from`,` `,p(`span`,{className:`font-medium`,children:o}),`. If the auto-derived host doesn't work, set the recorder's`,p(`span`,{className:`font-medium`,children:` recordingHubHostname`}),` global setting.`]})]}),l(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[p(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Recordings folders`}),p(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where recordings are stored. Multi-location collections — segments are split across the locations of a type. Add a location to grow capacity; mark one default per type.`}),p(v,{types:[`recordings`,`recordingsLow`]})]})]})}export{v as n,x as t};
1
+ import{Ia as e,Vr as t,ca as n,fa as r,ft as i,la as a,ua as o,ut as s}from"./src-C56sOV8c.js";import{Q as c,S as l,W as u,o as d,q as f,x as p}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{n as m,r as h,t as g}from"./AddLocationWizard-C6UBIuTS.js";import{S as _}from"./index-BWLF0UML.js";c();function v({types:t}){let i=d(),s=e(),{data:c}=o({}),_=a(),v=u(()=>_.data??[],[_.data]),[y,b]=f(null),[x,S]=f(null),C=()=>{i.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})},w=r({onSuccess:C}),T=n({onSuccess:C}),E=u(()=>{let e=new Map;for(let t of c??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[c]),D=e=>{e.isDefault||w.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},O=async e=>{if(e.isDefault){await s({title:`Cannot delete default location`,message:`"${e.displayName}" is the default for type "${e.type}". Mark another as default first.`,confirmLabel:`OK`,variant:`warning`});return}await s({title:`Delete location "${e.displayName}"?`,message:`Removes the record; files on disk are untouched.`,confirmLabel:`Delete`,variant:`danger`})&&T.mutate({id:e.id})},k=t.map(e=>v.find(t=>t.id===e)).filter(e=>e!==void 0);return l(`div`,{className:`space-y-3`,children:[k.length===0?p(`p`,{className:`text-[11px] text-foreground-subtle italic`,children:`No storage locations declared for this purpose.`}):k.map(e=>p(h,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:E.get(e.id)??[],onAdd:e=>b(e),onEdit:e=>S(e),onDelete:e=>{O(e)},onSetDefault:e=>D(e)},e.id)),y!==null&&p(g,{initialType:y,onClose:()=>b(null),onCreated:()=>{C(),b(null)}}),x!==null&&p(m,{location:x,onClose:()=>S(null),onSaved:()=>{C(),S(null)}})]})}c();var y=`recorder`;function b(e,t,n){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t&&typeof e.value==`string`)return e.value;return n}function x(){let e=d(),{data:n}=t(void 0),{data:r,isLoading:a}=s({addonId:y}),o=b(r,`recordingNodeId`,`hub`),c=i({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),f=u(()=>{let e=(n??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,o,...e])].filter(Boolean)},[n,o]);return l(`div`,{className:`flex flex-col gap-6`,children:[l(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[p(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Recording node`}),p(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that records (continuous & events) and serves playback. Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),l(`div`,{className:`mt-3 flex items-center gap-2`,children:[a?p(_,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):p(`select`,{value:o,onChange:e=>{e.target.value!==o&&c.mutate({addonId:y,patch:{recordingNodeId:e.target.value}})},disabled:c.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:f.map(e=>p(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),c.isPending&&p(_,{className:`h-4 w-4 animate-spin text-primary`})]}),o!==`hub`&&l(`p`,{className:`mt-2 text-[11px] text-amber-500`,children:[`The stream-broker is hub-only — an agent recorder pulls streams from the hub over the network. The hub's RTSP restream port must be reachable from`,` `,p(`span`,{className:`font-medium`,children:o}),`. If the auto-derived host doesn't work, set the recorder's`,p(`span`,{className:`font-medium`,children:` recordingHubHostname`}),` global setting.`]})]}),l(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[p(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Recordings folders`}),p(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where recordings are stored. Multi-location collections — segments are split across the locations of a type. Add a location to grow capacity; mark one default per type.`}),p(v,{types:[`recordings`,`recordingsLow`]})]})]})}export{v as n,x as t};
@@ -1 +1 @@
1
- import{A as e,T as t,jn as n}from"./src-DvkErVKO.js";import{I as r,Q as i,S as a,W as o,q 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-DTufy7Ue.js";import{t as l}from"./plus-Bh3p9eWS.js";import{C as u,i as d}from"./index-BUv7lIS6.js";i();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]=s(m),[i,u]=s(!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))}),i&&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:n}){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:n,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(t,{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,i]=s(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:i}):c(C,{widget:r,onCancel:()=>i(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:t,onAdd:r}){let[i,o]=s(e.defaultSize),[l,u]=s(e.defaultColumns),[d,f]=s(e.defaultRows),[p,m]=s(null),{data:h}=n({},{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:()=>o(e),className:`px-3 py-1 rounded-md text-[11px] font-medium border transition-colors ${i===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:t,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:i,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{A as e,T as t,jn as n}from"./src-C56sOV8c.js";import{I as r,Q as i,S as a,W as o,q 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-DTufy7Ue.js";import{t as l}from"./plus-CPeKYQLF.js";import{C as u,i as d}from"./index-BWLF0UML.js";i();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]=s(m),[i,u]=s(!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))}),i&&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:n}){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:n,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(t,{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,i]=s(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:i}):c(C,{widget:r,onCancel:()=>i(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:t,onAdd:r}){let[i,o]=s(e.defaultSize),[l,u]=s(e.defaultColumns),[d,f]=s(e.defaultRows),[p,m]=s(null),{data:h}=n({},{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:()=>o(e),className:`px-3 py-1 rounded-md text-[11px] font-medium border transition-colors ${i===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:t,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:i,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};
@@ -0,0 +1 @@
1
+ import{Et as e,Gt as t,Ha as n,Ht as r,Ia as i,Jt as a,Kt as o,Ut as s,Vt as c,Wt as l,Yt as u,bt as d,ca as f,fa as p,la as m,qt as h,ua as g,xt as _}from"./src-C56sOV8c.js";import{I as v,Q as y,S as b,W as x,b as S,o as C,q as w,x as T,z as E}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{K as D}from"./src-4xaQB5RZ.js";import{t as O}from"./download-CAa1eJdo.js";import{i as k,n as A,r as j,t as M}from"./AddLocationWizard-C6UBIuTS.js";import{t as N}from"./AddonCollectionPage-DxnZh-wM.js";import{t as P}from"./plus-CPeKYQLF.js";import{t as F}from"./rotate-cw-DacWausQ.js";import{H as ee,I,P as te,S as L,W as R,i as z,m as B,s as V}from"./index-BWLF0UML.js";import{t as H}from"./AdminPage-Dq33XE9j.js";import{n as ne}from"./authed-media-XfBD4Ma-.js";import{t as U}from"./format-size-CO9d3C3-.js";import{t as re}from"./AdminTabs-CeRplgux.js";import{t as ie}from"./addon-display-names-DvSEQty-.js";var W=R(`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`}]]),G=R(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),K=R(`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`}]]),q=R(`file-text`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]);y();function J(){let e=C(),t=i(),{data:n,isLoading:r,isError:a}=g({}),o=m(),s=x(()=>o.data??[],[o.data]),[c,l]=w(null),[u,d]=w(null),h=f({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),_=p({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),v=e=>{e.isDefault||_.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},y=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`})&&h.mutate({id:e.id})},S=x(()=>{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||o.isLoading,D=a||o.isError;return b(H,{children:[E&&T(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),D&&T(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!E&&!D&&b(`div`,{className:`space-y-3`,children:[s.length===0&&T(`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.`}),s.map(e=>T(j,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:S.get(e.id)??[],onAdd:e=>l(e),onEdit:e=>d(e),onDelete:e=>{y(e)},onSetDefault:e=>v(e)},e.id))]}),c!==null&&T(M,{initialType:c,onClose:()=>l(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),l(null)}}),u!==null&&T(A,{location:u,onClose:()=>d(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),d(null)}})]})}y();var Y=[[`backup`,`listDestinations`]],ae=[`backup`,`listArchives`];function oe({destinationId:e,restoreSupported:t,onOpenRestoreWizard:n}){let r=C(),a=i(),{data:o,isLoading:l,isError:u}=s({destinationId:e}),d=o??[],f=c({onSuccess:()=>{r.invalidateQueries({queryKey:[[...ae]]}),r.invalidateQueries({queryKey:Y})}}),p=v(async t=>{await a({title:`Delete this archive?`,message:`Permanently deletes "${t.label??t.id}" and frees ${U(t.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&f.mutate({destinationId:e,backupId:t.id})},[a,e,f]),[m,h]=w(null),g=v(async t=>{h(t.id);try{let n=await ne(se(e,t.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${t.label??t.id}.tar.gz`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{h(null)}},[e]),_=x(()=>[...d].toSorted((e,t)=>t.createdAt-e.createdAt),[d]);return l?T(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):u?T(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):_.length===0?T(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):T(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:b(`table`,{className:`w-full text-xs min-w-[640px]`,children:[T(`thead`,{children:b(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[T(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),T(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),T(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),T(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),T(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),T(`tbody`,{children:_.map(r=>b(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[T(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:ce(r.createdAt)}),T(`td`,{className:`px-3 py-1.5 text-foreground`,children:r.label??T(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),T(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:r.locations.join(`, `)}),T(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:U(r.sizeBytes)}),T(`td`,{className:`px-3 py-1.5`,children:b(`div`,{className:`flex items-center justify-end gap-1`,children:[b(`button`,{onClick:()=>{g(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?T(L,{className:`h-3 w-3 animate-spin`}):T(O,{className:`h-3 w-3`}),`Download`]}),t&&n&&b(`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:[T(F,{className:`h-3 w-3`}),`Restore`]}),T(`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?T(L,{className:`h-3 w-3 animate-spin`}):T(V,{className:`h-3 w-3`})})]})})]},r.id))})]})})}function se(e,t){return`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function ce(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}y();var X=[{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 le(e){let t=e.trim();for(let e of X)if(e.cron===t)return e.id;return`custom`}function ue({value:e,onChange:t,previewCount:n=5,disabled:r=!1}){let i=le(e),[a,s]=w(i===`custom`);E(()=>{i!==`custom`&&s(!1)},[i]);let c=pe(e,250),l=o({cron:c,count:n},{enabled:c.trim().length>0}),u=l.data??null,d=e=>{s(!1),t(e.cron)},f=a||i===`custom`;return b(`div`,{className:`space-y-3`,children:[b(`div`,{className:`space-y-1`,children:[T(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),b(`div`,{className:`flex flex-wrap gap-1.5`,children:[X.map(e=>T(`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)),T(`button`,{type:`button`,onClick:()=>{s(!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&&b(`div`,{className:`space-y-1`,children:[T(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),T(`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`}),b(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,T(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),T(de,{cron:c,preview:u,loading:l.isFetching})]})}function de({cron:e,preview:t,loading:n}){return n&&t===null?b(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[T(L,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?T(`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.`}):b(`div`,{className:`space-y-1`,children:[T(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),T(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>b(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[T(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),T(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:fe(e)})]},`${e}-${t}`))})]}):T(`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 fe(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 pe(e,t){let[n,r]=w(e),i=x(()=>e,[e]);return E(()=>{let e=setTimeout(()=>r(i),t);return()=>clearTimeout(e)},[i,t]),n}y();var me=[[`backup`,`listDestinations`]];function he({onCreateAt:e,onOpenRestoreWizard:t}){let{data:n,isLoading:r,isError:i}=l(),a=n??[],[o,s]=w(null),c=e=>{s(t=>t===e?null:e)},u=be();return r?T(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading destinations…`}):i?T(`div`,{className:`text-xs text-danger`,children:`Failed to load destinations`}):a.length===0?T(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:T(`p`,{className:`text-xs text-foreground-subtle`,children:"No `backups`-typed storage locations registered. Add one in Settings → Storage to begin."})}):T(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:b(`table`,{className:`w-full text-xs min-w-[720px]`,children:[T(`thead`,{children:b(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[T(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),T(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Destination`}),T(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),T(`th`,{className:`text-left px-3 py-2 font-medium w-28`,children:`Retention`}),T(`th`,{className:`text-left px-3 py-2 font-medium w-56`,children:`Schedule`}),T(`th`,{className:`text-left px-3 py-2 font-medium w-44`,children:`Last success`}),T(`th`,{className:`text-right px-3 py-2 font-medium w-44`,children:`Actions`})]})}),T(`tbody`,{children:a.map(n=>{let r=u.get(n.id);return T(ge,{row:n,isOpen:o===n.id,onToggle:()=>c(n.id),onCreateAt:e,liveLastSuccessAt:r?.at,liveLastSuccessSizeBytes:r?.sizeBytes,...t?{onOpenRestoreWizard:t}:{}},n.id)})})]})})}function ge({row:e,isOpen:t,onToggle:n,onCreateAt:r,onOpenRestoreWizard:i,liveLastSuccessAt:a,liveLastSuccessSizeBytes:o}){let s=C(),c=u({onSuccess:()=>{s.invalidateQueries({queryKey:me})}}),[l,d]=w(String(e.retentionCount));E(()=>{d(String(e.retentionCount))},[e.retentionCount]);let[f,p]=w(!1),m=v(t=>{c.mutate({locationId:e.id,enabled:t,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[c,e.id,e.retentionCount,e.label,e.cron]),h=v(()=>{let t=Number.parseInt(l,10);if(Number.isNaN(t)||t<1){d(String(e.retentionCount));return}t!==e.retentionCount&&c.mutate({locationId:e.id,enabled:e.enabled,retentionCount:t,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[c,l,e.id,e.enabled,e.retentionCount,e.label,e.cron]),g=v(t=>{c.mutate({locationId:e.id,enabled:e.enabled,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},cron:t},{onSuccess:()=>{p(!1)}})},[c,e.id,e.enabled,e.retentionCount,e.label]);return b(S,{children:[b(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[T(`td`,{className:`px-2 py-2`,children:T(`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:T(t?I:te,{className:`h-3.5 w-3.5`})})}),T(`td`,{className:`px-3 py-2`,children:b(`button`,{onClick:n,className:`text-left hover:underline focus:outline-none`,title:`View archives`,children:[T(`div`,{className:`text-foreground font-medium`,children:e.displayName}),b(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[T(`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}),T(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]})}),T(`td`,{className:`px-3 py-2`,children:T(`label`,{className:`inline-flex items-center cursor-pointer`,children:T(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:c.isPending,onChange:e=>m(e.target.checked)})})}),T(`td`,{className:`px-3 py-2`,children:T(`input`,{type:`number`,min:1,max:1e3,value:l,disabled:c.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`})}),T(`td`,{className:`px-3 py-2`,children:T(_e,{cron:e.cron,nextRunAt:e.nextRunAt,onEdit:()=>p(!0),disabled:c.isPending})}),T(`td`,{className:`px-3 py-2 text-foreground-subtle`,children:(()=>{let t=xe(a,e.lastSuccessAt),n=t===a?o:e.lastSuccessSizeBytes;return t===void 0?T(`span`,{className:`italic`,children:`Never`}):T(Se,{at:t,sizeBytes:n})})()}),T(`td`,{className:`px-3 py-2`,children:T(`div`,{className:`flex items-center justify-end gap-1.5`,children:e.triggerSupported&&b(`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:[T(P,{className:`h-3 w-3`}),`Create here`]})})})]}),t&&T(`tr`,{className:`border-t border-border bg-background/30`,children:T(`td`,{colSpan:7,className:`px-4 py-3`,children:T(oe,{destinationId:e.id,restoreSupported:e.restoreSupported,...i?{onOpenRestoreWizard:i}:{}})})}),f&&T(ye,{destinationName:e.displayName,currentCron:e.cron??``,onSave:g,onClose:()=>p(!1),saving:c.isPending,saveError:c.error instanceof Error?c.error.message:null})]})}function _e({cron:e,nextRunAt:t,onEdit:n,disabled:r}){let i=typeof e==`string`&&e.trim().length>0;return b(`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:[b(`div`,{className:`flex items-center gap-1.5`,children:[T(K,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),T(`span`,{className:i?`font-mono text-foreground`:`italic text-foreground-subtle`,children:i?e:`Manual`})]}),i&&t!==void 0&&b(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[`next `,ve(t)]})]})}function ve(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 ye({destinationName:e,currentCron:t,onSave:n,onClose:r,saving:i,saveError:a}){let[o,s]=w(t);return T(`tr`,{children:T(`td`,{colSpan:7,className:`p-0`,children:T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:b(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[b(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[b(`div`,{className:`space-y-0.5`,children:[T(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Schedule`}),b(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e]})]}),T(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,title:`Close`,children:T(z,{className:`h-4 w-4`})})]}),b(`div`,{className:`p-4`,children:[T(ue,{value:o,onChange:s,disabled:i}),a!==null&&T(`div`,{className:`mt-3 rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:a})]}),b(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[T(`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`}),T(`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 be(){let{map:e}=n(D.BackupCompleted,e=>e.destinationId);return x(()=>{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 xe(e,t){return e===void 0?t:t===void 0||e>t?e:t}function Se({at:e,sizeBytes:t}){let n=Ce(e);return b(`span`,{title:x(()=>new Date(e).toLocaleString(),[e]),className:`text-foreground tabular-nums`,children:[n,t!==void 0&&b(`span`,{className:`ml-1 text-foreground-subtle`,children:[`· `,U(t)]})]})}function Ce(e){let[,t]=w(0);return E(()=>{let e=setInterval(()=>t(e=>e+1),3e4);return()=>clearInterval(e)},[]),we(e)}function we(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`}y();var Te=[[`backup`,`list`]];function Ee({initialDestinationId:e,initialArchiveId:t,onClose:n,onScheduled:i}){let a=C(),[o,c]=w(e&&t?2:1),[u,d]=w(e),[f,p]=w(t),[m,g]=w(new Set),{data:_}=l(),v=_??[],{data:y,isLoading:S}=s({destinationId:u??``},{enabled:!!u}),D=y??[];E(()=>{if(u!==void 0)return;let e=v.filter(e=>e.restoreSupported);e.length===1&&d(e[0].id)},[u,v]);let{data:O}=r({destinationId:u??``,backupId:f??``},{enabled:!!u&&!!f}),k=x(()=>O?.locations??[],[O]);E(()=>{k.length!==0&&g(e=>e.size===0?new Set(k):e)},[k]);let A=h({onSuccess:()=>{a.invalidateQueries({queryKey:Te}),i(),n()}}),j=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},M=!!u&&!!f,N=m.size>0,P=M&&N&&!A.isPending,I=()=>{!u||!f||A.mutate({destinationId:u,backupId:f,locations:[...m]})};return T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:b(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[b(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[b(`div`,{className:`space-y-0.5`,children:[T(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),b(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,o,` of 3 —`,` `,o===1?`pick source`:o===2?`pick locations`:`confirm`]})]}),T(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:T(z,{className:`h-4 w-4`})})]}),o===1&&T(De,{destinations:v,destinationId:u,onPickDestination:e=>{d(e),p(void 0),g(new Set)},archives:D,archivesLoading:S,archiveId:f,onPickArchive:p}),o===2&&T(Oe,{locations:k,picked:m,onToggle:j}),o===3&&T(ke,{destinationName:v.find(e=>e.id===u)?.displayName??u??``,archive:D.find(e=>e.id===f),picked:[...m]}),b(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[T(`div`,{children:o>1&&b(`button`,{onClick:()=>c(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:[T(ee,{className:`h-3 w-3`}),`Back`]})}),b(`div`,{className:`flex items-center gap-2`,children:[T(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),o<3?b(`button`,{disabled:o===1&&!M||o===2&&!N,onClick:()=>c(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`,T(G,{className:`h-3 w-3`})]}):b(`button`,{onClick:I,disabled:!P,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?T(L,{className:`h-3.5 w-3.5 animate-spin`}):T(F,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function De({destinations:e,destinationId:t,onPickDestination:n,archives:r,archivesLoading:i,archiveId:a,onPickArchive:o}){let s=e.filter(e=>e.restoreSupported);return b(`div`,{className:`p-4 space-y-3`,children:[b(`div`,{className:`space-y-1.5`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),b(`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:[T(`option`,{value:``,disabled:!0,children:`Select destination…`}),s.map(e=>b(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),b(`div`,{className:`space-y-1.5`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&T(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&i&&T(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!i&&r.length===0&&T(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&r.length>0&&T(`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 b(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[b(`div`,{className:`flex items-center gap-2`,children:[T(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>o(e.id),className:`accent-primary`}),b(`div`,{children:[T(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),T(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),T(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:U(e.sizeBytes)})]},e.id)})})]})]})}function Oe({locations:e,picked:t,onToggle:n}){return e.length===0?T(`div`,{className:`p-4`,children:T(`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.`})}):b(`div`,{className:`p-4 space-y-3`,children:[T(`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.`}),b(`div`,{className:`space-y-1.5`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),T(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>b(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[T(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),T(`span`,{className:`font-mono text-foreground`,children:e}),T(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:je(e)})]},e))})]})]})}function ke({destinationName:e,archive:t,picked:n}){return b(`div`,{className:`p-4 space-y-3 text-xs`,children:[T(`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.`}),b(`dl`,{className:`space-y-1.5`,children:[T(Z,{term:`Destination`,value:e}),T(Z,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&T(Z,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${U(t.sizeBytes)}`}),T(Z,{term:`Locations`,value:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function Z({term:e,value:t}){return b(`div`,{className:`flex justify-between gap-3`,children:[T(`dt`,{className:`text-foreground-subtle`,children:e}),T(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Ae={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function je(e){return Ae[e]??``}y();var Q=[[`backup`,`list`]],Me=[[`backup`,`listLocations`]];function Ne(){let n=C(),r=i(),o=a({onSuccess:()=>{n.invalidateQueries({queryKey:Q}),n.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),n.invalidateQueries({queryKey:[[`backup`,`listArchives`]]})}}),s=e(),[c,l]=w(null),{data:u}=t(void 0,{enabled:c!==null,retry:1}),[d,f]=w(null),[p,m]=w(!1),[h,g]=w(!1),[_,v]=w(!1),y=async()=>{await r({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&s.mutate({confirm:!0})};return b(H,{children:[b(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[b(`button`,{onClick:()=>m(!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:[T(F,{className:`h-3.5 w-3.5`}),`Restore…`]}),b(`button`,{onClick:()=>v(!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:[T(P,{className:`h-3.5 w-3.5`}),`Add destination`]})]}),h&&T(`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:b(`div`,{className:`flex items-center justify-between gap-3`,children:[b(`div`,{className:`flex items-center gap-2`,children:[T(F,{className:`h-3.5 w-3.5`}),T(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),b(`button`,{onClick:()=>{y()},disabled:s.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:[s.isPending?T(L,{className:`h-3.5 w-3.5 animate-spin`}):T(F,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),T(he,{onCreateAt:e=>l(e),onOpenRestoreWizard:e=>f(e)}),c&&T(Pe,{destination:c,locations:u,onClose:()=>l(null),onSubmit:(e,t)=>{o.mutate({destinations:[c.id],locations:e,label:t||void 0},{onSuccess:()=>{l(null),n.invalidateQueries({queryKey:Me})}})},submitting:o.isPending}),(d||p)&&T(Ee,{...d?{initialDestinationId:d.destinationId,initialArchiveId:d.archiveId}:{},onClose:()=>{f(null),m(!1)},onScheduled:()=>g(!0)}),_&&T(M,{initialType:`backups`,onClose:()=>v(!1),onCreated:()=>{v(!1),n.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]})}})]})}function Pe({destination:e,locations:t,onClose:n,onSubmit:r,submitting:i}){let a=(t??[]).filter(e=>e.present),[o,s]=w(``),[c,l]=w(null),u=c??new Set(a.map(e=>e.name)),d=e=>{l(t=>{let n=new Set(t??a.map(e=>e.name));return n.has(e)?n.delete(e):n.add(e),n})};return T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:b(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[b(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[b(`div`,{className:`space-y-0.5`,children:[T(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Create Backup`}),b(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e.displayName]})]}),T(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:T(z,{className:`h-4 w-4`})})]}),b(`div`,{className:`p-4 space-y-3`,children:[b(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Label (optional)`}),T(`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`})]}),b(`div`,{className:`space-y-1.5`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Include`}),b(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:[t===void 0&&b(`div`,{className:`flex items-center gap-2 px-3 py-2 text-xs text-foreground-subtle`,children:[T(L,{className:`h-3.5 w-3.5 animate-spin`}),`Calculating sizes…`]}),t!==void 0&&a.length===0&&T(`div`,{className:`px-3 py-2 text-xs text-foreground-subtle italic`,children:`Nothing to back up.`}),a.map(e=>b(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[b(`div`,{className:`flex items-center gap-2`,children:[T(`input`,{type:`checkbox`,checked:u.has(e.name),onChange:()=>d(e.name),className:`accent-primary`}),T(`span`,{className:`font-mono text-foreground`,children:e.name})]}),b(`div`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[U(e.sizeBytes),` · `,e.fileCount,` files`]})]},e.name))]})]})]}),b(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[T(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),b(`button`,{onClick:()=>r(Array.from(u),o.trim()),disabled:i||t===void 0||u.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?T(L,{className:`h-3.5 w-3.5 animate-spin`}):T(W,{className:`h-3.5 w-3.5`}),i?`Creating…`:`Create`]})]})]})})}y();var $=5e3,Fe={"winston-logging":`Rotated log files on this node’s disk.`,"console-logging":`stdout / stderr of the node process.`,"loki-logging":`Pushes to a Grafana Loki instance. Off until enabled with a URL.`,"hub-forwarder":`Agent-only — forwards this node’s entries to the hub.`};function Ie(){let e=_({capName:`log-destination`},{refetchInterval:$}),t=d(void 0,{refetchInterval:$}),n=x(()=>ie(t.data??[]),[t.data]),r=x(()=>{let e=new Map;for(let n of t.data??[]){let t=n.description,r=n.id;typeof r==`string`&&typeof t==`string`&&t.length>0&&e.set(r,t)}return e},[t.data]);return T(N,{title:`Logging`,subtitle:`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another. Each destination's own configuration is docked under it.`,pageIcon:B,itemIcon:q,capability:`log-destination`,installButtonLabel:`Add destination`,items:x(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive,caption:r.get(e.addonId)??Fe[e.addonId]??``})),[e.data,n,r]),isLoading:e.isLoading,emptyTitle:`No log destinations registered`,emptyDescription:`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`,renderStatusBadges:e=>e.caption.length>0?T(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.caption}):null})}function Le(){return T(`div`,{className:`flex flex-col p-4`,children:T(re,{tabs:[{id:`storage`,label:`Storage`,icon:k,content:T(J,{})},{id:`backup`,label:`Backup`,icon:W,content:T(Ne,{})},{id:`logging`,label:`Logging`,icon:B,content:T(Ie,{})}]})})}export{Le as DataPage};
@@ -1 +1 @@
1
- import{$n as e,Ia as t,Jn as n,Qn as r,Ua as i,Xn as a,Yn as o,Zn as s,ar as c,bo as l,do as u,er as d,fo as f,ho as p,ir as m,jn as h,mo as g,nr as _,po as v,qn as y,rr as b,tr as x,uo as S,vo as C,xo as w}from"./src-DvkErVKO.js";import{K as T,Q as E,S as D,W as O,b as k,o as A,q as j,x as M,z as N}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{K as P}from"./src-GxiMH1Sc.js";import{a as F,i as I,n as L,r as ee,t as R}from"./face-bbox-D8rphF63.js";import{a as z,c as te,f as B,i as V,l as ne,m as H,n as re,o as ie,p as U,r as ae,s as oe,t as se,u as ce}from"./debounced-invalidate-D-KI_sbM.js";import{t as W}from"./pencil-BkLlKSmd.js";import{t as G}from"./plus-Bh3p9eWS.js";import{t as le}from"./refresh-cw-BdQgnZ_R.js";import{t as ue}from"./square-check-big-CA6GbSkt.js";import{t as de}from"./square-CcjBMK42.js";import{I as K,L as q,P as fe,S as J,W as pe,h as me,i as Y,l as he,s as X}from"./index-BUv7lIS6.js";import{t as Z}from"./AdminPage-BwmGKnRf.js";import{n as Q,t as ge}from"./authed-media-XfBD4Ma-.js";var _e=pe(`undo-2`,[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]),ve=pe(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]);E();var $=[[`faceGallery`]];function ye({identityId:t}){let n=A(),{data:r,isLoading:i}=e({identityId:t}),a=x();function o(e){a.mutate({identityId:t,sampleId:e.id},{onSettled:()=>{n.invalidateQueries({queryKey:$})}})}return i?D(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[M(J,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!r||r.length===0?M(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):M(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:r.map(e=>D(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?M(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):M(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:M(ve,{className:`h-6 w-6`})}),M(`button`,{type:`button`,onClick:()=>o(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:M(Y,{className:`h-4 w-4 text-white`})})]},e.id))})}function be({identity:e,expanded:t,onToggle:n}){let r=A(),[i,o]=j(``),[s,c]=j(!1),[d,m]=j(!1),h=_(),y=a();function b(){o(e.name),c(!0)}function x(){c(!1),o(``)}function T(){let t=i.trim();if(!t||t===e.name){x();return}h.mutate({id:e.id,name:t},{onSettled:()=>{r.invalidateQueries({queryKey:$}),x()}})}function E(){y.mutate({id:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:$}),m(!1)}})}return D(`div`,{className:`rounded-md border border-border bg-surface`,children:[D(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[M(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:e.coverBase64?M(`img`,{src:`data:image/jpeg;base64,${e.coverBase64}`,alt:e.name,className:`h-full w-full object-cover`}):M(`div`,{className:`flex h-full w-full items-center justify-center`,children:M(ve,{className:`h-4 w-4 text-foreground-subtle`})})}),M(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:s?D(k,{children:[M(C,{value:i,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T(),e.key===`Escape`&&x()},className:`h-6 text-xs`,autoFocus:!0}),M(`button`,{type:`button`,onClick:T,disabled:h.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:M(q,{className:`h-3.5 w-3.5`})}),M(`button`,{type:`button`,onClick:x,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:M(Y,{className:`h-3.5 w-3.5`})})]}):M(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),M(l,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!s&&D(`div`,{className:`flex items-center gap-1`,children:[M(`button`,{type:`button`,onClick:b,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:M(W,{className:`h-3.5 w-3.5`})}),M(`button`,{type:`button`,onClick:()=>m(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:M(X,{className:`h-3.5 w-3.5`})})]}),M(`button`,{type:`button`,onClick:n,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:M(t?K:fe,{className:`h-3.5 w-3.5`})})]}),t&&M(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:M(ye,{identityId:e.id})}),M(S,{open:d,onOpenChange:e=>!e&&m(!1),children:D(u,{children:[D(g,{children:[M(p,{children:`Delete person`}),D(f,{children:[`Delete `,M(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),D(v,{children:[M(w,{variant:`secondary`,onClick:()=>m(!1),children:`Cancel`}),D(w,{variant:`danger`,onClick:E,disabled:y.isPending,children:[y.isPending?M(J,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function xe(){let e=A(),[t,r]=j(``),i=n();function a(){let n=t.trim();n&&i.mutate({name:n},{onSettled:()=>{e.invalidateQueries({queryKey:$}),r(``)}})}return D(`div`,{className:`flex items-center gap-2 pt-2`,children:[M(C,{placeholder:`New person name…`,value:t,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&a()},className:`h-7 text-xs flex-1`}),D(w,{variant:`primary`,size:`sm`,onClick:a,disabled:i.isPending||!t.trim(),children:[i.isPending?M(J,{className:`h-3.5 w-3.5 animate-spin`}):M(G,{className:`h-3.5 w-3.5`}),`Add`]})]})}function Se(){let{data:e,isLoading:t}=r(),[n,i]=j(null);function a(e){i(t=>t===e?null:e)}return t?D(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[M(J,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):D(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&M(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>M(be,{identity:e,expanded:n===e.id,onToggle:()=>a(e.id)},e.id)),M(xe,{})]})}function Ce(e){return e.base64===void 0||e.base64.length===0}function we(e){return e.filter(Ce).map(e=>e.faceId)}function Te(e){let t=0;for(let n of e)Ce(n)&&(t+=1);return t}E();function Ee(e){let[t,n]=j(null),[r,i]=j(null),[a,o]=j(!1);return N(()=>{if(n(null),i(null),o(!1),!e)return;let t=!1,r=null;return(async()=>{try{let i=await Q(`${ge}/${encodeURIComponent(e)}`);if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),N(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>o(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function De(e){let t=e.filter(e=>e.base64.length>0);return t.length===0?null:t.find(e=>/crop|face/i.test(e.kind))??t[0]}function Oe({label:e,value:t}){return D(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[M(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),M(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:t})]})}function ke({box:e}){return M(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:M(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Face`})})}function Ae({face:e,cameraName:t,onClose:n,onAssign:r,onUnassign:i,onDelete:a,actionsPending:o}){let{data:c,isFetching:l}=s({faceId:e?.faceId??``},{enabled:e!==null}),[d,f]=j(`frame`),{frameSrc:p,naturalWidth:m,naturalHeight:h,failed:g}=Ee(e?.keyFrameMediaKey),_=O(()=>{let t=De(c??[]);return t?`data:image/jpeg;base64,${t.base64}`:e?.base64?`data:image/jpeg;base64,${e.base64}`:null},[c,e]),v=O(()=>!e?.faceBbox||m===null||h===null?null:R(e.faceBbox,m,h),[e?.faceBbox,m,h]);if(e===null)return null;let y=typeof e.keyFrameMediaKey==`string`&&e.keyFrameMediaKey.length>0&&!g,b=y&&d===`frame`,x=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return M(S,{open:!0,onOpenChange:e=>!e&&n(),children:D(u,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Face detail`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[D(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[D(`div`,{className:`min-w-0`,children:[M(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:`Face detail`}),M(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),M(`button`,{type:`button`,onClick:n,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:M(Y,{className:`h-4 w-4`})})]}),D(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[y&&D(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[D(`button`,{type:`button`,onClick:()=>f(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${d===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(I,{className:`h-3.5 w-3.5`}),` Full frame`]}),D(`button`,{type:`button`,onClick:()=>f(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${d===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(F,{className:`h-3.5 w-3.5`}),` Crop`]})]}),b&&p?M(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:M(V,{src:p,alt:`Full frame with detected face`,fit:`natural`,className:`w-full`,overlay:v?M(ke,{box:v}):void 0})}):_?D(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[M(V,{src:_,alt:`Detected face`,className:`h-full w-full`}),l&&M(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:M(J,{className:`h-3.5 w-3.5 animate-spin`})})]}):D(`div`,{className:`flex aspect-square w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[M(H,{className:`h-8 w-8 text-warning/70`}),M(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),M(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:`The crop media for this face could not be resolved (a pre-fix orphan). Safe to delete.`})]}),D(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[M(Oe,{label:`Camera`,value:t}),M(Oe,{label:`Captured`,value:U(e.timestamp)}),M(Oe,{label:`Track`,value:e.trackId}),M(Oe,{label:`Identity`,value:x})]})]}),D(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[e.assigned?D(w,{variant:`secondary`,onClick:()=>i(e.faceId),disabled:o,children:[M(L,{className:`h-3.5 w-3.5`}),` Detach`]}):D(w,{variant:`primary`,onClick:()=>r(e.faceId),disabled:o,children:[M(ee,{className:`h-3.5 w-3.5`}),` Assign`]}),D(w,{variant:`secondary`,onClick:()=>a(e.faceId),disabled:o,children:[M(X,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}E();var je=[[`faceGallery`]];function Me({faceIds:e,identities:t,onDone:r}){let i=A(),a=y(),o=n(),[s,c]=j(``),[l,d]=j(!1),[m,h]=j(null),_=e!==null&&e.length>0,b=e?.length??0;function x(){d(!1),c(``),h(null)}function T(){x(),r()}function E(t){!e||e.length===0||a.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{i.invalidateQueries({queryKey:je}),T()}})}function O(){!e||!s.trim()||o.mutate({name:s.trim()},{onSuccess:e=>{e?.id&&E(e.id)},onError:()=>{i.invalidateQueries({queryKey:je}),T()}})}let k=a.isPending||o.isPending;return M(S,{open:_,onOpenChange:e=>!e&&T(),children:D(u,{children:[D(g,{children:[M(p,{children:b>1?`Assign ${String(b)} faces to person`:`Assign face to person`}),M(f,{children:`Select an existing person or create a new one.`})]}),M(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>D(`button`,{type:`button`,onClick:()=>h(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:[M(`span`,{className:`font-medium`,children:e.name}),D(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),l?M(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:M(C,{placeholder:`New person name…`,value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&O()},autoFocus:!0,className:`flex-1`})}):M(`button`,{type:`button`,onClick:()=>{h(null),d(!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…`}),D(v,{children:[M(w,{variant:`secondary`,onClick:T,disabled:k,children:`Cancel`}),l?D(w,{variant:`primary`,onClick:O,disabled:k||!s.trim(),children:[k&&M(J,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):D(w,{variant:`primary`,onClick:()=>m&&E(m),disabled:k||!m,children:[k&&M(J,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,b>1?` ${String(b)}`:``]})]})]})})}function Ne(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Pe(e,t){return e.faceIds.filter(e=>!t.has(e))}function Fe(e,t){return e.faceIds.filter(e=>t(e))}E();var Ie=[[`faceGallery`]],Le=20,Re=.3,ze=.9,Be=.05,Ve=.5,He=2,Ue=10,We=2;function Ge({cluster:e,face:t,active:n,onSelect:r}){return D(`button`,{type:`button`,onClick:r,className:`flex shrink-0 flex-col items-center gap-1.5 rounded-md border p-2 text-center transition-colors md:w-full md:flex-row md:gap-2.5 md:text-left ${n?`border-primary bg-primary/8`:`border-border bg-surface hover:bg-surface-hover`}`,children:[M(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:t?.base64?M(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:``,className:`h-24 w-24 object-cover`}):M(H,{className:`h-24 w-24 p-6 text-foreground-subtle`})}),D(`span`,{className:`w-24 text-[11px] leading-tight text-foreground-subtle md:w-auto`,children:[e.size,` faces · `,Math.round(e.cohesion*100),`% alike`]})]})}function Ke({face:e,cameraName:t,nowMs:n,excluded:r,onToggleExclude:i,onDelete:a,deletePending:o}){return D(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${r?`border-border opacity-40 grayscale`:`border-border`}`,children:[D(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?M(V,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face from ${t}`,className:`h-full w-full`}):D(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[M(H,{className:`h-7 w-7 text-warning/70`}),M(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}),M(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":r?`Include face`:`Exclude face`,title:r?`Include`:`Exclude`,children:M(r?_e:Y,{className:`h-3.5 w-3.5`})})]}),D(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[M(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),M(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:B(e.timestamp,n)})]}),M(`div`,{className:`mt-1 flex items-center justify-end border-t border-border/60 px-1 py-0.5`,children:M(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},disabled:o,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete face`,title:`Delete face`,children:o?M(J,{className:`h-4 w-4 animate-spin`}):M(X,{className:`h-4 w-4`})})})]})}function qe({open:e,onClose:n,byId:r,cameraName:i,nowMs:a,identities:s,selectMany:c}){let l=A(),d=t(),f=o(),[p,m]=j(Ve),[h,g]=j(We),[_,v]=j(null),[y,x]=j({}),[C,T]=j(null),{data:E,isFetching:P,refetch:F}=b({threshold:p,minClusterSize:h,limit:Le},{enabled:e}),I=E??[];N(()=>{x({})},[p,h]),N(()=>{if(I.length===0){v(null);return}I.some(e=>e.representativeFaceId===_)||v(I[0]?.representativeFaceId??null)},[I]);let L=O(()=>I.find(e=>e.representativeFaceId===_)??null,[I,_]),R=L?y[L.representativeFaceId]??new Set:new Set,z=O(()=>L?Fe(L,e=>r.has(e)):[],[L,r]),te=L?L.faceIds.length-z.length:0,B=L?Pe({...L,faceIds:z},R):[];function V(e){if(!L)return;let t=L.representativeFaceId;x(n=>({...n,[t]:Ne(n[t]??new Set,e)}))}function ne(){l.invalidateQueries({queryKey:Ie})}async function H(e){await d({title:`Delete face`,message:`Permanently deletes this face crop. This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&f.mutate({faceId:e},{onSettled:ne})}function re(){T(null),n()}function ie(){B.length!==0&&(c(B),re())}return D(S,{open:e,onOpenChange:e=>!e&&re(),children:[D(u,{placement:`sheet-on-mobile`,width:`lg`,"aria-label":`Look-alike groups`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 md:max-w-4xl`,children:[D(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border px-4 py-3`,children:[D(`div`,{className:`flex items-center justify-between gap-2`,children:[D(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[M(he,{className:`h-4 w-4 text-primary`}),` Look-alike groups`]}),M(`button`,{type:`button`,onClick:re,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:M(Y,{className:`h-4 w-4`})})]}),D(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[D(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Threshold`,M(`input`,{type:`range`,min:Re,max:ze,step:Be,value:p,onChange:e=>m(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),M(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:p.toFixed(2)})]}),D(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Min size`,M(`input`,{type:`number`,min:He,max:Ue,step:1,value:h,onChange:e=>g(Math.min(Ue,Math.max(He,Number(e.target.value)||He))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),D(w,{variant:`secondary`,onClick:()=>{x({}),F()},disabled:P,children:[P?M(J,{className:`h-3.5 w-3.5 animate-spin`}):M(le,{className:`h-3.5 w-3.5`}),`Re-analyze`]})]})]}),M(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:P&&I.length===0?D(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[M(J,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):I.length===0?M(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:`No look-alike groups at this threshold.`}):D(k,{children:[M(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:I.map(e=>M(Ge,{cluster:e,face:r.get(e.representativeFaceId),active:e.representativeFaceId===_,onSelect:()=>v(e.representativeFaceId)},e.representativeFaceId))}),M(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:I.map(e=>M(Ge,{cluster:e,face:r.get(e.representativeFaceId),active:e.representativeFaceId===_,onSelect:()=>v(e.representativeFaceId)},e.representativeFaceId))}),M(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:L&&D(k,{children:[te>0&&D(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:[te,` not loaded — excluded from actions`]}),M(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,1fr))] gap-2`,children:z.map(e=>{let t=r.get(e);return t?M(Ke,{face:t,cameraName:i(t.deviceId),nowMs:a,excluded:R.has(e),onToggleExclude:()=>V(e),onDelete:()=>void H(e),deletePending:f.isPending&&f.variables?.faceId===e},e):null})})]})})]})}),D(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[M(w,{variant:`secondary`,onClick:ie,disabled:B.length===0,children:`Select in gallery`}),D(w,{variant:`primary`,onClick:()=>T(B),disabled:B.length===0,children:[M(ee,{className:`h-3.5 w-3.5`}),` Adopt (`,B.length,`)`]})]})]}),M(Me,{faceIds:C,identities:s,onDone:()=>T(null)})]})}E();var Je=[[`faceGallery`]],Ye=500,Xe=120;function Ze({face:e,cameraName:t,nowMs:n,selected:r,onToggleSelect:i,onAssign:a,onOpenDetail:s}){let c=A(),l=m(),u=o(),d=()=>{c.invalidateQueries({queryKey:Je})},f=()=>s(e.faceId);return D(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${r?`border-primary ring-1 ring-primary`:`border-border`}`,children:[D(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?M(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face from ${t}`,onClick:f,className:`h-full w-full cursor-zoom-in object-cover`}):D(`button`,{type:`button`,onClick:f,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:`No crop image — the face's crop media is missing (a pre-fix orphan). Safe to delete.`,children:[M(H,{className:`h-7 w-7 text-warning/70`}),M(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}),M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(e.faceId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":r?`Deselect`:`Select`,children:r?M(ue,{className:`h-4 w-4 text-primary`}):M(de,{className:`h-4 w-4`})})]}),D(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[M(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),M(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:B(e.timestamp,n)}),e.identityName&&M(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]}),D(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),l.mutate({faceId:e.faceId},{onSettled:d})},disabled:l.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":`Detach face`,title:`Detach`,children:l.isPending?M(J,{className:`h-4 w-4 animate-spin`}):M(L,{className:`h-4 w-4`})}):M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(e.faceId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":`Assign face to person`,title:`Assign to person`,children:M(ee,{className:`h-4 w-4`})}),M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),u.mutate({faceId:e.faceId},{onSettled:d})},disabled:u.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete face`,title:`Delete face`,children:u.isPending?M(J,{className:`h-4 w-4 animate-spin`}):M(X,{className:`h-4 w-4`})})]})]})}var Qe=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function $e(){let e=A(),[t,n]=j(`all`),[i,a]=j(oe),[s,l]=j(new Set),[u,f]=j(new Set),[p,g]=j(null),[_,v]=j(!1),[b,x]=j(null),{data:S,isLoading:C}=d({limit:Ye,filter:t},{refetchInterval:3e4}),{data:T=[]}=r(),{data:E}=h({}),N=y(),P=m(),F=c(),I=o(),R=Date.now(),B=S??[],V=O(()=>{let e=new Map;for(let t of E??[])e.set(t.id,t.name);return e},[E]),U=e=>V.get(e)??`Camera #${String(e)}`,se=O(()=>te(B).map(e=>({id:e,name:U(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[B,V]),W=O(()=>ne(ce(B,i),s),[B,i,s]),G=re(W,Xe,O(()=>JSON.stringify([t,i.fromMs,i.toMs,[...s].sort((e,t)=>e-t)]),[t,i.fromMs,i.toMs,s])),le=O(()=>new Map(B.map(e=>[e.faceId,e])),[B]),ue=O(()=>Te(W),[W]),de=b===null?null:le.get(b)??null,K=()=>{e.invalidateQueries({queryKey:Je})},q=()=>f(new Set);function fe(e){f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function pe(e){f(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function me(){pe(we(W))}let Z=[...u],Q=N.isPending||F.isPending||I.isPending,ge=P.isPending||I.isPending;function _e(){Z.length!==0&&F.mutate({faceIds:Z},{onSettled:()=>{K(),q()}})}function ve(){Z.length!==0&&Promise.allSettled(Z.map(e=>I.mutateAsync({faceId:e}))).then(()=>{K(),q()})}function $(e){x(null),g([e])}function ye(e){P.mutate({faceId:e},{onSettled:K}),x(null)}function be(e){I.mutate({faceId:e},{onSettled:K}),x(null)}let xe=W.length!==B.length;return D(`div`,{className:`relative space-y-3`,children:[D(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[M(`div`,{className:`flex items-center gap-1`,children:Qe.map(e=>M(`button`,{type:`button`,onClick:()=>n(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${t===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),M(z,{onChange:a}),M(ie,{cameras:se,selected:s,onChange:l}),D(`button`,{type:`button`,onClick:()=>v(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${_?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(he,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!C&&ue>0&&D(`button`,{type:`button`,onClick:me,className:`ml-auto flex items-center gap-1 rounded-md px-2.5 py-1 text-xs text-warning/90 transition-colors hover:bg-warning/10`,title:`Select every visible face whose crop image is missing so you can delete the orphans in one pass`,children:[M(H,{className:`h-3.5 w-3.5`}),` Select `,ue,` crop-less`]}),!C&&M(`span`,{className:`text-[10px] text-foreground-subtle ${ue>0?`ml-2`:`ml-auto`}`,children:xe?`${String(W.length)} of ${String(B.length)} faces`:`${String(W.length)} face${W.length===1?``:`s`}`})]}),u.size>0&&D(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[D(`span`,{className:`text-xs font-medium text-foreground`,children:[u.size,` selected`]}),D(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[D(w,{variant:`primary`,onClick:()=>g(Z),disabled:Q,children:[M(ee,{className:`h-3.5 w-3.5`}),` Assign`]}),D(w,{variant:`secondary`,onClick:_e,disabled:Q,children:[F.isPending?M(J,{className:`h-3.5 w-3.5 animate-spin`}):M(L,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),D(w,{variant:`secondary`,onClick:ve,disabled:Q,children:[M(X,{className:`h-3.5 w-3.5`}),` Delete`]}),M(w,{variant:`ghost`,onClick:q,disabled:Q,children:M(Y,{className:`h-3.5 w-3.5`})})]})]}),C&&D(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[M(J,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!C&&W.length===0&&M(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:B.length>0?`No faces match the current date / camera filters.`:`No faces found for this filter.`}),!C&&W.length>0&&D(k,{children:[M(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(6.5rem,1fr))] gap-2`,children:G.pageItems.map(e=>M(Ze,{face:e,cameraName:U(e.deviceId),nowMs:R,selected:u.has(e.faceId),onToggleSelect:fe,onAssign:e=>g([e]),onOpenDetail:x},e.faceId))}),M(ae,{currentPage:G.page,totalItems:G.totalItems,pageSize:G.pageSize,onPageChange:G.setPage,itemNoun:`faces`})]}),M(Ae,{face:de,cameraName:de?U(de.deviceId):``,onClose:()=>x(null),onAssign:$,onUnassign:ye,onDelete:be,actionsPending:ge}),M(Me,{faceIds:p,identities:T,onDone:()=>{g(null),q()}}),M(qe,{open:_,onClose:()=>v(!1),byId:le,cameraName:U,nowMs:R,identities:T,selectMany:pe})]})}E();var et=[[`faceGallery`]],tt=2e3;function nt(){let e=A(),t=T(e);t.current=e;let n=T(void 0);n.current||=se({delayMs:tt,invalidate:()=>{t.current.invalidateQueries({queryKey:et})}}),N(()=>()=>n.current?.cancel(),[]),i(P.PipelineAnalyticsFaceGalleryChanged,()=>{n.current?.trigger()})}function rt(){return nt(),M(Z,{icon:me,title:`Faces`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:D(`section`,{className:`space-y-3`,children:[D(`div`,{children:[M(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),M(`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.`}),M(Se,{})]}),D(`div`,{className:`pt-4 border-t border-border`,children:[M(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),M(`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.`}),M($e,{})]})]})})}export{rt as DetectionIntelligencePage};
1
+ import{$n as e,Ia as t,Jn as n,Qn as r,Ua as i,Xn as a,Yn as o,Zn as s,ar as c,bo as l,do as u,er as d,fo as f,ho as p,ir as m,jn as h,mo as g,nr as _,po as v,qn as y,rr as b,tr as x,uo as S,vo as C,xo as w}from"./src-C56sOV8c.js";import{K as T,Q as E,S as D,W as O,b as k,o as A,q as j,x as M,z as N}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{K as P}from"./src-4xaQB5RZ.js";import{a as F,i as I,n as L,r as ee,t as R}from"./face-bbox-U4Diy0fI.js";import{a as z,c as te,f as B,i as V,l as ne,m as H,n as re,o as ie,p as U,r as ae,s as oe,t as se,u as ce}from"./debounced-invalidate-Dg1JokGS.js";import{t as W}from"./pencil-QENELNzs.js";import{t as G}from"./plus-CPeKYQLF.js";import{t as le}from"./refresh-cw-B3fSkJoP.js";import{t as ue}from"./square-check-big-CGX9b-bD.js";import{t as de}from"./square-CcV1_Dk6.js";import{I as K,L as q,P as fe,S as J,W as pe,h as me,i as Y,l as he,s as X}from"./index-BWLF0UML.js";import{t as Z}from"./AdminPage-Dq33XE9j.js";import{n as Q,t as ge}from"./authed-media-XfBD4Ma-.js";var _e=pe(`undo-2`,[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]),ve=pe(`user-round`,[[`circle`,{cx:`12`,cy:`8`,r:`5`,key:`1hypcn`}],[`path`,{d:`M20 21a8 8 0 0 0-16 0`,key:`rfgkzh`}]]);E();var $=[[`faceGallery`]];function ye({identityId:t}){let n=A(),{data:r,isLoading:i}=e({identityId:t}),a=x();function o(e){a.mutate({identityId:t,sampleId:e.id},{onSettled:()=>{n.invalidateQueries({queryKey:$})}})}return i?D(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[M(J,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!r||r.length===0?M(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):M(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:r.map(e=>D(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?M(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):M(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:M(ve,{className:`h-6 w-6`})}),M(`button`,{type:`button`,onClick:()=>o(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:M(Y,{className:`h-4 w-4 text-white`})})]},e.id))})}function be({identity:e,expanded:t,onToggle:n}){let r=A(),[i,o]=j(``),[s,c]=j(!1),[d,m]=j(!1),h=_(),y=a();function b(){o(e.name),c(!0)}function x(){c(!1),o(``)}function T(){let t=i.trim();if(!t||t===e.name){x();return}h.mutate({id:e.id,name:t},{onSettled:()=>{r.invalidateQueries({queryKey:$}),x()}})}function E(){y.mutate({id:e.id},{onSettled:()=>{r.invalidateQueries({queryKey:$}),m(!1)}})}return D(`div`,{className:`rounded-md border border-border bg-surface`,children:[D(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[M(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:e.coverBase64?M(`img`,{src:`data:image/jpeg;base64,${e.coverBase64}`,alt:e.name,className:`h-full w-full object-cover`}):M(`div`,{className:`flex h-full w-full items-center justify-center`,children:M(ve,{className:`h-4 w-4 text-foreground-subtle`})})}),M(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:s?D(k,{children:[M(C,{value:i,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T(),e.key===`Escape`&&x()},className:`h-6 text-xs`,autoFocus:!0}),M(`button`,{type:`button`,onClick:T,disabled:h.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:M(q,{className:`h-3.5 w-3.5`})}),M(`button`,{type:`button`,onClick:x,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:M(Y,{className:`h-3.5 w-3.5`})})]}):M(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),M(l,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!s&&D(`div`,{className:`flex items-center gap-1`,children:[M(`button`,{type:`button`,onClick:b,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:M(W,{className:`h-3.5 w-3.5`})}),M(`button`,{type:`button`,onClick:()=>m(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:M(X,{className:`h-3.5 w-3.5`})})]}),M(`button`,{type:`button`,onClick:n,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:M(t?K:fe,{className:`h-3.5 w-3.5`})})]}),t&&M(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:M(ye,{identityId:e.id})}),M(S,{open:d,onOpenChange:e=>!e&&m(!1),children:D(u,{children:[D(g,{children:[M(p,{children:`Delete person`}),D(f,{children:[`Delete `,M(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),D(v,{children:[M(w,{variant:`secondary`,onClick:()=>m(!1),children:`Cancel`}),D(w,{variant:`danger`,onClick:E,disabled:y.isPending,children:[y.isPending?M(J,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function xe(){let e=A(),[t,r]=j(``),i=n();function a(){let n=t.trim();n&&i.mutate({name:n},{onSettled:()=>{e.invalidateQueries({queryKey:$}),r(``)}})}return D(`div`,{className:`flex items-center gap-2 pt-2`,children:[M(C,{placeholder:`New person name…`,value:t,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&a()},className:`h-7 text-xs flex-1`}),D(w,{variant:`primary`,size:`sm`,onClick:a,disabled:i.isPending||!t.trim(),children:[i.isPending?M(J,{className:`h-3.5 w-3.5 animate-spin`}):M(G,{className:`h-3.5 w-3.5`}),`Add`]})]})}function Se(){let{data:e,isLoading:t}=r(),[n,i]=j(null);function a(e){i(t=>t===e?null:e)}return t?D(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[M(J,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):D(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&M(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>M(be,{identity:e,expanded:n===e.id,onToggle:()=>a(e.id)},e.id)),M(xe,{})]})}function Ce(e){return e.base64===void 0||e.base64.length===0}function we(e){return e.filter(Ce).map(e=>e.faceId)}function Te(e){let t=0;for(let n of e)Ce(n)&&(t+=1);return t}E();function Ee(e){let[t,n]=j(null),[r,i]=j(null),[a,o]=j(!1);return N(()=>{if(n(null),i(null),o(!1),!e)return;let t=!1,r=null;return(async()=>{try{let i=await Q(`${ge}/${encodeURIComponent(e)}`);if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),N(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>o(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function De(e){let t=e.filter(e=>e.base64.length>0);return t.length===0?null:t.find(e=>/crop|face/i.test(e.kind))??t[0]}function Oe({label:e,value:t}){return D(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[M(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),M(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:t})]})}function ke({box:e}){return M(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:M(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Face`})})}function Ae({face:e,cameraName:t,onClose:n,onAssign:r,onUnassign:i,onDelete:a,actionsPending:o}){let{data:c,isFetching:l}=s({faceId:e?.faceId??``},{enabled:e!==null}),[d,f]=j(`frame`),{frameSrc:p,naturalWidth:m,naturalHeight:h,failed:g}=Ee(e?.keyFrameMediaKey),_=O(()=>{let t=De(c??[]);return t?`data:image/jpeg;base64,${t.base64}`:e?.base64?`data:image/jpeg;base64,${e.base64}`:null},[c,e]),v=O(()=>!e?.faceBbox||m===null||h===null?null:R(e.faceBbox,m,h),[e?.faceBbox,m,h]);if(e===null)return null;let y=typeof e.keyFrameMediaKey==`string`&&e.keyFrameMediaKey.length>0&&!g,b=y&&d===`frame`,x=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return M(S,{open:!0,onOpenChange:e=>!e&&n(),children:D(u,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Face detail`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[D(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[D(`div`,{className:`min-w-0`,children:[M(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:`Face detail`}),M(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),M(`button`,{type:`button`,onClick:n,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:M(Y,{className:`h-4 w-4`})})]}),D(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[y&&D(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[D(`button`,{type:`button`,onClick:()=>f(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${d===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(I,{className:`h-3.5 w-3.5`}),` Full frame`]}),D(`button`,{type:`button`,onClick:()=>f(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${d===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(F,{className:`h-3.5 w-3.5`}),` Crop`]})]}),b&&p?M(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:M(V,{src:p,alt:`Full frame with detected face`,fit:`natural`,className:`w-full`,overlay:v?M(ke,{box:v}):void 0})}):_?D(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[M(V,{src:_,alt:`Detected face`,className:`h-full w-full`}),l&&M(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:M(J,{className:`h-3.5 w-3.5 animate-spin`})})]}):D(`div`,{className:`flex aspect-square w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[M(H,{className:`h-8 w-8 text-warning/70`}),M(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),M(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:`The crop media for this face could not be resolved (a pre-fix orphan). Safe to delete.`})]}),D(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[M(Oe,{label:`Camera`,value:t}),M(Oe,{label:`Captured`,value:U(e.timestamp)}),M(Oe,{label:`Track`,value:e.trackId}),M(Oe,{label:`Identity`,value:x})]})]}),D(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[e.assigned?D(w,{variant:`secondary`,onClick:()=>i(e.faceId),disabled:o,children:[M(L,{className:`h-3.5 w-3.5`}),` Detach`]}):D(w,{variant:`primary`,onClick:()=>r(e.faceId),disabled:o,children:[M(ee,{className:`h-3.5 w-3.5`}),` Assign`]}),D(w,{variant:`secondary`,onClick:()=>a(e.faceId),disabled:o,children:[M(X,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}E();var je=[[`faceGallery`]];function Me({faceIds:e,identities:t,onDone:r}){let i=A(),a=y(),o=n(),[s,c]=j(``),[l,d]=j(!1),[m,h]=j(null),_=e!==null&&e.length>0,b=e?.length??0;function x(){d(!1),c(``),h(null)}function T(){x(),r()}function E(t){!e||e.length===0||a.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{i.invalidateQueries({queryKey:je}),T()}})}function O(){!e||!s.trim()||o.mutate({name:s.trim()},{onSuccess:e=>{e?.id&&E(e.id)},onError:()=>{i.invalidateQueries({queryKey:je}),T()}})}let k=a.isPending||o.isPending;return M(S,{open:_,onOpenChange:e=>!e&&T(),children:D(u,{children:[D(g,{children:[M(p,{children:b>1?`Assign ${String(b)} faces to person`:`Assign face to person`}),M(f,{children:`Select an existing person or create a new one.`})]}),M(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>D(`button`,{type:`button`,onClick:()=>h(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:[M(`span`,{className:`font-medium`,children:e.name}),D(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),l?M(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:M(C,{placeholder:`New person name…`,value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&O()},autoFocus:!0,className:`flex-1`})}):M(`button`,{type:`button`,onClick:()=>{h(null),d(!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…`}),D(v,{children:[M(w,{variant:`secondary`,onClick:T,disabled:k,children:`Cancel`}),l?D(w,{variant:`primary`,onClick:O,disabled:k||!s.trim(),children:[k&&M(J,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):D(w,{variant:`primary`,onClick:()=>m&&E(m),disabled:k||!m,children:[k&&M(J,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,b>1?` ${String(b)}`:``]})]})]})})}function Ne(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Pe(e,t){return e.faceIds.filter(e=>!t.has(e))}function Fe(e,t){return e.faceIds.filter(e=>t(e))}E();var Ie=[[`faceGallery`]],Le=20,Re=.3,ze=.9,Be=.05,Ve=.5,He=2,Ue=10,We=2;function Ge({cluster:e,face:t,active:n,onSelect:r}){return D(`button`,{type:`button`,onClick:r,className:`flex shrink-0 flex-col items-center gap-1.5 rounded-md border p-2 text-center transition-colors md:w-full md:flex-row md:gap-2.5 md:text-left ${n?`border-primary bg-primary/8`:`border-border bg-surface hover:bg-surface-hover`}`,children:[M(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:t?.base64?M(`img`,{src:`data:image/jpeg;base64,${t.base64}`,alt:``,className:`h-24 w-24 object-cover`}):M(H,{className:`h-24 w-24 p-6 text-foreground-subtle`})}),D(`span`,{className:`w-24 text-[11px] leading-tight text-foreground-subtle md:w-auto`,children:[e.size,` faces · `,Math.round(e.cohesion*100),`% alike`]})]})}function Ke({face:e,cameraName:t,nowMs:n,excluded:r,onToggleExclude:i,onDelete:a,deletePending:o}){return D(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${r?`border-border opacity-40 grayscale`:`border-border`}`,children:[D(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?M(V,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face from ${t}`,className:`h-full w-full`}):D(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[M(H,{className:`h-7 w-7 text-warning/70`}),M(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}),M(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":r?`Include face`:`Exclude face`,title:r?`Include`:`Exclude`,children:M(r?_e:Y,{className:`h-3.5 w-3.5`})})]}),D(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[M(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),M(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:B(e.timestamp,n)})]}),M(`div`,{className:`mt-1 flex items-center justify-end border-t border-border/60 px-1 py-0.5`,children:M(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},disabled:o,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete face`,title:`Delete face`,children:o?M(J,{className:`h-4 w-4 animate-spin`}):M(X,{className:`h-4 w-4`})})})]})}function qe({open:e,onClose:n,byId:r,cameraName:i,nowMs:a,identities:s,selectMany:c}){let l=A(),d=t(),f=o(),[p,m]=j(Ve),[h,g]=j(We),[_,v]=j(null),[y,x]=j({}),[C,T]=j(null),{data:E,isFetching:P,refetch:F}=b({threshold:p,minClusterSize:h,limit:Le},{enabled:e}),I=E??[];N(()=>{x({})},[p,h]),N(()=>{if(I.length===0){v(null);return}I.some(e=>e.representativeFaceId===_)||v(I[0]?.representativeFaceId??null)},[I]);let L=O(()=>I.find(e=>e.representativeFaceId===_)??null,[I,_]),R=L?y[L.representativeFaceId]??new Set:new Set,z=O(()=>L?Fe(L,e=>r.has(e)):[],[L,r]),te=L?L.faceIds.length-z.length:0,B=L?Pe({...L,faceIds:z},R):[];function V(e){if(!L)return;let t=L.representativeFaceId;x(n=>({...n,[t]:Ne(n[t]??new Set,e)}))}function ne(){l.invalidateQueries({queryKey:Ie})}async function H(e){await d({title:`Delete face`,message:`Permanently deletes this face crop. This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&f.mutate({faceId:e},{onSettled:ne})}function re(){T(null),n()}function ie(){B.length!==0&&(c(B),re())}return D(S,{open:e,onOpenChange:e=>!e&&re(),children:[D(u,{placement:`sheet-on-mobile`,width:`lg`,"aria-label":`Look-alike groups`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 md:max-w-4xl`,children:[D(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border px-4 py-3`,children:[D(`div`,{className:`flex items-center justify-between gap-2`,children:[D(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[M(he,{className:`h-4 w-4 text-primary`}),` Look-alike groups`]}),M(`button`,{type:`button`,onClick:re,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:M(Y,{className:`h-4 w-4`})})]}),D(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[D(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Threshold`,M(`input`,{type:`range`,min:Re,max:ze,step:Be,value:p,onChange:e=>m(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),M(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:p.toFixed(2)})]}),D(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Min size`,M(`input`,{type:`number`,min:He,max:Ue,step:1,value:h,onChange:e=>g(Math.min(Ue,Math.max(He,Number(e.target.value)||He))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),D(w,{variant:`secondary`,onClick:()=>{x({}),F()},disabled:P,children:[P?M(J,{className:`h-3.5 w-3.5 animate-spin`}):M(le,{className:`h-3.5 w-3.5`}),`Re-analyze`]})]})]}),M(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:P&&I.length===0?D(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[M(J,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):I.length===0?M(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:`No look-alike groups at this threshold.`}):D(k,{children:[M(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:I.map(e=>M(Ge,{cluster:e,face:r.get(e.representativeFaceId),active:e.representativeFaceId===_,onSelect:()=>v(e.representativeFaceId)},e.representativeFaceId))}),M(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:I.map(e=>M(Ge,{cluster:e,face:r.get(e.representativeFaceId),active:e.representativeFaceId===_,onSelect:()=>v(e.representativeFaceId)},e.representativeFaceId))}),M(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:L&&D(k,{children:[te>0&&D(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:[te,` not loaded — excluded from actions`]}),M(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,1fr))] gap-2`,children:z.map(e=>{let t=r.get(e);return t?M(Ke,{face:t,cameraName:i(t.deviceId),nowMs:a,excluded:R.has(e),onToggleExclude:()=>V(e),onDelete:()=>void H(e),deletePending:f.isPending&&f.variables?.faceId===e},e):null})})]})})]})}),D(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[M(w,{variant:`secondary`,onClick:ie,disabled:B.length===0,children:`Select in gallery`}),D(w,{variant:`primary`,onClick:()=>T(B),disabled:B.length===0,children:[M(ee,{className:`h-3.5 w-3.5`}),` Adopt (`,B.length,`)`]})]})]}),M(Me,{faceIds:C,identities:s,onDone:()=>T(null)})]})}E();var Je=[[`faceGallery`]],Ye=500,Xe=120;function Ze({face:e,cameraName:t,nowMs:n,selected:r,onToggleSelect:i,onAssign:a,onOpenDetail:s}){let c=A(),l=m(),u=o(),d=()=>{c.invalidateQueries({queryKey:Je})},f=()=>s(e.faceId);return D(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${r?`border-primary ring-1 ring-primary`:`border-border`}`,children:[D(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[e.base64?M(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Face from ${t}`,onClick:f,className:`h-full w-full cursor-zoom-in object-cover`}):D(`button`,{type:`button`,onClick:f,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:`No crop image — the face's crop media is missing (a pre-fix orphan). Safe to delete.`,children:[M(H,{className:`h-7 w-7 text-warning/70`}),M(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}),M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(e.faceId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":r?`Deselect`:`Select`,children:r?M(ue,{className:`h-4 w-4 text-primary`}):M(de,{className:`h-4 w-4`})})]}),D(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[M(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),M(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:B(e.timestamp,n)}),e.identityName&&M(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]}),D(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),l.mutate({faceId:e.faceId},{onSettled:d})},disabled:l.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":`Detach face`,title:`Detach`,children:l.isPending?M(J,{className:`h-4 w-4 animate-spin`}):M(L,{className:`h-4 w-4`})}):M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(e.faceId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":`Assign face to person`,title:`Assign to person`,children:M(ee,{className:`h-4 w-4`})}),M(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),u.mutate({faceId:e.faceId},{onSettled:d})},disabled:u.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete face`,title:`Delete face`,children:u.isPending?M(J,{className:`h-4 w-4 animate-spin`}):M(X,{className:`h-4 w-4`})})]})]})}var Qe=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function $e(){let e=A(),[t,n]=j(`all`),[i,a]=j(oe),[s,l]=j(new Set),[u,f]=j(new Set),[p,g]=j(null),[_,v]=j(!1),[b,x]=j(null),{data:S,isLoading:C}=d({limit:Ye,filter:t},{refetchInterval:3e4}),{data:T=[]}=r(),{data:E}=h({}),N=y(),P=m(),F=c(),I=o(),R=Date.now(),B=S??[],V=O(()=>{let e=new Map;for(let t of E??[])e.set(t.id,t.name);return e},[E]),U=e=>V.get(e)??`Camera #${String(e)}`,se=O(()=>te(B).map(e=>({id:e,name:U(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[B,V]),W=O(()=>ne(ce(B,i),s),[B,i,s]),G=re(W,Xe,O(()=>JSON.stringify([t,i.fromMs,i.toMs,[...s].sort((e,t)=>e-t)]),[t,i.fromMs,i.toMs,s])),le=O(()=>new Map(B.map(e=>[e.faceId,e])),[B]),ue=O(()=>Te(W),[W]),de=b===null?null:le.get(b)??null,K=()=>{e.invalidateQueries({queryKey:Je})},q=()=>f(new Set);function fe(e){f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function pe(e){f(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function me(){pe(we(W))}let Z=[...u],Q=N.isPending||F.isPending||I.isPending,ge=P.isPending||I.isPending;function _e(){Z.length!==0&&F.mutate({faceIds:Z},{onSettled:()=>{K(),q()}})}function ve(){Z.length!==0&&Promise.allSettled(Z.map(e=>I.mutateAsync({faceId:e}))).then(()=>{K(),q()})}function $(e){x(null),g([e])}function ye(e){P.mutate({faceId:e},{onSettled:K}),x(null)}function be(e){I.mutate({faceId:e},{onSettled:K}),x(null)}let xe=W.length!==B.length;return D(`div`,{className:`relative space-y-3`,children:[D(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[M(`div`,{className:`flex items-center gap-1`,children:Qe.map(e=>M(`button`,{type:`button`,onClick:()=>n(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${t===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),M(z,{onChange:a}),M(ie,{cameras:se,selected:s,onChange:l}),D(`button`,{type:`button`,onClick:()=>v(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${_?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[M(he,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!C&&ue>0&&D(`button`,{type:`button`,onClick:me,className:`ml-auto flex items-center gap-1 rounded-md px-2.5 py-1 text-xs text-warning/90 transition-colors hover:bg-warning/10`,title:`Select every visible face whose crop image is missing so you can delete the orphans in one pass`,children:[M(H,{className:`h-3.5 w-3.5`}),` Select `,ue,` crop-less`]}),!C&&M(`span`,{className:`text-[10px] text-foreground-subtle ${ue>0?`ml-2`:`ml-auto`}`,children:xe?`${String(W.length)} of ${String(B.length)} faces`:`${String(W.length)} face${W.length===1?``:`s`}`})]}),u.size>0&&D(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[D(`span`,{className:`text-xs font-medium text-foreground`,children:[u.size,` selected`]}),D(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[D(w,{variant:`primary`,onClick:()=>g(Z),disabled:Q,children:[M(ee,{className:`h-3.5 w-3.5`}),` Assign`]}),D(w,{variant:`secondary`,onClick:_e,disabled:Q,children:[F.isPending?M(J,{className:`h-3.5 w-3.5 animate-spin`}):M(L,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),D(w,{variant:`secondary`,onClick:ve,disabled:Q,children:[M(X,{className:`h-3.5 w-3.5`}),` Delete`]}),M(w,{variant:`ghost`,onClick:q,disabled:Q,children:M(Y,{className:`h-3.5 w-3.5`})})]})]}),C&&D(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[M(J,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!C&&W.length===0&&M(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:B.length>0?`No faces match the current date / camera filters.`:`No faces found for this filter.`}),!C&&W.length>0&&D(k,{children:[M(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(6.5rem,1fr))] gap-2`,children:G.pageItems.map(e=>M(Ze,{face:e,cameraName:U(e.deviceId),nowMs:R,selected:u.has(e.faceId),onToggleSelect:fe,onAssign:e=>g([e]),onOpenDetail:x},e.faceId))}),M(ae,{currentPage:G.page,totalItems:G.totalItems,pageSize:G.pageSize,onPageChange:G.setPage,itemNoun:`faces`})]}),M(Ae,{face:de,cameraName:de?U(de.deviceId):``,onClose:()=>x(null),onAssign:$,onUnassign:ye,onDelete:be,actionsPending:ge}),M(Me,{faceIds:p,identities:T,onDone:()=>{g(null),q()}}),M(qe,{open:_,onClose:()=>v(!1),byId:le,cameraName:U,nowMs:R,identities:T,selectMany:pe})]})}E();var et=[[`faceGallery`]],tt=2e3;function nt(){let e=A(),t=T(e);t.current=e;let n=T(void 0);n.current||=se({delayMs:tt,invalidate:()=>{t.current.invalidateQueries({queryKey:et})}}),N(()=>()=>n.current?.cancel(),[]),i(P.PipelineAnalyticsFaceGalleryChanged,()=>{n.current?.trigger()})}function rt(){return nt(),M(Z,{icon:me,title:`Faces`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:D(`section`,{className:`space-y-3`,children:[D(`div`,{children:[M(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),M(`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.`}),M(Se,{})]}),D(`div`,{className:`pt-4 border-t border-border`,children:[M(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),M(`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.`}),M($e,{})]})]})})}export{rt as DetectionIntelligencePage};