@camstack/addon-admin-ui 1.2.90 → 1.2.95

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 (114) hide show
  1. package/dist/assets/AddLocationWizard-yQ5xKdxu.js +1 -0
  2. package/dist/assets/{AddonCollectionPage-DgxQiC5R.js → AddonCollectionPage-CPaB3q84.js} +1 -1
  3. package/dist/assets/{Addons-DIkbBQAN.js → Addons-CC_eX4kE.js} +1 -1
  4. package/dist/assets/{AdminTabs-DS0Srvsl.js → AdminTabs-C4XUBKp2.js} +1 -1
  5. package/dist/assets/{AiProfiles-CxEToJhw.js → AiProfiles-chnntJNX.js} +1 -1
  6. package/dist/assets/{BrokerForm-C2Ffj2TP.js → BrokerForm-CX4FDINk.js} +1 -1
  7. package/dist/assets/{Build-CjZnQDw-.js → Build-BUtA82o0.js} +1 -1
  8. package/dist/assets/{Capabilities-DCCQTIe1.js → Capabilities-R1K3F30i.js} +1 -1
  9. package/dist/assets/{CapabilityBadges-D5vvC1yi.js → CapabilityBadges-BMjeNmtX.js} +1 -1
  10. package/dist/assets/{Cluster-xCjfPks5.js → Cluster-C8CaTKus.js} +1 -1
  11. package/dist/assets/Data-pcu1Zpli.js +1 -0
  12. package/dist/assets/{DetectionIntelligence-D0-LailW.js → DetectionIntelligence-SURWYu20.js} +1 -1
  13. package/dist/assets/{DeviceAggregateSection-BCYifsQE.js → DeviceAggregateSection-CQOaL9JL.js} +1 -1
  14. package/dist/assets/DeviceDetail-ECI5nkJB.js +2 -0
  15. package/dist/assets/{Devices-CrnIRovn.js → Devices-BCl95wea.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-CZ6zyHHW.js → EmbedPlayerPage-CvsYBLqq.js} +1 -1
  17. package/dist/assets/{Events-DQHeF8ak.js → Events-DiFMylc6.js} +1 -1
  18. package/dist/assets/{FormBuilder-DoXEuyDl.js → FormBuilder-CuLKYvG7.js} +1 -1
  19. package/dist/assets/Identity-BjIqFAaz.js +1 -0
  20. package/dist/assets/{IntegrationDetail-D2BcdghA.js → IntegrationDetail-DEmXDCkW.js} +1 -1
  21. package/dist/assets/{Integrations-sEcPRDl_.js → Integrations-CPzHUkTD.js} +1 -1
  22. package/dist/assets/{Integrations-DNlWMb_O.js → Integrations-OSUItK7O.js} +1 -1
  23. package/dist/assets/{Logs-CkSiZEDd.js → Logs-CiyLp_uy.js} +1 -1
  24. package/dist/assets/{MotionZonesSettings-Cswy44AX.js → MotionZonesSettings-20Hjjo_I.js} +1 -1
  25. package/dist/assets/{MyAccess-YfTGgX7y.js → MyAccess-CguqmuH6.js} +1 -1
  26. package/dist/assets/Network-ze5IIcl8.js +1 -0
  27. package/dist/assets/{NodeAddonsSettingsPanel-DBFMTvCH.js → NodeAddonsSettingsPanel-Bq4IxxW0.js} +1 -1
  28. package/dist/assets/{NodeInferenceDevices-B73NC03X.js → NodeInferenceDevices-DqNTETvP.js} +1 -1
  29. package/dist/assets/Notifications-Ck65jgUT.js +1 -0
  30. package/dist/assets/Pipeline-Cj8ZGzsh.js +1 -0
  31. package/dist/assets/{Plates-BlLBjmm0.js → Plates--FHuvJtf.js} +1 -1
  32. package/dist/assets/{PrivacyMaskSettings-DXTJ79bO.js → PrivacyMaskSettings-Col9BQK1.js} +1 -1
  33. package/dist/assets/{ProviderIcon-MfX3M-Ob.js → ProviderIcon-Dil6gqDJ.js} +1 -1
  34. package/dist/assets/Recordings-Udy7CZRb.js +1 -0
  35. package/dist/assets/{ScanNetworkModal-BIIqnjlI.js → ScanNetworkModal-C4TCIDsZ.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-CGpMYdow.js → SceneMonitorEditor-DqtLziNW.js} +1 -1
  37. package/dist/assets/{Scenes-Bkv_F5Zt.js → Scenes-HDZBlnCW.js} +1 -1
  38. package/dist/assets/{Settings-DexyTMK3.js → Settings-1Y6Wn9ZD.js} +1 -1
  39. package/dist/assets/{Showroom-BXbcCAve.js → Showroom-BdSOAg3D.js} +1 -1
  40. package/dist/assets/{Terminal-ChyYT2Xd.js → Terminal-BvVtGnWl.js} +3 -3
  41. package/dist/assets/_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BpoPtUSo.js +1 -0
  42. package/dist/assets/{bell-ring-BSDAxanc.js → bell-ring-CWQuZR3H.js} +1 -1
  43. package/dist/assets/{boxes-OU9o0K_I.js → boxes-DsGxiYqV.js} +1 -1
  44. package/dist/assets/{build-cluster-graph-CkdrNOrw.js → build-cluster-graph-svux1srI.js} +1 -1
  45. package/dist/assets/circle-check-big-BAMbdgEi.js +1 -0
  46. package/dist/assets/{circle-x-DgXg62nX.js → circle-x-B3X5szNf.js} +1 -1
  47. package/dist/assets/clock-GuRIHL-h.js +1 -0
  48. package/dist/assets/{copy-DS7H6-em.js → copy-CVILowFL.js} +1 -1
  49. package/dist/assets/{debounced-invalidate-DX8r5XfG.js → debounced-invalidate-aIBv9OV7.js} +1 -1
  50. package/dist/assets/dist-B9mLhJtV.js +349 -0
  51. package/dist/assets/{dist-Cw4PMJs2.js → dist-CJUMPVYI.js} +1 -1
  52. package/dist/assets/{download-FcOcOShY.js → download-DfPmVE-2.js} +1 -1
  53. package/dist/assets/{face-bbox-C_ak-5Gz.js → face-bbox-CzTHnnve.js} +1 -1
  54. package/dist/assets/{format-size-CO9d3C3-.js → format-size-DIxKXxtj.js} +1 -1
  55. package/dist/assets/hostInit-5kq3Yl3B.js +1 -0
  56. package/dist/assets/index-xtKsywAe.js +4 -0
  57. package/dist/assets/{key-round-DO25vFwm.js → key-round-WY_5T8Mk.js} +1 -1
  58. package/dist/assets/{mf-entry-bootstrap-0-48e7c1b3.js → mf-entry-bootstrap-0-ce1c7c91.js} +2 -2
  59. package/dist/assets/{pencil-C9e8FY_K.js → pencil-cTIlqAi1.js} +1 -1
  60. package/dist/assets/play-Bk1uczlT.js +1 -0
  61. package/dist/assets/{player-overlays-DN_06_1T.js → player-overlays-Dk2BW_cb.js} +1 -1
  62. package/dist/assets/plus-CWTt_eYK.js +1 -0
  63. package/dist/assets/power-C6ph7AJF.js +1 -0
  64. package/dist/assets/{radio-KghuZMQV.js → radio-1P6dBuv2.js} +1 -1
  65. package/dist/assets/{refresh-cw-S_IzGUwN.js → refresh-cw-BpkwnD6g.js} +1 -1
  66. package/dist/assets/remoteEntry-BNr9mS4Z.js +1 -0
  67. package/dist/assets/rotate-ccw-IbMCK7V1.js +1 -0
  68. package/dist/assets/rotate-cw-OrQnSp1d.js +1 -0
  69. package/dist/assets/search-C5207GJ1.js +1 -0
  70. package/dist/assets/{send-BxpQV4uW.js → send-f6PZcwFX.js} +1 -1
  71. package/dist/assets/{server-CouJc0au.js → server-pnOxXPzc.js} +1 -1
  72. package/dist/assets/{shield-BLP_9cz7.js → shield-C2j9f5TB.js} +1 -1
  73. package/dist/assets/square-DZLDRRzS.js +1 -0
  74. package/dist/assets/{square-check-big-DGZA6wHf.js → square-check-big-BsTe_XLj.js} +1 -1
  75. package/dist/assets/src-IYbs58V5.js +67 -0
  76. package/dist/assets/src-uorLMfKR.js +349 -0
  77. package/dist/assets/{star-COsLARFs.js → star-BmPQOt4U.js} +1 -1
  78. package/dist/assets/{undo-2-CHGwpF3q.js → undo-2-COm2RQUf.js} +1 -1
  79. package/dist/assets/{upload-UbmWhfNy.js → upload-FT1whtv-.js} +1 -1
  80. package/dist/assets/{use-scenes-feed--CY2Z_u1.js → use-scenes-feed-By1r5UVz.js} +1 -1
  81. package/dist/assets/useEventInvalidation-BC0Feqcy.js +1 -0
  82. package/dist/assets/{video-7B-RN_5Z.js → video-Cr4Jo6jI.js} +1 -1
  83. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-xmN5U0v7.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CY6_31J0.js} +2 -2
  84. package/dist/assets/{wifi-B8upcnaM.js → wifi-C-HsaPKu.js} +1 -1
  85. package/dist/assets/{zap-qTa-8D3P.js → zap-4zBPpSJn.js} +1 -1
  86. package/dist/index.html +5 -5
  87. package/dist/server/addon.js +103 -12
  88. package/package.json +1 -1
  89. package/dist/assets/AddLocationWizard-Cfcvdso2.js +0 -1
  90. package/dist/assets/Data-Bx3JEBlB.js +0 -1
  91. package/dist/assets/DeviceDetail-l4ItEN2Q.js +0 -2
  92. package/dist/assets/Identity-CyFJ39bP.js +0 -1
  93. package/dist/assets/Network-BlbxdrNT.js +0 -1
  94. package/dist/assets/Notifications-ppv_emHc.js +0 -1
  95. package/dist/assets/Pipeline-ujYtuLUK.js +0 -1
  96. package/dist/assets/Recordings-Cb5e0T7R.js +0 -1
  97. package/dist/assets/_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C7gqtZRe.js +0 -1
  98. package/dist/assets/circle-check-big-B7_QKFSQ.js +0 -1
  99. package/dist/assets/clock-DrVdCcaX.js +0 -1
  100. package/dist/assets/dist-BmzucNaP.js +0 -349
  101. package/dist/assets/hard-drive-JDbfX603.js +0 -1
  102. package/dist/assets/hostInit-XQNV3SQC.js +0 -1
  103. package/dist/assets/index-B1t00qUp.js +0 -4
  104. package/dist/assets/play-DHOSTYVl.js +0 -1
  105. package/dist/assets/plus-5BBPoTgM.js +0 -1
  106. package/dist/assets/power-C-BBysAq.js +0 -1
  107. package/dist/assets/remoteEntry-CrJWwg3y.js +0 -1
  108. package/dist/assets/rotate-ccw-CAAGiLAw.js +0 -1
  109. package/dist/assets/rotate-cw-DVJmPlX9.js +0 -1
  110. package/dist/assets/search-DXNVjwOG.js +0 -1
  111. package/dist/assets/square-DO1rX5dt.js +0 -1
  112. package/dist/assets/src-5IxHiQXr.js +0 -349
  113. package/dist/assets/src-Dw_YuA21.js +0 -67
  114. package/dist/assets/useEventInvalidation-Co1T3fjc.js +0 -1
@@ -1 +0,0 @@
1
- import{I as e,Q as t,S as n,W as r,a as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as l}from"./player-overlays-DN_06_1T.js";import{Qo as u,g as d,qo as f}from"./src-Dw_YuA21.js";import{t as p}from"./FormBuilder-DoXEuyDl.js";import{t as m}from"./pencil-C9e8FY_K.js";import{t as h}from"./plus-5BBPoTgM.js";import{t as g}from"./power-C-BBysAq.js";import{t as _}from"./star-COsLARFs.js";import{C as v,I as y,i as b,s as x}from"./index-B1t00qUp.js";t();function S(e){return e.enabled!==!1}function C(e){return e.isDefault}function w(e,t){let n={id:e.id,type:e.type,displayName:t.displayName??e.displayName,providerId:e.providerId,config:e.config,isDefault:t.isDefault??e.isDefault,isSystem:e.isSystem},r=e.nodeId===void 0?n:{...n,nodeId:e.nodeId},i=t.enabled??e.enabled;return i===void 0?r:{...r,enabled:i}}function T(e){return`${(e/1024**3).toFixed(e>=100*1024**3?0:1)} GB`}function E({location:e}){let t=e.capacity;return t==null?null:n(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[T(t.availableBytes),` free of `,T(t.totalBytes)]})}function D(e){let t=e.basePath;if(typeof t==`string`&&t.length>0)return t;let n=Object.keys(e);return n.length===0?``:n.join(`, `)}function O({location:e,cardinality:t,onEdit:r,onDelete:i,onSetDefault:a,onToggleEnabled:o}){let c=D(e.config),l=S(e),u=C(e);return n(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2 px-3 py-2 border-t border-border first:border-t-0 hover:bg-primary/5`,children:[n(`div`,{className:`flex flex-wrap items-center gap-2 min-w-0 flex-1 basis-64`,children:[s(`div`,{className:`w-[88px] shrink-0`,children:e.isDefault?n(`span`,{className:`inline-flex items-center gap-0.5 rounded bg-primary/10 border border-primary/20 px-1.5 py-0.5 text-[10px] font-semibold text-primary uppercase tracking-wide`,title:`Default location for this type`,children:[s(_,{className:`h-2.5 w-2.5 fill-primary`}),`Default`]}):n(`button`,{onClick:()=>a(e),className:`inline-flex items-center gap-0.5 rounded border border-border px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 hover:border-primary/30 uppercase tracking-wide`,title:`Promote to default for this type`,children:[s(_,{className:`h-2.5 w-2.5`}),`Set default`]})}),s(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5 font-mono`,children:e.providerId}),!l&&s(`span`,{className:`text-[10px] uppercase tracking-wide text-warning bg-warning/10 border border-warning/30 rounded px-1.5 py-0.5`,title:`Disabled — nothing new is written here. Existing data stays readable and is still pruned by age.`,children:`disabled`}),e.isSystem&&s(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5`,title:`System-managed location — cannot be deleted; edit config to relocate`,children:`system`}),e.config.readOnly===!0&&s(`span`,{className:`text-[10px] uppercase tracking-wide text-warning bg-warning/10 border border-warning/30 rounded px-1.5 py-0.5`,title:`Drain mode — reads and age retention continue; nothing new is written here and disk-pressure eviction skips it`,children:`read-only`}),n(`div`,{className:`min-w-0`,children:[s(`div`,{className:`text-xs font-medium text-foreground truncate`,children:e.displayName}),n(`div`,{className:`flex flex-wrap items-center gap-x-2`,children:[c&&s(`span`,{className:`text-[10px] text-foreground-subtle truncate font-mono`,children:c}),s(E,{location:e})]})]})]}),n(`div`,{className:`flex flex-wrap items-center gap-1 shrink-0`,children:[n(`button`,{type:`button`,role:`switch`,"aria-label":`Writes enabled`,"aria-checked":l,disabled:u,onClick:()=>o(e,!l),title:u?`The default location of a type is always enabled — it is the fallback every balancing consumer falls back to. Promote another location to default first.`:l?`Enabled — balancing consumers may write new data here. Click to stop new writes.`:`Disabled — no new data is written here. Existing data stays readable. Click to enable.`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium border disabled:cursor-not-allowed ${l?`border-success/30 text-success hover:bg-success/10`:`border-warning/40 text-warning hover:bg-warning/10`}`,children:[s(g,{className:`h-3 w-3`}),l?`Enabled`:`Disabled`]}),!e.isDefault&&n(`button`,{onClick:()=>a(e),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle border border-border hover:text-foreground hover:bg-primary/10`,title:`Set as default for this type`,children:[s(_,{className:`h-3 w-3`}),`Set default`]}),n(`button`,{onClick:()=>r(e),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle border border-border hover:text-foreground hover:bg-primary/10`,children:[s(m,{className:`h-3 w-3`}),`Edit`]}),!e.isSystem&&t!==`single`&&s(`button`,{onClick:()=>i(e),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10`,title:`Delete location`,children:s(x,{className:`h-3 w-3`})})]})]})}function k({type:e,displayName:t,description:i,cardinality:a,locations:o,onAdd:c,onEdit:l,onDelete:u,onSetDefault:d,onToggleEnabled:f}){let p=r(()=>{let e=[...o];return e.sort((e,t)=>e.isDefault===t.isDefault?e.displayName.localeCompare(t.displayName):e.isDefault?-1:1),e},[o]);return n(`div`,{className:`rounded-lg border border-border bg-surface`,children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-3 py-2`,children:[n(`div`,{className:`space-y-0.5`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`span`,{className:`text-sm font-semibold text-foreground capitalize`,children:t}),s(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5 font-mono`,children:e})]}),i&&s(`p`,{className:`text-[11px] text-foreground-subtle`,children:i}),a===`single`&&s(`p`,{className:`text-[10px] text-foreground-subtle italic`,children:`Single — one location per type. Edit the existing entry; it can't be split.`})]}),a===`multi`&&n(`button`,{onClick:()=>c(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:[s(h,{className:`h-3 w-3`}),`Add`]})]}),p.length===0?s(`div`,{className:`px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:a===`multi`?`No location registered. Click "Add" to register one.`:`No location registered yet — should be auto-seeded at next boot.`}):s(`div`,{children:p.map(e=>s(O,{location:e,cardinality:a,onEdit:l,onDelete:u,onSetDefault:d,onToggleEnabled:f},e.id))})]})}var A=new Set([`proc`,`sys`,`dev`,`run`,`boot`,`lost+found`,`snap`,`bin`,`sbin`,`lib`,`lib32`,`lib64`,`libx32`,`usr`,`etc`,`var`,`opt`,`tmp`,`srv`,`root`,`System`,`Library`,`Applications`,`cores`,`private`]),j=[`recordings`,`data`,`mnt`,`media`,`Volumes`];function M(e){let t=j.findIndex(t=>t===`recordings`?e.startsWith(t):e===t);return t===-1?j.length:t}function N(e){return e.filter(e=>!e.name.startsWith(`.`)&&!A.has(e.name)).toSorted((e,t)=>{let n=M(e.name)-M(t.name);return n===0?e.name.localeCompare(t.name):n}).map(e=>e.path)}t();function P({nodeId:t,value:r,onChange:i}){let a=l().trpcClient,[u,d]=o([]),[f,p]=o(r),[m,h]=o(null),[g,_]=o(null),[v,y]=o(``),b=e(async(e,n)=>{_(null);try{let r=await a.filesystemBrowse.browse.query({nodeId:t,path:e});h(r),p(r.path),n&&i(r.path)}catch(e){_(e instanceof Error?e.message:`browse failed`)}},[a,t,i]);c(()=>{p(r),(async()=>{let e=await a.filesystemBrowse.browse.query({nodeId:t,path:`/`}).then(e=>e).catch(()=>null);if(e){d(N(e.entries)),await b(r.startsWith(`/`)?r:`/`,!1);return}try{let e=await a.filesystemBrowse.listAllowedRoots.query({nodeId:t});d(e),await b(r&&e.some(e=>r.startsWith(e))?r:e[0]??``,!1)}catch(e){d([]),h(null),_(e instanceof Error&&/not available on node/i.test(e.message)?`This node can't be browsed remotely. Enter the path manually.`:e instanceof Error?e.message:`browse unavailable`)}})()},[t]);let x=async()=>{if(!(!v.trim()||!m)){_(null);try{let e=`${m.path.replace(/\/+$/,``)}/${v.trim()}`;await a.filesystemBrowse.createDir.mutate({nodeId:t,path:e}),y(``),await b(m.path,!0)}catch(e){_(e instanceof Error?e.message:`create failed`)}}},S=e=>`${(e/1e9).toFixed(1)} GB`;return n(`div`,{className:`space-y-2 rounded border border-border p-2`,children:[s(`div`,{className:`flex flex-wrap gap-1`,children:u.map(e=>s(`button`,{onClick:()=>void b(e,!0),className:`rounded border border-border px-2 py-0.5 text-[10px] font-mono hover:border-primary/40`,children:e},e))}),s(`input`,{value:f,onChange:e=>{p(e.target.value),i(e.target.value)},placeholder:`/absolute/path`,className:`w-full rounded border border-border bg-background px-2 py-1 text-[11px] font-mono`}),m&&n(`div`,{className:`text-[10px] text-foreground-subtle`,children:[S(m.freeBytes),` free / `,S(m.totalBytes)]}),s(`div`,{className:`max-h-40 space-y-0.5 overflow-y-auto`,children:m?.entries.map(e=>n(`button`,{onClick:()=>void b(e.path,!0),className:`block w-full truncate rounded px-2 py-1 text-left text-xs hover:bg-primary/5`,children:[`📁 `,e.name]},e.path))}),n(`div`,{className:`flex gap-1`,children:[s(`input`,{value:v,onChange:e=>y(e.target.value),placeholder:`new folder`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs`}),s(`button`,{onClick:()=>void x(),className:`rounded border border-border px-2 py-1 text-xs hover:border-primary/40`,children:`Create`})]}),g&&s(`div`,{className:`text-[10px] text-red-400`,children:g})]})}t();function F({location:e,onClose:t,onSaved:c}){let m=a(),h=l().trpcClient,[g,_]=o({...e.config}),[y,x]=o(e.displayName),[S,C]=o(null),[w,T]=o(!1),E=f(),D=r(()=>{let t=E.data;return Array.isArray(t)?t.find(t=>t.providerId===e.providerId)??null:null},[E.data,e.providerId]),O=u({onSuccess:()=>{m.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),c()}}),k=D?.shouldSaveDiskSpace===!0,A=D?.nodeLocal===!0,[j,M]=o(typeof e.nodeId==`string`?e.nodeId:`hub`),N=typeof g.basePath==`string`?g.basePath:``,F=e=>_(t=>({...t,basePath:e})),I=g.readOnly===!0,L=i({queryKey:[`storage`,`listLocations`,`ro-guard`],queryFn:()=>h.storage.listLocations.query({})}),R=(L.data??[]).filter(t=>t.type===e.type&&t.id!==e.id&&t.config.readOnly!==!0).length,z=!I&&L.data!==void 0&&R===0,B=e=>_(t=>{let n={...t};return delete n.readOnly,e?{...n,readOnly:!0}:n}),V=typeof g.maxUsedGb==`number`?g.maxUsedGb:``,H=e=>{let t=e.trim(),n=t===``?void 0:Number(t);_(e=>{let t={...e};return n===void 0||!Number.isFinite(n)||n<=0?delete t.maxUsedGb:t.maxUsedGb=n,t})},U=typeof g.minFreePercent==`number`?g.minFreePercent:``,W=e=>{let t=e.trim(),n=t===``?void 0:Number(t);_(e=>{let t={...e};return n===void 0||!Number.isFinite(n)?delete t.minFreePercent:t.minFreePercent=Math.min(100,Math.max(0,n)),t})},G=async()=>{T(!0),C(null);try{C(await(e=>h.storage.testConfig.query(e))({providerId:e.providerId,config:g}))}catch(e){C({ok:!1,error:e instanceof Error?e.message:String(e)})}finally{T(!1)}};return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:n(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[n(`div`,{className:`space-y-0.5`,children:[n(`h2`,{className:`text-sm font-semibold text-foreground`,children:[`Edit `,e.displayName]}),n(`p`,{className:`text-xs text-foreground-subtle`,children:[s(`span`,{className:`font-mono`,children:e.id}),` ·`,` `,D?.displayName??e.providerId]})]}),s(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:s(b,{className:`h-4 w-4`})})]}),n(`div`,{className:`p-4 space-y-3 max-h-[60vh] overflow-y-auto`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Display name`}),s(`input`,{type:`text`,value:y,onChange:e=>x(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`})]}),D&&s(p,{schema:D.configSchema,values:g,onChange:_}),n(`div`,{className:`space-y-1`,children:[n(`label`,{className:`flex items-center gap-2 text-xs ${z?`text-foreground-subtle cursor-not-allowed`:`text-foreground cursor-pointer`}`,children:[s(`input`,{type:`checkbox`,checked:I,disabled:z,onChange:e=>B(e.target.checked),className:`accent-primary`}),`Read-only (drain mode)`]}),s(`p`,{className:`text-[10px] text-foreground-subtle`,children:z?`Blocked: this is the last writable location of its type — new footage would have nowhere to go.`:`Reads and age-based retention continue; nothing new is written here and disk-pressure eviction skips it. Use it to slowly decommission a disk.`})]}),A&&n(`div`,{className:`space-y-2`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Node`}),s(d,{selectedNodeId:j,onSelect:M,alwaysShow:!0}),s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Path`}),s(P,{nodeId:j,value:N,onChange:F})]}),k&&n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Min free disk %`}),s(`input`,{type:`number`,min:0,max:100,value:U,placeholder:D?.minFreePercent==null?``:String(D.minFreePercent),onChange:e=>W(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`}),n(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`When free space on this volume drops below this %, the oldest data stored here is evicted to reclaim space.`,D?.minFreePercent==null?` Empty = use the default.`:` Empty = use the default (${D.minFreePercent}%).`]}),s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Max used (GB)`}),s(`input`,{type:`number`,min:1,value:V,placeholder:`unlimited`,onChange:e=>H(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`}),s(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Hard cap on the TOTAL bytes evictable data (recordings) may occupy on this location, independent of disk free space — oldest footage is evicted past it. Empty = unlimited.`})]}),!D&&!E.isLoading&&n(`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:[`Provider `,s(`code`,{className:`font-mono`,children:e.providerId}),` is no longer registered. Field schema unavailable; raw config is preserved on save.`]}),S&&s(`div`,{className:`rounded border px-3 py-2 text-[11px] ${S.ok?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:S.ok?`Connection OK.`:`Test failed: ${S.error??`unknown error`}`}),O.isError&&s(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:O.error instanceof Error?O.error.message:String(O.error)})]}),n(`div`,{className:`flex items-center justify-between gap-2 border-t border-border px-4 py-3`,children:[s(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),n(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:()=>{G()},disabled:w||!D,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10 disabled:opacity-50`,children:w?`Testing…`:`Test connection`}),n(`button`,{onClick:()=>{O.mutate({id:e.id,type:e.type,providerId:e.providerId,isDefault:e.isDefault,displayName:y.trim(),config:g,nodeId:A?j:void 0})},disabled:O.isPending||y.trim().length===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:[O.isPending?s(v,{className:`h-3.5 w-3.5 animate-spin`}):null,O.isPending?`Saving…`:`Save`]})]})]})]})})}function I(e){let t=e.trim().toLowerCase();return t.length===0?``:t.replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function L(e,t){let n=I(t);return`${e}:${n.length>0?n:`default`}`}t();function R({initialType:e,onClose:t,onCreated:i}){let c=a(),m=l().trpcClient,[h,g]=o(`picker`),[_,x]=o(e),[S,C]=o(null),[w,T]=o({}),[E,D]=o(``),[O,k]=o(null),[A,j]=o(!1),[M,N]=o(!1),[F,I]=o(`hub`),[R,z]=o(null),[B,V]=o(!1),H=e=>T(t=>({...t,basePath:e})),U=typeof w.basePath==`string`?w.basePath:``,W=f(),G=r(()=>{let e=W.data;return Array.isArray(e)?e:[]},[W.data]),K=W.isLoading,q=u({onSuccess:()=>{c.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),i()}}),J=r(()=>O!==null&&O.length>0?O:L(_,E),[_,E,O]),Y=async()=>{if(S){V(!0),z(null);try{z(await(e=>m.storage.testConfig.query(e))({providerId:S.providerId,config:w}))}catch(e){z({ok:!1,error:e instanceof Error?e.message:String(e)})}finally{V(!1)}}};return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:n(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[n(`div`,{className:`space-y-0.5`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:{picker:`Add Location — Pick provider`,config:`Add Location — ${S?.displayName??``}`,naming:`Add Location — Name & defaults`}[h]}),n(`p`,{className:`text-xs text-foreground-subtle`,children:[`Type: `,s(`span`,{className:`font-mono`,children:_})]})]}),s(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:s(b,{className:`h-4 w-4`})})]}),h===`picker`&&n(`div`,{className:`p-4 space-y-2`,children:[K&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading providers…`}),!K&&G.length===0&&n(`div`,{className:`rounded border border-border bg-background px-3 py-4 text-center text-xs text-foreground-subtle`,children:[`No storage-provider supports type "`,_,`". Install a compatible addon (e.g.`,` `,s(`code`,{className:`font-mono`,children:`remote-storage`}),`) to enable it.`]}),G.map(e=>n(`button`,{onClick:()=>{C(e),g(`config`)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-background p-3 text-left hover:border-primary/40 hover:bg-primary/5 transition-colors`,children:[n(`div`,{className:`flex-1 min-w-0`,children:[s(`p`,{className:`text-xs font-semibold text-foreground`,children:e.displayName}),s(`p`,{className:`text-[10px] text-foreground-subtle font-mono mt-0.5 truncate`,children:e.providerId})]}),s(y,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},e.providerId))]}),h===`config`&&S&&n(`div`,{className:`p-4 space-y-3 max-h-[60vh] overflow-y-auto`,children:[s(p,{schema:S.configSchema,values:w,onChange:T}),S.nodeLocal&&n(`div`,{className:`space-y-2`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Node`}),s(d,{selectedNodeId:F,onSelect:I,alwaysShow:!0}),s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Path`}),s(P,{nodeId:F,value:U,onChange:H})]}),R&&s(`div`,{className:`rounded border px-3 py-2 text-[11px] ${R.ok?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:R.ok?`Connection OK.`:`Test failed: ${R.error??`unknown error`}`}),n(`div`,{className:`flex items-center justify-between pt-1`,children:[s(`button`,{onClick:()=>g(`picker`),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Back`}),n(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:()=>{Y()},disabled:B,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10 disabled:opacity-50`,children:B?`Testing…`:`Test connection`}),s(`button`,{onClick:()=>g(`naming`),className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Next`})]})]})]}),h===`naming`&&S&&n(`div`,{className:`p-4 space-y-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Display name`}),s(`input`,{type:`text`,value:E,onChange:e=>D(e.target.value),placeholder:`${_} on ${S.displayName}`,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`})]}),n(`div`,{className:`space-y-1`,children:[n(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:[`Id`,` `,s(`span`,{className:`lowercase tracking-normal text-foreground-subtle`,children:`— auto-derived; override if needed`})]}),s(`input`,{type:`text`,value:J,onChange:e=>k(e.target.value),placeholder:L(_,E),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground font-mono focus:outline-none focus:ring-1 focus:ring-primary`}),n(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,s(`code`,{className:`font-mono`,children:`<type>:<slug>`}),`. Lowercase letters, digits, and hyphens only.`]})]}),n(`label`,{className:`flex items-start gap-2 rounded border border-border bg-background px-3 py-2 cursor-pointer hover:bg-primary/5`,children:[s(`input`,{type:`checkbox`,checked:A,onChange:e=>j(e.target.checked),className:`accent-primary mt-0.5`}),n(`div`,{className:`space-y-0.5`,children:[n(`div`,{className:`text-xs font-medium text-foreground`,children:[`Mark as default for type "`,_,`"`]}),n(`div`,{className:`text-[10px] text-foreground-subtle`,children:[`Setting this as default will demote the current default for this type. References like `,n(`code`,{className:`font-mono`,children:[`"`,_,`"`]}),` resolve to whichever location is the default.`]})]})]}),n(`label`,{className:`flex items-start gap-2 rounded border border-border bg-background px-3 py-2 cursor-pointer hover:bg-primary/5`,children:[s(`input`,{type:`checkbox`,checked:M,onChange:e=>N(e.target.checked),className:`accent-primary mt-0.5`}),n(`div`,{className:`space-y-0.5`,children:[s(`div`,{className:`text-xs font-medium text-foreground`,children:`Enable immediately`}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:`A disabled location receives no writes until enabled — reads and age-based retention still work, nothing new lands here. Leave this off to register the disk now and start using it later.`})]})]}),q.isError&&s(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:q.error instanceof Error?q.error.message:String(q.error)}),n(`div`,{className:`flex items-center justify-between pt-1`,children:[s(`button`,{onClick:()=>g(`config`),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Back`}),n(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:()=>{x(e),C(null),T({}),D(``),k(null),j(!1),N(!1),z(null),g(`picker`)},className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Reset`}),n(`button`,{onClick:()=>{S&&q.mutate({id:J,type:_,displayName:E.trim(),providerId:S.providerId,config:w,isDefault:A,enabled:M,nodeId:S.nodeLocal?F:void 0})},disabled:q.isPending||E.trim().length===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:[q.isPending?s(v,{className:`h-3.5 w-3.5 animate-spin`}):null,q.isPending?`Saving…`:`Save`]})]})]})]})]})})}export{w as i,F as n,k as r,R as t};
@@ -1 +0,0 @@
1
- import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{$n as l,Dn as u,En as d,Go as f,Jn as p,Ko as m,Mn as h,Qn as g,Qo as _,Wo as v,Xn as y,Yn as b,Zn as x,er as S,ln as C,nr as w,rr as T,tr as E}from"./src-Dw_YuA21.js";import{t as D}from"./download-FcOcOShY.js";import{t as O}from"./hard-drive-JDbfX603.js";import{t as k}from"./pencil-C9e8FY_K.js";import{t as A}from"./play-DHOSTYVl.js";import{t as j}from"./plus-5BBPoTgM.js";import{t as M}from"./rotate-cw-DVJmPlX9.js";import{C as N,I as P,K as F,R as I,W as ee,i as L,m as R,s as z}from"./index-B1t00qUp.js";import{t as B}from"./AdminPage-CCD07UMs.js";import{r as te}from"./authed-media-BPd_L9jr.js";import{t as ne}from"./AdminTabs-DS0Srvsl.js";import{t as V}from"./format-size-CO9d3C3-.js";import{i as H,n as re,r as ie,t as ae}from"./AddLocationWizard-Cfcvdso2.js";import{t as U}from"./AddonCollectionPage-DgxQiC5R.js";import{t as W}from"./addon-display-names-DvSEQty-.js";var G=F(`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`}]]),K=F(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),q=F(`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`}]]),J=F(`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`}]]);t();function oe(){let e=a(),t=C(),{data:i,isLoading:c,isError:l}=m({}),u=f(),d=r(()=>u.data??[],[u.data]),[p,h]=o(null),[g,y]=o(null),b=v({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),x=_({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),S=e=>{e.isDefault||x.mutate(H(e,{isDefault:!0}))},w=(e,t)=>{x.mutate(H(e,{enabled:t}))},T=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`})&&b.mutate({id:e.id})},E=r(()=>{let e=new Map;for(let t of i??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[i]),D=c||u.isLoading,O=l||u.isError;return n(B,{children:[D&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),O&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!D&&!O&&n(`div`,{className:`space-y-3`,children:[d.length===0&&s(`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.`}),d.map(e=>s(ie,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:E.get(e.id)??[],onAdd:e=>h(e),onEdit:e=>y(e),onDelete:e=>{T(e)},onSetDefault:e=>S(e),onToggleEnabled:(e,t)=>w(e,t)},e.id))]}),p!==null&&s(ae,{initialType:p,onClose:()=>h(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),h(null)}}),g!==null&&s(re,{location:g,onClose:()=>y(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),y(null)}})]})}t();var se=[[`backup`,`listDestinations`]],ce=[`backup`,`listArchives`];function le({destinationId:t,restoreSupported:i,onOpenRestoreWizard:c}){let l=a(),u=C(),{data:d,isLoading:f,isError:m}=x({destinationId:t}),h=d??[],g=p({onSuccess:()=>{l.invalidateQueries({queryKey:[[...ce]]}),l.invalidateQueries({queryKey:se})}}),_=e(async e=>{await u({title:`Delete this archive?`,message:`Permanently deletes "${e.label??e.id}" and frees ${V(e.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&g.mutate({destinationId:t,backupId:e.id})},[u,t,g]),[v,y]=o(null),b=e(async e=>{y(e.id);try{let n=await te(ue(t,e.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.label??e.id}.tar.gz`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{y(null)}},[t]),S=r(()=>[...h].toSorted((e,t)=>t.createdAt-e.createdAt),[h]);return f?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):m?s(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):S.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):s(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:S.map(e=>n(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:Y(e.createdAt)}),s(`td`,{className:`px-3 py-1.5 text-foreground`,children:e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),s(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:e.locations.join(`, `)}),s(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:V(e.sizeBytes)}),s(`td`,{className:`px-3 py-1.5`,children:n(`div`,{className:`flex items-center justify-end gap-1`,children:[n(`button`,{onClick:()=>{b(e)},disabled:v===e.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:[v===e.id?s(N,{className:`h-3 w-3 animate-spin`}):s(D,{className:`h-3 w-3`}),`Download`]}),i&&c&&n(`button`,{onClick:()=>c({destinationId:t,archiveId:e.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:[s(M,{className:`h-3 w-3`}),`Restore`]}),s(`button`,{onClick:()=>{_(e)},disabled:g.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:g.isPending?s(N,{className:`h-3 w-3 animate-spin`}):s(z,{className:`h-3 w-3`})})]})})]},e.id))})]})})}function ue(e,t){return`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function Y(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}t();var X=[[`backup`,`listSchedules`]];function de({onEdit:e,onOpenRestoreWizard:t}){let{data:i,isLoading:a,isError:c}=l(),u=i??[],d=g().data??[],f=r(()=>{let e=new Map;for(let t of d)e.set(t.id,t);return e},[d]),[p,m]=o(null),h=e=>{m(t=>t===e?null:e)};return a?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading backup entries…`}):c?s(`div`,{className:`text-xs text-danger`,children:`Failed to load backup entries`}):u.length===0?s(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:s(`p`,{className:`text-xs text-foreground-subtle`,children:`No backup entries yet. Create one to schedule backups across one or more storage locations.`})}):s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[820px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[s(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),s(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Entry`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),s(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Locations`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-24`,children:`Retention`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-48`,children:`Schedule`}),s(`th`,{className:`text-right px-3 py-2 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:u.map(n=>s(fe,{row:n,destById:f,isOpen:p===n.id,onToggle:()=>h(n.id),onEdit:()=>e(n),...t?{onOpenRestoreWizard:t}:{}},n.id))})]})})}function fe({row:t,destById:l,isOpen:u,onToggle:d,onEdit:f,onOpenRestoreWizard:p}){let m=a(),h=C(),g=T({onSuccess:()=>{m.invalidateQueries({queryKey:X})}}),_=b({onSuccess:()=>{m.invalidateQueries({queryKey:X})}}),v=w({onSuccess:()=>{m.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),m.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]})}}),[y,x]=o(String(t.retentionCount));c(()=>{x(String(t.retentionCount))},[t.retentionCount]);let S=r(()=>({id:t.id,label:t.label,cron:t.cron,locationIds:[...t.locationIds],retentionCount:t.retentionCount,...t.dataSources?{dataSources:[...t.dataSources]}:{}}),[t]),E=e(e=>{g.mutate({...S,enabled:e})},[g,S]),D=e(()=>{let e=Number.parseInt(y,10);if(Number.isNaN(e)||e<1){x(String(t.retentionCount));return}e!==t.retentionCount&&g.mutate({...S,enabled:t.enabled,retentionCount:e})},[g,S,y,t.retentionCount,t.enabled]),O=e(()=>{t.locationIds.length!==0&&v.mutate({destinations:[...t.locationIds],...t.dataSources&&t.dataSources.length>0?{locations:[...t.dataSources]}:{},label:t.label,retentionCount:t.retentionCount})},[v,t]),j=e(async()=>{await h({title:`Delete backup entry?`,message:`"${t.label||t.id}" will stop running. Existing archives are kept.`,confirmLabel:`Delete`,variant:`warning`})&&_.mutate({id:t.id})},[h,_,t.id,t.label]),M=t.cron.trim().length>0,F=g.isPending||_.isPending;return n(i,{children:[n(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[s(`td`,{className:`px-2 py-2`,children:s(`button`,{onClick:d,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:u?`Hide archives`:`Show archives`,children:s(u?I:P,{className:`h-3.5 w-3.5`})})}),s(`td`,{className:`px-3 py-2`,children:n(`button`,{onClick:f,className:`text-left hover:underline focus:outline-none`,children:[s(`div`,{className:`text-foreground font-medium`,children:t.label||`(unnamed)`}),t.lastRunAt!==void 0&&n(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[`last run `,new Date(t.lastRunAt).toLocaleString()]})]})}),s(`td`,{className:`px-3 py-2`,children:s(`label`,{className:`inline-flex items-center cursor-pointer`,children:s(`input`,{type:`checkbox`,className:`accent-primary`,checked:t.enabled,disabled:F,onChange:e=>E(e.target.checked)})})}),s(`td`,{className:`px-3 py-2`,children:n(`div`,{className:`flex flex-wrap gap-1`,children:[t.locationIds.length===0&&s(`span`,{className:`text-[11px] text-danger italic`,children:`No locations`}),t.locationIds.map(e=>s(`span`,{className:`inline-flex items-center rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-foreground`,title:e,children:l.get(e)?.displayName??e},e))]})}),s(`td`,{className:`px-3 py-2`,children:s(`input`,{type:`number`,min:1,max:1e3,value:y,disabled:F,onChange:e=>x(e.target.value),onBlur:D,onKeyDown:e=>{e.key===`Enter`&&e.target.blur(),e.key===`Escape`&&x(String(t.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`})}),s(`td`,{className:`px-3 py-2`,children:n(`button`,{onClick:f,className:`group flex flex-col items-start gap-0.5 text-left`,title:`Edit schedule`,children:[n(`span`,{className:`inline-flex items-center gap-1`,children:[s(q,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),s(`span`,{className:`font-mono text-[11px] text-foreground`,children:M?t.cron:`Manual`})]}),M&&t.nextRunAt!==void 0&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`next `,new Date(t.nextRunAt).toLocaleString()]})]})}),s(`td`,{className:`px-3 py-2`,children:n(`div`,{className:`flex items-center justify-end gap-1.5`,children:[n(`button`,{onClick:O,disabled:v.isPending||t.locationIds.length===0,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 disabled:opacity-50`,title:`Run this entry now`,children:[v.isPending?s(N,{className:`h-3 w-3 animate-spin`}):s(A,{className:`h-3 w-3`}),`Run now`]}),s(`button`,{onClick:f,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-foreground hover:bg-primary/5`,title:`Edit entry`,children:s(k,{className:`h-3 w-3`})}),s(`button`,{onClick:()=>{j()},disabled:F,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-danger hover:border-danger/40 disabled:opacity-50`,title:`Delete entry`,children:s(z,{className:`h-3 w-3`})})]})})]}),u&&s(`tr`,{className:`border-t border-border bg-background/30`,children:n(`td`,{colSpan:7,className:`px-4 py-3 space-y-4`,children:[t.locationIds.length===0&&s(`p`,{className:`text-xs text-foreground-subtle italic`,children:`This entry has no locations selected.`}),t.locationIds.map(e=>n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:l.get(e)?.displayName??e}),s(le,{destinationId:e,restoreSupported:l.get(e)?.restoreSupported??!0,...p?{onOpenRestoreWizard:p}:{}})]},e))]})})]})}t();var Z=[{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 pe(e){let t=e.trim();for(let e of Z)if(e.cron===t)return e.id;return`custom`}function me({value:e,onChange:t,previewCount:r=5,disabled:i=!1}){let a=pe(e),[l,u]=o(a===`custom`);c(()=>{a!==`custom`&&u(!1)},[a]);let d=_e(e,250),f=S({cron:d,count:r},{enabled:d.trim().length>0}),p=f.data??null,m=e=>{u(!1),t(e.cron)},h=l||a===`custom`;return n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),n(`div`,{className:`flex flex-wrap gap-1.5`,children:[Z.map(e=>s(`button`,{type:`button`,onClick:()=>m(e),disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!l&&a===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)),s(`button`,{type:`button`,onClick:()=>{u(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(h?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),h&&n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),s(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:i,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`}),n(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,s(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),s(he,{cron:d,preview:p,loading:f.isFetching})]})}function he({cron:e,preview:t,loading:r}){return r&&t===null?n(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[s(N,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?s(`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.`}):n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),s(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>n(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[s(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),s(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:ge(e)})]},`${e}-${t}`))})]}):s(`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 ge(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 _e(e,t){let[n,i]=o(e),a=r(()=>e,[e]);return c(()=>{let e=setTimeout(()=>i(a),t);return()=>clearTimeout(e)},[a,t]),n}t();var ve=[[`backup`,`listSchedules`]];function ye({entry:e,onClose:t,onSaved:i}){let c=a(),l=g(),u=l.data??[],[d,f]=o(e?.label??``),[p,m]=o(e?.cron??`0 3 * * *`),[h,_]=o(e?.enabled??!0),[v,y]=o(String(e?.retentionCount??7)),[b,x]=o(new Set(e?.locationIds??[])),S=T({onSuccess:()=>{c.invalidateQueries({queryKey:ve}),i()}}),C=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},w=Number.parseInt(v,10),E=r(()=>d.trim().length>0&&b.size>0&&!Number.isNaN(w)&&w>=1&&w<=1e3,[d,b,w]),D=()=>{E&&S.mutate({...e?{id:e.id}:{},label:d.trim(),cron:p.trim(),enabled:h,locationIds:Array.from(b),retentionCount:w})},O=S.error instanceof Error?S.error.message:null;return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:n(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3 sticky top-0 bg-surface`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e?`Edit backup entry`:`New backup entry`}),s(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:s(L,{className:`h-4 w-4`})})]}),n(`div`,{className:`p-4 space-y-4`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Name`}),s(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`Nightly offsite`,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`})]}),n(`div`,{className:`space-y-1.5`,children:[n(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:[`Locations (`,b.size,` selected)`]}),l.isLoading&&n(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[s(N,{className:`h-3.5 w-3.5 animate-spin`}),`Loading locations…`]}),!l.isLoading&&u.length===0&&s(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:"No `backups` storage locations configured. Add one in Settings → Storage first."}),u.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-52 overflow-y-auto`,children:u.map(e=>n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`checkbox`,checked:b.has(e.id),onChange:()=>C(e.id),className:`accent-primary`}),s(`span`,{className:`text-foreground`,children:e.displayName})]}),n(`div`,{className:`flex items-center gap-1.5`,children:[s(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-surface border border-border rounded px-1.5 py-0.5`,children:e.kind}),s(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]},e.id))})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Retention (archives kept)`}),s(`input`,{type:`number`,min:1,max:1e3,value:v,onChange:e=>y(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`})]}),n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Enabled`}),n(`label`,{className:`inline-flex items-center gap-2 py-1.5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:h,onChange:e=>_(e.target.checked),className:`accent-primary`}),s(`span`,{className:`text-xs text-foreground-subtle`,children:`Run on schedule`})]})]})]}),n(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Schedule`}),s(me,{value:p,onChange:m,disabled:S.isPending})]}),O&&s(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:O})]}),n(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3 sticky bottom-0 bg-surface`,children:[s(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),n(`button`,{onClick:D,disabled:!E||S.isPending,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:[S.isPending&&s(N,{className:`h-3.5 w-3.5 animate-spin`}),e?`Save`:`Create entry`]})]})]})})}t();var be=[[`backup`,`list`]];function xe({initialDestinationId:e,initialArchiveId:t,onClose:i,onScheduled:l}){let u=a(),[d,f]=o(e&&t?2:1),[p,m]=o(e),[h,_]=o(t),[v,b]=o(new Set),{data:S}=g(),C=S??[],{data:w,isLoading:T}=x({destinationId:p??``},{enabled:!!p}),D=w??[];c(()=>{if(p!==void 0)return;let e=C.filter(e=>e.restoreSupported);e.length===1&&m(e[0].id)},[p,C]);let{data:O}=y({destinationId:p??``,backupId:h??``},{enabled:!!p&&!!h}),k=r(()=>O?.locations??[],[O]);c(()=>{k.length!==0&&b(e=>e.size===0?new Set(k):e)},[k]);let A=E({onSuccess:()=>{u.invalidateQueries({queryKey:be}),l(),i()}}),j=e=>{b(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},P=!!p&&!!h,F=v.size>0,I=P&&F&&!A.isPending,R=()=>{!p||!h||A.mutate({destinationId:p,backupId:h,locations:[...v]})};return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:i,children:n(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[n(`div`,{className:`space-y-0.5`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),n(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,d,` of 3 —`,` `,d===1?`pick source`:d===2?`pick locations`:`confirm`]})]}),s(`button`,{onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:s(L,{className:`h-4 w-4`})})]}),d===1&&s(Se,{destinations:C,destinationId:p,onPickDestination:e=>{m(e),_(void 0),b(new Set)},archives:D,archivesLoading:T,archiveId:h,onPickArchive:_}),d===2&&s(Ce,{locations:k,picked:v,onToggle:j}),d===3&&s(we,{destinationName:C.find(e=>e.id===p)?.displayName??p??``,archive:D.find(e=>e.id===h),picked:[...v]}),n(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[s(`div`,{children:d>1&&n(`button`,{onClick:()=>f(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:[s(ee,{className:`h-3 w-3`}),`Back`]})}),n(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),d<3?n(`button`,{disabled:d===1&&!P||d===2&&!F,onClick:()=>f(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`,s(K,{className:`h-3 w-3`})]}):n(`button`,{onClick:R,disabled:!I,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?s(N,{className:`h-3.5 w-3.5 animate-spin`}):s(M,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function Se({destinations:e,destinationId:t,onPickDestination:r,archives:i,archivesLoading:a,archiveId:o,onPickArchive:c}){let l=e.filter(e=>e.restoreSupported);return n(`div`,{className:`p-4 space-y-3`,children:[n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),n(`select`,{value:t??``,onChange:e=>r(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:[s(`option`,{value:``,disabled:!0,children:`Select destination…`}),l.map(e=>n(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&a&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!a&&i.length===0&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&i.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:i.map(e=>{let t=o===e.id;return n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>c(e.id),className:`accent-primary`}),n(`div`,{children:[s(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),s(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:V(e.sizeBytes)})]},e.id)})})]})]})}function Ce({locations:e,picked:t,onToggle:r}){return e.length===0?s(`div`,{className:`p-4`,children:s(`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.`})}):n(`div`,{className:`p-4 space-y-3`,children:[s(`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.`}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>n(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>r(e),className:`accent-primary`}),s(`span`,{className:`font-mono text-foreground`,children:e}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ee(e)})]},e))})]})]})}function we({destinationName:e,archive:t,picked:r}){return n(`div`,{className:`p-4 space-y-3 text-xs`,children:[s(`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.`}),n(`dl`,{className:`space-y-1.5`,children:[s(Q,{term:`Destination`,value:e}),s(Q,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&s(Q,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${V(t.sizeBytes)}`}),s(Q,{term:`Locations`,value:r.length>0?r.join(`, `):`— (full archive)`})]})]})}function Q({term:e,value:t}){return n(`div`,{className:`flex justify-between gap-3`,children:[s(`dt`,{className:`text-foreground-subtle`,children:e}),s(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Te={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function Ee(e){return Te[e]??``}t();function De(){let e=C(),t=h(),[r,i]=o(null),[a,c]=o(!1),[l,u]=o(!1),[d,f]=o(void 0),p=async()=>{await e({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&t.mutate({confirm:!0})};return n(B,{children:[n(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[n(`button`,{onClick:()=>c(!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:[s(M,{className:`h-3.5 w-3.5`}),`Restore…`]}),n(`button`,{onClick:()=>f(null),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:[s(j,{className:`h-3.5 w-3.5`}),`New entry`]})]}),l&&s(`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:n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(M,{className:`h-3.5 w-3.5`}),s(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),n(`button`,{onClick:()=>{p()},disabled:t.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:[t.isPending?s(N,{className:`h-3.5 w-3.5 animate-spin`}):s(M,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),s(de,{onEdit:e=>f(e),onOpenRestoreWizard:e=>i(e)}),d!==void 0&&s(ye,{entry:d,onClose:()=>f(void 0),onSaved:()=>f(void 0)}),(r||a)&&s(xe,{...r?{initialDestinationId:r.destinationId,initialArchiveId:r.archiveId}:{},onClose:()=>{i(null),c(!1)},onScheduled:()=>u(!0)})]})}t();var $=5e3,Oe={"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 ke(){let e=u({capName:`log-destination`},{refetchInterval:$}),t=d(void 0,{refetchInterval:$}),n=r(()=>W(t.data??[]),[t.data]),i=r(()=>{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 s(U,{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:R,itemIcon:J,capability:`log-destination`,installButtonLabel:`Add destination`,items:r(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive,caption:i.get(e.addonId)??Oe[e.addonId]??``})),[e.data,n,i]),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?s(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.caption}):null})}function Ae(){return s(`div`,{className:`flex flex-col p-4`,children:s(ne,{tabs:[{id:`storage`,label:`Storage`,icon:O,content:s(oe,{})},{id:`backup`,label:`Backup`,icon:G,content:s(De,{})},{id:`logging`,label:`Logging`,icon:R,content:s(ke,{})}]})})}export{Ae as DataPage};
@@ -1,2 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,W as i,a,b as o,o as s,q as c,t as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{K as f,W as p,Z as m,o as h,r as g,t as _,v}from"./player-overlays-DN_06_1T.js";import{$ as y,$t as b,A as x,Bt as S,D as C,Dr as w,E as T,Ei as E,Fo as D,G as O,Gr as k,H as A,Hr as ee,I as te,Ir as j,J as ne,Jr as M,Jt as N,K as P,Ka as re,L as F,Lr as I,M as ie,Mr as ae,Nr as L,O as R,P as z,Qr as B,Qt as oe,R as se,Rt as ce,Ti as V,U as H,Ua as le,V as U,Va as ue,Vr as W,Vt as G,W as de,Xa as K,Xi as q,Xr as fe,Yr as pe,Zr as me,Zt as he,_ as ge,a as _e,aa as ve,an as ye,at as be,b as xe,c as Se,co as J,ct as Ce,d as we,dt as Te,et as Ee,ft as De,gr as Oe,gt as ke,hr as Ae,i as je,ja as Me,jn as Ne,k as Pe,ko as Fe,l as Ie,ln as Le,lt as Re,mo as ze,mt as Be,o as Ve,oa as He,on as Ue,ot as We,pt as Ge,qn as Ke,qr as qe,r as Je,ra as Ye,s as Xe,sn as Ze,so as Qe,u as $e,ut as et,v as tt,vi as nt,wi as rt,wr as it,y as at,z as ot,zo as st,zr as ct,zt as lt}from"./src-Dw_YuA21.js";import{Ft as ut,It as dt,Pt as ft,a as pt,ft as mt,i as ht,mt as Y}from"./src-5IxHiQXr.js";import{t as gt}from"./CapabilityBadges-D5vvC1yi.js";import{n as _t,t as vt}from"./bell-ring-BSDAxanc.js";import{t as yt}from"./boxes-OU9o0K_I.js";import{t as bt}from"./ProviderIcon-MfX3M-Ob.js";import{c as xt,d as St,n as Ct,s as wt,u as Tt}from"./NodeInferenceDevices-B73NC03X.js";import{n as Et}from"./FormBuilder-DoXEuyDl.js";import{t as Dt}from"./pencil-C9e8FY_K.js";import{t as Ot}from"./power-C-BBysAq.js";import{t as kt}from"./refresh-cw-S_IzGUwN.js";import{t as At}from"./rotate-ccw-CAAGiLAw.js";import{t as jt}from"./rotate-cw-DVJmPlX9.js";import{t as Mt}from"./server-CouJc0au.js";import{t as Nt}from"./wifi-B8upcnaM.js";import{C as Pt,G as Ft,J as It,K as X,M as Lt,N as Rt,U as zt,V as Bt,X as Vt,Y as Ht,a as Ut,b as Wt,c as Gt,d as Kt,g as qt,i as Jt,m as Yt,s as Xt,t as Zt,y as Qt,z as $t}from"./index-B1t00qUp.js";import"./useEventInvalidation-Co1T3fjc.js";import{t as en}from"./StatusBadge-CeptlsPG.js";import{i as tn,n as nn,r as rn,t as an}from"./DeviceAggregateSection-BCYifsQE.js";var on=X(`circle-help`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),sn=X(`disc`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]),cn=X(`ear`,[[`path`,{d:`M6 8.5a6.5 6.5 0 1 1 13 0c0 6-6 6-6 10a3.5 3.5 0 1 1-7 0`,key:`1dfaln`}],[`path`,{d:`M15 8.5a2.5 2.5 0 0 0-5 0v1a2 2 0 1 1 0 4`,key:`1qnva7`}]]),ln=X(`hand`,[[`path`,{d:`M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2`,key:`1fvzgz`}],[`path`,{d:`M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2`,key:`1kc0my`}],[`path`,{d:`M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8`,key:`10h0bg`}],[`path`,{d:`M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15`,key:`1s1gnw`}]]),un=X(`link-2`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]),dn=X(`mouse-pointer-click`,[[`path`,{d:`M14 4.1 12 6`,key:`ita8i4`}],[`path`,{d:`m5.1 8-2.9-.8`,key:`1go3kf`}],[`path`,{d:`m6 12-1.9 2`,key:`mnht97`}],[`path`,{d:`M7.2 2.2 8 5.1`,key:`1cfko1`}],[`path`,{d:`M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z`,key:`s0h3yz`}]]),fn=X(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]);n();var pn=[{id:`object-detection`,label:`Object detection`,costWhenOff:`No detections, tracks or detection-driven notifications for this camera.`,capName:ut},{id:`audio-analysis`,label:`Audio analysis`,costWhenOff:`No audio events (glass, alarm, speech) and no audio-driven notifications.`,capName:ft}],mn=`Recording`,hn=`Nothing new is written to disk — live still works, existing footage is kept.`;function gn(e,t){let{bindings:n,bindable:r}=t,i=n===null?void 0:n.find(t=>t.capName===e.capName&&t.kind===`wrapped`),a=r?.find(t=>t.capName===e.capName)?.wrappers[0],o=i!==void 0&&i.providerAddonId!==``?i.providerAddonId:a??null,s=n===null?null:i!==void 0;return{id:e.id,label:e.label,costWhenOff:e.costWhenOff,on:s,available:s!==null&&o!==null,capName:e.capName,wrapperAddonId:o}}function _n(e,t,n,r){let i=e.entries.filter(e=>e.capName!==t);return r?{...e,entries:[...i,{capName:t,kind:`wrapped`,providerAddonId:n}]}:{...e,entries:i}}function vn(e,t){let n=e.filter(e=>e.on===!1).map(e=>e.id),r=e.filter(e=>e.on===null).map(e=>e.id),i=t=>t.map(t=>e.find(e=>e.id===t)?.label??t).join(`, `),a=[];return n.length>0&&a.push(`Off: ${i(n)}`),r.length>0&&a.push(`Unknown: ${i(r)}`),{layout:t?`menu`:`inline`,offIds:n,unknownIds:r,summary:a.length===0?`All camera functions on`:a.join(` · `)}}function yn(e){let t=pn.map(t=>gn(t,e)),n={id:`recording`,label:mn,costWhenOff:hn,on:e.recordingEnabled,available:e.recordingEnabled!==null,capName:null,wrapperAddonId:null};return[...t,n]}var bn={"object-detection":qt,"audio-analysis":cn,recording:sn};function xn(e){if(typeof e!=`object`||!e)return!1;let t={...e};return typeof t.enabled==`boolean`&&Array.isArray(t.bands)}function Sn(e){if(typeof e!=`object`||!e)return!1;let t={...e};return typeof t.deviceId==`number`&&Array.isArray(t.entries)}function Cn(e){return Sn(e)?e.entries:null}function wn(e){if(!Array.isArray(e))return null;let t=[];for(let n of e){if(typeof n!=`object`||!n)continue;let e={...n},r=e.capName,i=e.wrappers;typeof r!=`string`||!Array.isArray(i)||t.push({capName:r,wrappers:i.filter(e=>typeof e==`string`)})}return t}function Tn({deviceId:t}){let n=s(),i=Number.isFinite(t),[a,o]=c(null),[l,d]=c(!1),f=L({deviceId:t},{enabled:i}),p=W({deviceType:Y.Camera},{enabled:i}),m=D({deviceId:t},{enabled:i,retry:!1});je([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let h=[[`deviceManager`,`getBindings`],{input:{deviceId:t}}],g=[[`recording`,`getDeviceConfig`],{input:{deviceId:t}}],_=m.data,v=xn(_)?_:null,y=yn({bindings:Cn(f.data),bindable:wn(p.data),recordingEnabled:v===null?null:v.enabled}),b=B({onError:(e,r)=>{let i=r.capName===y[1]?.capName?`audio-analysis`:`object-detection`;console.error(`[CameraFunctionSwitches] wrapper write failed — reverting`,{tags:{deviceId:t},meta:{capName:r.capName,error:e instanceof Error?e.message:String(e)}}),n.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]}),o({id:i,message:e instanceof Error?e.message:String(e)})},onSuccess:()=>{o(null),n.invalidateQueries({queryKey:[[`deviceManager`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]})}}),x=st({onError:e=>{console.error(`[CameraFunctionSwitches] recording write failed — reverting`,{tags:{deviceId:t},meta:{error:e instanceof Error?e.message:String(e)}}),n.invalidateQueries({queryKey:[[`recording`,`getDeviceConfig`]]}),o({id:`recording`,message:e instanceof Error?e.message:String(e)})},onSuccess:()=>{o(null),n.invalidateQueries({queryKey:[[`recording`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`]]})}}),S=e(e=>{if(!e.available||e.on===null)return;let r=!e.on;if(e.id===`recording`){if(v===null)return;n.setQueryData(g,{...v,enabled:r}),x.mutate({deviceId:t,config:{...v,enabled:r}});return}let{capName:i,wrapperAddonId:a}=e;if(i===null||a===null)return;let o=n.getQueryData(h);Sn(o)&&n.setQueryData(h,_n(o,i,a,r)),b.mutate({deviceId:t,capName:i,wrapperAddonId:a,active:r})},[h,t,n,v,g,x,b]),C=vn(y,ke()),w=e=>a?.id===e.id?a.message:null;return C.layout===`menu`?r(De,{open:l,onOpenChange:d,children:[r(Be,{"aria-label":`Camera functions`,title:C.summary,className:`inline-flex items-center gap-1 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors ${a===null?C.offIds.length>0?`border-warning/40 text-warning hover:bg-warning/10`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`:`border-danger/50 text-danger bg-danger/5`}`,children:[u(Kt,{className:`h-3.5 w-3.5`}),C.offIds.length>0&&r(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:[C.offIds.length,` off`]})]}),r(Ge,{className:`left-auto right-0 mt-1 min-w-[240px] p-1`,children:[u(`div`,{className:`px-2 py-1 text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Camera functions`}),u(`ul`,{className:`space-y-0.5`,children:y.map(e=>u(`li`,{children:u(En,{state:e,failure:w(e),onToggle:()=>S(e)})},e.id))})]})]}):u(`div`,{className:`flex items-center gap-1`,children:y.map(e=>u(Dn,{state:e,failure:w(e),onToggle:()=>S(e)},e.id))})}function En({state:e,failure:t,onToggle:n}){let i=bn[e.id],a=e.on===null,o=e.on===!1;return r(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:a?`${e.label} — state unknown; the source that owns it did not answer.`:t===null?e.costWhenOff:`Last write failed: ${t}`,className:`flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left text-[12px] text-foreground transition-colors hover:bg-surface-hover disabled:opacity-40 disabled:cursor-not-allowed`,children:[u(i,{className:`h-3.5 w-3.5 shrink-0 mt-0.5 ${t===null?a?`text-foreground-subtle/50`:o?`text-warning`:`text-success`:`text-danger`}`}),r(`span`,{className:`flex-1 min-w-0`,children:[u(`span`,{className:`block leading-tight`,children:e.label}),u(`span`,{className:`block mt-0.5 text-[10px] text-foreground-subtle leading-tight`,children:t===null?a?`Unknown`:e.costWhenOff:`Write failed: ${t}`})]}),u(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[9px] font-semibold uppercase tracking-wide ${a?`bg-surface-hover text-foreground-subtle/60`:o?`bg-warning/20 text-warning`:`bg-success/20 text-success`}`,children:a?`—`:o?`off`:`on`})]})}function Dn({state:e,failure:t,onToggle:n}){let i=bn[e.id],a=e.on===null,o=e.on===!1,s=a?`${e.label} — state unknown; the source that owns it did not answer.`:o?`${e.label} is OFF. ${e.costWhenOff}`:`${e.label} is on. Turning it off: ${e.costWhenOff}`;return r(`button`,{type:`button`,role:`switch`,"aria-label":e.label,"aria-checked":e.on===!0,disabled:!e.available,onClick:n,title:t===null?s:`${s} — last write failed: ${t}`,className:`inline-flex items-center gap-1 rounded-lg border px-1.5 sm:px-2 py-1.5 text-[11px] font-medium transition-colors disabled:cursor-not-allowed ${t===null?a?`border-dashed border-border text-foreground-subtle/50`:o?`border-warning/40 text-warning hover:bg-warning/10`:`border-success/30 text-success hover:bg-success/10`:`border-danger/50 text-danger bg-danger/5`}`,children:[u(i,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden lg:inline`,children:e.label}),o&&u(`span`,{className:`rounded bg-warning/20 px-1 text-[9px] font-semibold uppercase tracking-wide`,children:`off`})]})}function On({parentDeviceId:e}){let{t}=Zt(),n=It(),i=m(),{data:a,isLoading:o,isError:s}=xt(e),{data:c}=j({deviceId:e},{enabled:Number.isFinite(e)});if(o)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(s)return u(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:u(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let l=(a??[]).filter(e=>e.display?.hidden!==!0);if(l.length===0)return null;let d=R(c?.stableId??``,l,c?.childLayout),f=d.ungrouped,p=e=>n(`/devices/${String(e)}`),h=c?.name??``,g=(e,t)=>u(T,{trpc:i.trpcClient,device:{...t,name:x(t,h)},variant:`minimal`,onNavigate:p},e),_=f.some(e=>!!e.role),v=f.some(e=>!e.role),y=_&&!v?t(`device.accessories`,{defaultValue:`Accessories`}):!_&&v?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),b=f.length>0?r(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[u(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:y}),u(`div`,{className:`space-y-1`,children:f.map(e=>g(e.id,e))})]}):null,S=d.disabledSection===void 0?null:u(C,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:d.disabledSection.children.length,defaultOpen:!1,children:u(`div`,{className:`opacity-60 space-y-1`,children:d.disabledSection.children.map(e=>g(e.id,e))})},d.disabledSection.title);return d.sections.length===0?S===null?b:r(`div`,{className:`space-y-2`,children:[b,S]}):r(`div`,{className:`space-y-2`,children:[d.sections.map(e=>u(C,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>g(e.id,e))},e.title)),b,S]})}function kn({deviceId:e}){let t=m(),{data:n,isLoading:r}=wt(e),{data:i,isLoading:a}=xt(e),o=r||a,s=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),c=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,l=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return o?u(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):u(`div`,{className:`flex h-full w-full flex-col`,children:u(F,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}n();function An({dev:e,busy:t,setBusy:n}){let i=e?.motionTrigger,a=f(e?.state.motionTrigger),[o,s]=c(!1);if(!i)return null;let l=a?.enabled===!0,d=a!==void 0,p=async()=>{if(t||!d)return;let e=!l;n(!0),s(!0);try{await i.setMotionTrigger({enabled:e})}finally{n(!1),s(!1)}};return r(`button`,{type:`button`,onClick:()=>{p()},disabled:t||!d,title:d?l?`Disable trigger on motion`:`Enable trigger on motion`:`Awaiting state…`,"aria-pressed":l,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${l?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[u(Ft,{className:`h-3 w-3`}),u(`span`,{children:o?l?`Disabling…`:`Enabling…`:d?l?`On motion: on`:`On motion: off`:`On motion: …`})]})}n();function Z({deviceId:e,deviceType:t,features:n}){let i=m(),a=U(t)?.HeroCard??A,o=p(i.trpcClient,e),s=f(o?.state.deviceStatus),[l,d]=c(!1),h=s!==void 0&&s.online===!1,g=h?s.lastChangedAt:null;return r(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[h?u(`div`,{className:`flex justify-center`,children:u(ot,{lastChangedAt:g})}):null,u(a,{trpc:i.trpcClient,deviceId:e,features:n}),u(`div`,{className:`flex justify-center`,children:u(An,{dev:o,busy:l,setBusy:d})})]})}function jn({deviceId:e,features:t}){return u(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:u(H,{trpc:m().trpcClient,deviceId:e,features:t})})}function Mn({deviceId:e,features:t}){return u(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:u(A,{trpc:m().trpcClient,deviceId:e,features:t})})}function Nn(e){if(!e)return null;let t=e.channel;return typeof t!=`number`||!Number.isInteger(t)||t<0?null:t}function Pn(e){if(!e)return null;let t=Nn(e.data);return t===null?e.eventType:`Button ${String(t)} · ${e.eventType}`}var Fn=1e3,In=60*Fn,Ln=60*In,Rn=24*Ln;function zn(e,t){if(e==null||e<=0)return`—`;let n=t-e;return n<Fn?`just now`:n<In?`${String(Math.floor(n/Fn))}s ago`:n<Ln?`${String(Math.floor(n/In))}m ago`:n<Rn?`${String(Math.floor(n/Ln))}h ago`:`${String(Math.floor(n/Rn))}d ago`}n();var Bn=1500,Vn=15e3,Hn=1e3;function Un({deviceId:e}){let n=p(m().trpcClient,e)?.state.eventEmitter,i=f(n);d(()=>{if(!n)return;n.refresh();let e=setInterval(()=>{n.refresh()},Vn);return()=>{clearInterval(e)}},[n]);let a=i?.lastEvent??null,o=a?.seq??null,s=t(null),[l,h]=c(!1);d(()=>{if(o===null)return;let e=s.current;if(s.current=o,e===null||e===o)return;h(!0);let t=setTimeout(()=>{h(!1)},Bn);return()=>{clearTimeout(t)}},[o]);let[g,_]=c(()=>Date.now());d(()=>{let e=setInterval(()=>{_(Date.now())},Hn);return()=>{clearInterval(e)}},[]);let v=Pn(a),y=i?.eventTypes??[],b=i?.eventCountSinceStart??0,x=i!==void 0,S=Nn(a?.data);return r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 p-4`,children:[u(`div`,{"data-testid":`event-emitter-indicator`,"data-flashing":String(l),className:`flex h-24 w-24 items-center justify-center rounded-full border-2 transition-all ${l?`border-primary bg-primary/20 text-primary shadow-lg shadow-primary/30 scale-105`:`border-border bg-surface text-foreground-subtle`}`,"aria-live":`polite`,title:v??`No press recorded`,children:u(l?dn:ln,{className:`h-10 w-10`})}),r(`div`,{className:`text-center`,children:[S!==null&&u(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-primary`,children:`Button ${String(S)}`}),u(`div`,{"data-testid":`event-emitter-headline`,className:`text-sm font-semibold ${v?`text-foreground`:`text-foreground-subtle`}`,children:v??(x?`No press recorded`:`Awaiting state…`)}),u(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:a?zn(a.timestamp,g):`Waiting for the first event`})]}),y.length>0&&u(`div`,{className:`flex max-w-full flex-wrap justify-center gap-1`,children:y.map(e=>u(`span`,{"data-testid":`event-emitter-chip`,className:`rounded-full border px-2 py-0.5 text-[10px] font-medium ${e===a?.eventType?`border-primary bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle`}`,children:e},e))}),u(`div`,{className:`text-[10px] text-foreground-subtle`,children:`${String(b)} ${b===1?`event`:`events`} since start`})]})}function Wn({deviceName:e,deviceType:t,provider:n,isOnline:i,features:a}){return r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[u(bt,{type:n,size:`lg`}),r(`div`,{children:[u(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),u(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),r(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[u(en,{status:i?`online`:`offline`}),a.length>0&&u(gt,{capabilities:a})]}),u(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:`No live view for this device type. Use the Config tab or the shortcut row to interact.`})]})}n();function Gn({deviceId:e}){let t=s(),n=Ae({deviceId:e},{refetchInterval:1e4,retry:!1}),a=Oe({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),o=i(()=>Kn(n.data??[]),[n.data]);return r(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[r(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[u(qn,{label:`Discovered`,value:o.total,icon:u(Qt,{className:`h-3.5 w-3.5`})}),u(qn,{label:`Adopted`,value:o.adopted,accent:`success`}),u(qn,{label:`Available`,value:o.available,accent:o.available>0?`primary`:void 0}),r(`button`,{type:`button`,onClick:()=>{a.mutateAsync({deviceId:e}).catch(()=>{})},disabled:a.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[a.isPending?u(Pt,{className:`h-3.5 w-3.5 animate-spin`}):u(kt,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[u(Jn,{icon:u(Nt,{className:`h-3 w-3 text-emerald-500`}),label:`${o.online} online`}),u(Jn,{icon:u(Wt,{className:`h-3 w-3 text-amber-500`}),label:`${o.sleeping} sleeping`}),u(Jn,{icon:u(Ut,{className:`h-3 w-3 text-destructive`}),label:`${o.offline} offline`}),o.unknown>0?u(Jn,{icon:u(on,{className:`h-3 w-3 text-foreground-subtle`}),label:`${o.unknown} unknown`}):null]})]})}function Kn(e){let t={total:e.length,adopted:0,available:0,online:0,sleeping:0,offline:0,unknown:0};for(let n of e)n.alreadyAdopted?t.adopted+=1:t.available+=1,t[n.status]+=1;return t}function qn({label:e,value:t,icon:n,accent:i}){return r(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${i===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:i===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[r(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,u(`span`,{className:`truncate`,children:e})]}),u(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function Jn({icon:e,label:t}){return r(`span`,{className:`inline-flex items-center gap-1`,children:[e,u(`span`,{children:t})]})}var Yn={[Y.Switch]:Z,[Y.Siren]:Z,[Y.Light]:Z,[Y.Sensor]:Z,[Y.Button]:Z,[Y.Hub]:Gn,[Y.Cover]:jn,[Y.Valve]:Z,[Y.Humidifier]:Z,[Y.WaterHeater]:Z,[Y.Container]:kn,[Y.Lock]:Z,[Y.Fan]:Z,[Y.Thermostat]:Z,[Y.Climate]:Z,[Y.MediaPlayer]:Z,[Y.Control]:Z,[Y.AlarmPanel]:Z,[Y.EventEmitter]:Un,[Y.Notifier]:Mn,[Y.Script]:Z,[Y.Automation]:Z,[Y.Presence]:Z,[Y.Update]:Z,[Y.Vacuum]:Z,[Y.LawnMower]:Z,[Y.Weather]:Z,[Y.Image]:Z,[Y.PetFeeder]:Z};function Xn(e){return Yn[e]??Wn}function Zn(e){return u(Xn(e.deviceType),{...e})}function Qn(e){return Xe(m().trpcClient,e)}n();function $n(n){let[r,i]=c(`idle`),[a,o]=c(null),s=t(null),l=t(null),u=t(null),f=t(!0),p=V(),m=rt(),h=E(),g=e(()=>{if(s.current){try{s.current.close()}catch{}s.current=null}if(l.current){for(let e of l.current.getTracks())try{e.stop()}catch{}l.current=null}u.current=null},[]),_=e(async()=>{if(r===`idle`)return;i(`stopping`);let e=u.current;if(e&&n!==null)try{await Promise.race([h.mutateAsync({deviceId:n,sessionId:e}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}g(),f.current&&(i(`idle`),o(null))},[r,n,h,g]),v=e(async()=>{if(n===null||r!==`idle`&&r!==`error`)return;o(null);let e=null,t=null,a=null;try{i(`requesting-mic`),e=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),l.current=e,i(`starting`);let r=await p.mutateAsync({deviceId:n});a=r.sessionId,u.current=a,i(`connecting`),t=new RTCPeerConnection,s.current=t,t.oniceconnectionstatechange=()=>{if(!f.current)return;let e=t.iceConnectionState;e===`connected`||e===`completed`?i(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&f.current&&(o(e===`failed`?`WebRTC connection failed`:null),_())};for(let n of e.getAudioTracks())t.addTrack(n,e);await t.setRemoteDescription({type:`offer`,sdp:r.sdpOffer});let c=await t.createAnswer();await t.setLocalDescription(c);let d=t.localDescription?.sdp??c.sdp??``;await m.mutateAsync({deviceId:n,sessionId:a,sdpAnswer:d})}catch(r){let c=r instanceof Error?r.message:String(r);if(console.warn(`[intercom] start failed`,r),t)try{t.close()}catch{}if(e)for(let t of e.getTracks())try{t.stop()}catch{}if(s.current=null,l.current=null,a!==null)try{await h.mutateAsync({deviceId:n,sessionId:a})}catch{}u.current=null,f.current&&(o(c),i(`error`))}},[n,r,p,m,h,_]);return d(()=>(f.current=!0,()=>{f.current=!1;let e=u.current;if(e!==null&&n!==null&&h.mutate({deviceId:n,sessionId:e}),s.current){try{s.current.close()}catch{}s.current=null}if(l.current){for(let e of l.current.getTracks())try{e.stop()}catch{}l.current=null}u.current=null}),[n]),{state:r,error:a,start:v,stop:_,isTalking:r===`talking`}}n();var er=0;function Q(){return++er}function tr(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function nr(e){return[``,`Commands`,` help Show this help`,` examples Show usage examples for the current scope`,` context Show every available variable + full API surface`,` clear Clear terminal (also Ctrl+L)`,``,`Shortcuts`,` Enter Execute expression`,` Arrow Up/Down Navigate command history`,` Ctrl+L Clear terminal`,``,`Try: ${{system:` sm.summary() // fleet overview`,device:` device.state.battery.value?.sleeping // sync read`,provider:` devices.map(d => d.name)`,addon:` manifest.version`}[e.type]}`,``,`Top-level objects: sm (SystemMirror), DeviceType, Math, JSON, Date, …`]}function rr(e){switch(e.type){case`device`:return[``,`── State (sync, zero round-trip) ─────────────────────────`,` device.state.battery.value`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,``,`── Actions (async, through wrapper chain) ────────────────`,` await device.snapshot.getSnapshot({})`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.switch.setState({ on: true })`,``,`── Wait for condition ───────────────────────────────────`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`── Subscribe to changes ─────────────────────────────────`,` const off = device.state.battery.subscribe(s => console.log(s))`,``,`── Quick info ───────────────────────────────────────────`,` info.name device name`,` info.addonId owning addon`,` sm.dump(deviceId) full debug dump`];case`system`:return[``,`── Lookups ──────────────────────────────────────────────`,` sm.getDeviceById(8)`,` sm.getDeviceByName('Sala da pranzo')`,` sm.getDevicesByAddon('reolink')`,` sm.getDevicesByType(DeviceType.Camera)`,``,`── Filters (typed query) ────────────────────────────────`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] })`,` sm.query({ name: /^Cam-/ })`,``,`── Cross-device ─────────────────────────────────────────`,` sm.whereState('battery', s => s.percentage < 20).length`,` sm.mapState('battery', s => s.percentage)`,` sm.countByCap('snapshot')`,``,`── Batch action ─────────────────────────────────────────`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,``,`── Listen ───────────────────────────────────────────────`,` sm.listenCap('motion', (id, s) => console.log(id, s))`,` sm.onDeviceAdded((id, info) => console.log('+', info.name))`,``,`── Diagnostics ──────────────────────────────────────────`,` sm.summary()`,` sm.dump(8)`];case`provider`:return[``,` devices.map(d => d.name)`,` await getIntegration()`,` sm.getDevicesByAddon('<this-addon-id>').length`];case`addon`:return[``,` manifest.name`,` manifest.version`,` declaration`]}}function ir(e){let t=[``,`Scope: ${e.type}`,``];switch(e.type){case`system`:return[...t,`Primary API — sm (SystemMirror):`,` sm.getDeviceById(id) DeviceProxy | null (sync)`,` sm.getDeviceByName(name) DeviceProxy | null`,` sm.getDeviceByStableId(sid) DeviceProxy | null`,` sm.getAllDevices() readonly DeviceProxy[]`,` sm.getDeviceInfo(id) DeviceInfo | null`,` sm.summary() fleet stats`,``,`Filters — sm.query({...}):`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] }) // ALL caps required`,` sm.query({ anyCap: ['ptz', 'motion'] }) // ANY cap`,` sm.query({ name: { contains: 'sala' } }) // case-insensitive`,` sm.query({ name: /^Cam-\\d+$/ })`,` sm.query({ type: DeviceType.Camera })`,` sm.query({ parentDeviceId: 8 }) // accessories of cam 8`,` sm.query({ where: (info, dev) => dev.state.battery.value?.sleeping })`,``,`State queries:`,` sm.whereState('battery', s => s.percentage < 20)`,` sm.mapState('battery', s => s.percentage)`,` sm.findState('motion', s => s.detected)`,` sm.countByCap('snapshot')`,``,`Listeners (return unsubscribe fn):`,` sm.listen((id, cap, slice) => …) // every state change`,` sm.listenCap('motion', (id, slice) => …)`,` sm.listenDevice(8, (id, cap, slice) => …)`,` sm.onDeviceAdded((id, info) => …)`,` sm.onDeviceRemoved((id, info) => …)`,``,`Wait primitives:`,` await sm.waitForState(8, 'battery', s => !s.sleeping, 30_000)`,` await sm.waitForDevice(99, 30_000)`,``,`Batch:`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,` await sm.forEachCap('reboot', d => d.reboot.reboot({}))`,``,`Diagnostics:`,` sm.dump(8) debug dump (one device)`,` sm.dump() full fleet dump`,` sm.summary() breakdown by cap/addon/type`,``,`Legacy: deviceRegistry, addonRegistry, eventBus, devices(), addons()`];case`device`:return[...t,`Pre-bound variables:`,` device DeviceProxy for this device (sync state + async methods)`,` deviceId number`,` info DeviceInfo metadata (name, addonId, type, online, …)`,` sm SystemMirror (full cluster view)`,` rawDevice legacy IDevice instance (escape hatch)`,``,`Reactive state (sync, zero round-trip):`,` device.state.battery.value BatteryStatus | undefined`,` device.state.battery.value?.sleeping`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,` device.state.switch.value?.on`,` device.state.brightness.value?.percentage`,` device.state.doorbell.value?.lastPressedAt`,``,`Cap actions (async, through wrapper chain):`,` await device.snapshot.getSnapshot({})`,` await device.snapshot.getSnapshot({ streamId: 'high' })`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.ptz.goToPreset({ presetId: 'home' })`,` await device.switch.setState({ on: true })`,` await device.brightness.setBrightness({ percentage: 60 })`,` await device.reboot.reboot({})`,``,`Subscribe to slice changes:`,` const off = device.state.battery.subscribe(s => console.log(s))`,` // off() to unsubscribe`,``,`Wait for a state condition:`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`Diagnostics:`,` info.name device name`,` info.addonId which addon owns it`,` info.online transport health`,` sm.dump(deviceId) full debug dump (binding + state + info)`];case`provider`:return[...t,`Pre-bound variables:`,` devices Devices belonging to this provider (raw IDevice[])`,` getIntegration() Integration metadata`,``,`For typed device access use the SystemMirror:`,` await getSystemMirror()`,` sm.getDevicesByAddon('this-addon-id')`];case`addon`:return[...t,`Pre-bound variables:`,` manifest { name, version, ... }`,` declaration addon declaration`,` source addon source location`,``,`Examples:`,` manifest.name`,` manifest.version`]}}function ar({scope:n,greeting:i,className:a}){let o=m(),[s,f]=c(()=>{let e=[];return i&&e.push({id:Q(),kind:`info`,text:i}),e.push({id:Q(),kind:`info`,text:`scope: ${tr(n)} — type help or context for available commands`}),e}),[p,h]=c(``),[g,_]=c([]),[v,y]=c(-1),b=t(null),x=t(null);d(()=>{let e=x.current;e&&(e.scrollTop=e.scrollHeight)},[s]);let S=e(()=>{b.current?.focus()},[]),C=l({mutationFn:e=>o.trpcClient.repl.execute.mutate({code:e,scope:n}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;f(e=>[...e,{id:Q(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);f(e=>[...e,{id:Q(),kind:`error`,text:t}])}});function w(e){let t=e.trim();if(t){if(t===`clear`){f([{id:Q(),kind:`info`,text:`scope: ${tr(n)}`}]),h(``);return}if(t===`help`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...nr(n).map(e=>({id:Q(),kind:`info`,text:e}))]),h(``);return}if(t===`context`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...ir(n).map(e=>({id:Q(),kind:`info`,text:e}))]),h(``);return}if(t===`examples`){f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`},...rr(n).map(e=>({id:Q(),kind:`info`,text:e}))]),h(``);return}_(e=>[...e,t]),y(-1),f(e=>[...e,{id:Q(),kind:`input`,text:`> ${t}`}]),h(``),C.mutate(t)}}function T(e){if(e.key===`Enter`){e.preventDefault(),w(p);return}if(e.key===`ArrowUp`){if(e.preventDefault(),g.length===0)return;let t=v===-1?g.length-1:Math.max(0,v-1);y(t),h(g[t]??``);return}if(e.key===`ArrowDown`){if(e.preventDefault(),v===-1)return;let t=v+1;t>=g.length?(y(-1),h(``)):(y(t),h(g[t]??``));return}e.ctrlKey&&e.key===`l`&&(e.preventDefault(),f([{id:Q(),kind:`info`,text:`scope: ${tr(n)}`}]))}let E={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return r(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${a??``}`,onClick:S,children:[r(`div`,{ref:x,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[s.map(e=>u(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${E[e.kind]}`,children:e.text},e.id)),C.isPending&&u(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),r(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[u(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),u(`input`,{ref:b,value:p,onChange:e=>h(e.target.value),onKeyDown:T,disabled:C.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function or({deviceId:e,intercomAvailable:t=!1}){let n=m(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=Qn(i?e:null),{streams:s,pipelineMetrics:c,createSession:l,sendAnswer:d,handleOffer:f,getIceServers:p,addIceCandidate:_,getIceCandidates:v,closeSession:y,getSessionState:x}=Ve(n.trpcClient,i?e:null),S=h(i?e:null,{width:dr}),C=$n(i&&t?e:null),w=C.state===`requesting-mic`||C.state===`starting`||C.state===`connecting`||C.state===`stopping`,T=C.isTalking||w,E=()=>{C.state===`idle`||C.state===`error`?C.start():C.state!==`stopping`&&C.stop()},D=g(),O=b(),k=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,A=D.length>0?u(o,{children:D.map(e=>u(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return u(Ie,{serverUrl:r,createSession:l,sendAnswer:d,handleOffer:f,getIceServers:p,addIceCandidate:_,getIceCandidates:v,closeSession:y,getSessionState:x,...O.request?{playbackUrl:O.request.url,playbackAuthToken:k,...O.request.label?{playbackLabel:O.request.label}:{},onExitPlayback:()=>O.clear()}:{},streams:s,pipelineMetrics:c,phase:a.phase,detections:a,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:S.src,...S.src?{posterUrl:S.src}:{},snapshotLoading:S.loading,onRefreshSnapshot:S.refresh,intercomAvailable:t,intercomShown:T,onIntercomToggle:E,extraOverlay:A,chromeless:!0,className:`h-full`})}function sr({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full`,children:u(ne,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function cr({deviceId:e}){if(!Number.isFinite(e))return r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
2
- `);return u(ar,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function lr({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(P,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function ur({deviceId:e}){return Number.isFinite(e)?u(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:u(O,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):r(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}var dr=960;function fr({deviceId:e}){let t=s(),n=Number.isFinite(e),{data:i}=j({deviceId:e},{enabled:n}),a=typeof i?.type==`string`?i.type:`camera`;je([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:o,isLoading:c,isError:l,error:d}=L({deviceId:e},{enabled:n}),{data:f}=W({deviceType:a},{enabled:!!a}),p=B({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(c)return u(`div`,{className:`p-4`,children:u(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(l)return r(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,d instanceof Error?d.message:String(d)]});let m=new Map,h={};for(let e of f??[])h[e.capName]=e.wrappers;for(let e of o?.entries??[])m.set(e.capName,{...e,wrappers:h[e.capName]??[]});for(let e of f??[])m.has(e.capName)||m.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let g=[...m.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(g.length===0)return r(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[u(yt,{className:`h-8 w-8 opacity-40`}),u(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),u(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let _=g.filter(e=>e.kind!==`unbound`).length;return r(`div`,{className:`flex flex-col gap-3 p-1`,children:[r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-foreground`,children:_}),` of `,g.length,` capabilit`,g.length===1?`y`:`ies`,` bound — rows marked `,u(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),u(Ee,{columns:[{key:`capability`,header:`Capability`,render:e=>u(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>u(pr,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>u(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||u(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?u(mr,{nodeId:e.providerNodeId}):u(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>u(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||u(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return u(hr,{wrappers:t.wrappers,activeWrapperId:n,disabled:p.isPending,onPick:r=>{let i=n===r;p.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:g,rowKey:e=>e.capName,minWidthPx:720})]})}function pr({kind:e}){return e===`native`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(Mt,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(St,{className:`h-3 w-3`}),`wrapped`]}):e===`linked`?r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-warning/30 text-warning bg-warning/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(un,{className:`h-3 w-3`}),`linked`]}):r(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[u(Tt,{className:`h-3 w-3`}),`unbound`]})}function mr({nodeId:e}){return u(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function hr({wrappers:e,activeWrapperId:t,disabled:n,onPick:i}){return e.length===0?u(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):u(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let a=e===t;return r(`button`,{disabled:n,onClick:()=>i(e),title:a?`Click to deactivate (revert to native)`:`Activate wrapper ${e}`,className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${a?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[u(a?$t:At,{className:`h-3 w-3`}),e]},e)})})}function gr({deviceId:e,activeSubTab:t,onSubTabChange:n}){return u(`div`,{className:`flex flex-col gap-3`,children:u(an,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}n();var _r=new Set([`package-detection`]);function vr(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function yr(e){return e?e.modelId!==void 0||e.settings!==void 0:!1}function br({deviceId:e,refreshToken:t}){let n=s(),l=m().trpcClient,[d,f]=c(null),[p,h]=c(null),[g,_]=c(null),v=ue({deviceId:e},{refetchOnMount:`always`}),y=le({deviceId:e},{refetchOnMount:`always`}),b=K(void 0,{refetchOnMount:`always`});je([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let x=Ye(void 0,{refetchOnMount:`always`}),C=i(()=>{let e=new Set;for(let t of x.data??[])t.isOnline&&e.add(t.id);return e},[x.data]),w=i(()=>(b.data??[]).filter(e=>C.has(e.nodeId)).map(e=>e.nodeId),[b.data,C]),T=w[0]??``,E=Me({nodeId:T},{enabled:T!==``,refetchOnMount:`always`}),D=a({enabled:w.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`device-step`,w.join(`,`),t],queryFn:async()=>{let e={};for(let t of w)try{e[t]=(await l.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:t})).devices}catch{e[t]=[]}return e}}),O=()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},k=Qe({onSuccess:O}),A=J({onSuccess:O}),ee=i(()=>E.data?$e(E.data):[],[E.data]),te=i(()=>{let e=b.data??[],t=C.size===0?[]:e.filter(e=>C.has(e.nodeId)),n=[];for(let e of t){let t=(D.data?.[e.nodeId]??[]).filter(e=>e.enabled&&e.available);if(t.length>=2)for(let r of t)n.push({agentNodeId:e.nodeId,engineLabel:r.format,deviceKey:r.key,deviceLabel:Ct(r).label});else n.push({agentNodeId:e.nodeId,engineLabel:t[0]?.format??`(engine unknown)`})}return n},[b.data,D.data,C]),j=(e,t)=>D.data?.[e]?.find(e=>e.key===t)??null,ne=e=>{if(e.deviceKey!==void 0)return e.deviceKey;let t=D.data?.[e.agentNodeId]??[],n=t.filter(e=>e.enabled&&e.available);return n.length>=1?n[0].key:t.find(e=>e.available)?.key??t[0]?.key??null},M=(e,t,n)=>y.data?.[e]?.[t]?.[n]??null,N=e=>{if(_r.has(e))return{kind:`zone-driven`};let t=vr(E.data??null,e)?.enabledByDefault??!0,n=v.data?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},P=(e,t)=>{let n=vr(E.data??null,e);if(n)return lt(n,t)},re=(e,t)=>{let n=N(e),r=n.kind===`gate`?n.effectiveOn:!1,i=vr(E.data??null,e),a=ne(t),o=a===null?null:j(t.agentNodeId,a);if(!G(i?.models??[],o?.format))return r?{kind:`skip`}:{kind:`na`};let s=a===null?null:M(t.agentNodeId,a,e),c=o?.steps?.[e];return{kind:`enabled`,modelId:(i?S({catalog:i,device:o,override:s?.modelId,base:c?.modelId}):void 0)??`Auto`,overridden:yr(s)}},F=d&&E.data?vr(E.data,d.addonId):null,I=d?j(d.agentNodeId,d.deviceKey):null,ie=I?.format??`coreml`,ae=d?yr(M(d.agentNodeId,d.deviceKey,d.addonId)):!1,L=d?P(d.addonId,I):void 0,R=i(()=>{if(!d||!I)return null;let e=I.steps?.[d.addonId];return{enabled:!0,...e?.modelId===void 0?{}:{modelId:e.modelId},settings:e?.settings??{}}},[d,I]),z=()=>{f(null),h(null)},B=(e,t)=>{let n=ne(t);n!==null&&(f({addonId:e,agentNodeId:t.agentNodeId,deviceKey:n}),h(M(t.agentNodeId,n,e)))},oe=(t,n)=>{A.mutate({deviceId:e,addonId:t,enabled:n})},se=()=>{d&&k.mutate({deviceId:e,agentNodeId:d.agentNodeId,deviceKey:d.deviceKey,addonId:d.addonId,patch:p},{onSuccess:z})},V=()=>{d&&k.mutate({deviceId:e,agentNodeId:d.agentNodeId,deviceKey:d.deviceKey,addonId:d.addonId,patch:null},{onSuccess:z})};if(b.isLoading||T!==``&&E.isLoading)return u(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(te.length===0)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`No online agents.`});if(!E.data)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let H=d!==null&&F!==null&&I!==null;return r(`div`,{className:`relative h-full w-full space-y-3`,children:[r(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-foreground`,children:`Gate`}),` (col 1) decides whether this camera runs a step — independent of nodes. Each`,` `,u(`span`,{className:`font-medium text-foreground`,children:`node column`}),` shows the model that node runs; click a cell to pin a per-camera model override for that accelerator. A gated-on step with no model on a device shows a clickable `,u(`span`,{className:`text-amber-500`,children:`⚠ skip`}),` `,`and won't run there.`]}),r(`div`,{className:`rounded-md border border-sky-500/25 bg-sky-500/[0.06] px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[u(`span`,{className:`font-medium text-sky-400`,children:`Placement is dynamic.`}),` When a node has multiple inference accelerators, each session is balanced across them per-session at dispatch time — these device columns show each accelerator's effective model (override ?? device default), not a fixed assignment.`]}),u(`div`,{className:H?`md:pr-[360px]`:``,children:ee.length>0?u(xe,{tree:ee,agents:te,gateFor:N,getCellState:re,onCellClick:B,selectedCell:d,onSetGate:oe,gateBusy:A.isPending,fallbackNodeId:g,onFallbackNodeChange:_}):u(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),u(we,{open:H,onClose:z,title:F?.name??``,subtitle:d&&I?`${d.agentNodeId} · ${Ct(I).label} · ${I.format}`:``,footer:r(o,{children:[u(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle disabled:opacity-50`,disabled:!ae||k.isPending,onClick:V,children:`Clear override`}),u(`div`,{className:`flex-1`}),u(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:z,children:`Cancel`}),u(`button`,{type:`button`,disabled:!d||!R||k.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:se,children:k.isPending?`Saving…`:`Save`})]}),children:F&&d&&R?u(ce,{mode:`device`,addon:F,agentDefault:R,agentNodeId:d.agentNodeId,currentPatch:p,engineFormat:ie,effectiveModelId:L,onChangePatch:h}):u(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}var xr=[{id:`object-detection`,label:`Object detection`,icon:`scan-search`},{id:`tracking`,label:`Tracking`,icon:`route`},{id:`motion`,label:`Motion`,icon:`activity`},{id:`stationary`,label:`Stationary`,icon:`square-parking`},{id:`zones`,label:`Zones`,icon:`shapes`},{id:`audio`,label:`Audio`,icon:`volume-2`},{id:`cluster`,label:`Cluster`,icon:`server`}],Sr={"pipeline-object-detection":`object-detection`,"detection-sensitivity":`object-detection`,"onboard-object-detection":`object-detection`,tracking:`tracking`,"tracking-core":`tracking`,"motion-tuning":`motion`,"stationary-objects":`stationary`,occupancy:`stationary`,zones:`zones`,"pipeline-audio":`audio`,"cluster-assignment":`cluster`,"orchestrator-live":`cluster`};function Cr(e){return Sr[e]??`object-detection`}n();var wr=`steps`,Tr=`settings`,Er=new Set([wr,Tr]);function Dr(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function Or({deviceId:t,activeSubTab:n,onSubTabChange:i}){return r(Ce,{value:n&&Er.has(n)?n:wr,onValueChange:e(e=>{i?.(e)},[i]),className:`flex flex-col`,children:[r(et,{className:`flex-shrink-0`,children:[u(Te,{value:wr,children:`Steps`}),u(Te,{value:Tr,children:`Settings`})]}),u(Re,{value:wr,children:u(br,{deviceId:t,refreshToken:0})}),u(Re,{value:Tr,children:u(an,{deviceId:t,sectionFilter:Dr,subTabGrouping:{groupOf:e=>Cr(e.id),tabs:xr}})})]})}function $({label:e,value:t}){return r(`div`,{className:`${v} flex items-start gap-2 sm:gap-3`,children:[u(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),u(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}n();function kr({deviceId:e,initialName:n}){let i=s(),[a,o]=c(!1),[l,f]=c(n),[p,m]=c(!1),h=t(null);d(()=>{a||f(n)},[n,a]),d(()=>{a&&h.current?.focus()},[a]);let g=pe({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),i.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),i.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),_=async()=>{let t=l.trim();if(t.length===0||t===n){o(!1),f(n);return}m(!0);try{await g.mutateAsync({deviceId:e,name:t}),o(!1)}catch{}finally{m(!1)}},v=()=>{f(n),o(!1)};return a?u($,{label:`Name`,value:r(`div`,{className:`flex items-center gap-1`,children:[u(`input`,{ref:h,type:`text`,value:l,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`?_():e.key===`Escape`&&v()},disabled:p,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),u(`button`,{type:`button`,onClick:()=>void _(),disabled:p,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:u($t,{className:`h-3 w-3`})}),u(`button`,{type:`button`,onClick:v,disabled:p,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:u(Jt,{className:`h-3 w-3`})})]})}):u($,{label:`Name`,value:r(`div`,{className:`flex items-center gap-2 group`,children:[u(`span`,{className:`truncate`,children:n}),u(`button`,{type:`button`,onClick:()=>o(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit name`,children:u(Dt,{className:`h-3.5 w-3.5`})})]})})}n();function Ar({deviceId:e,initialLocation:n}){let a=s(),[o,l]=c(!1),[f,p]=c(n??``),[m,h]=c(!1),g=t(null),{data:_}=ee(void 0,{enabled:o}),v=_??[];d(()=>{o||p(n??``)},[n,o]),d(()=>{o&&g.current?.focus()},[o]);let y=M({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),b=i(()=>{let e=f.trim().toLowerCase();return e.length===0?v:v.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[v,f]),x=f.trim().length>0&&!v.some(e=>e.toLowerCase()===f.trim().toLowerCase()),S=async t=>{let r=(t??f).trim(),i=r.length===0?null:r;if(i===(n??null)){l(!1);return}h(!0);try{await y.mutateAsync({deviceId:e,location:i}),l(!1)}catch{}finally{h(!1)}},C=()=>{p(n??``),l(!1)};return o?u($,{label:`Location`,value:r(`div`,{className:`relative`,children:[r(`div`,{className:`flex items-center gap-1`,children:[u(`input`,{ref:g,type:`text`,value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`?S():e.key===`Escape`&&C()},disabled:m,placeholder:`Room / area (or leave empty to clear)`,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),u(`button`,{type:`button`,onClick:()=>void S(),disabled:m,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:u($t,{className:`h-3 w-3`})}),u(`button`,{type:`button`,onClick:C,disabled:m,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:u(Jt,{className:`h-3 w-3`})})]}),(b.length>0||x)&&r(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:[b.map(e=>r(`button`,{type:`button`,onClick:()=>{p(e),S(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[u(Et,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),u(`span`,{className:`truncate`,children:e})]},e)),x&&r(`button`,{type:`button`,onClick:()=>void S(),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover border-t border-border`,children:[u(`span`,{className:`text-foreground-subtle`,children:`Create`}),r(`span`,{className:`font-medium truncate`,children:[`"`,f.trim(),`"`]})]})]})]})}):u($,{label:`Location`,value:r(`div`,{className:`flex items-center gap-2 group`,children:[n?u(`span`,{className:`truncate`,children:n}):u(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),u(`button`,{type:`button`,onClick:()=>l(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit location`,children:u(Dt,{className:`h-3.5 w-3.5`})})]})})}n();function jr({deviceId:e}){let t=s(),{data:n}=wt(e),{data:i}=xt(e),[a,l]=c(null),d=fe({onSuccess:()=>{l(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{l(`Could not change primary child: ${e.message}`)}});if(n==null||String(n.type??``)!==Y.Container)return null;let f=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(f.length<=1)return null;let p=se(f,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return r(o,{children:[u($,{label:`Primary child`,value:u(te,{childrenList:f,selectedId:p===null?f[0].id:p.id,onSetPrimary:t=>d.mutate({deviceId:e,primaryChildEntityId:t}),disabled:d.isPending})}),a!==null&&u(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:a})]})}n();var Mr=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function Nr(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function Pr(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function Fr(){let e=Ue(),t=Ze(),{data:n}=j({deviceId:e??0},{enabled:e!==null}),{data:i}=L({deviceId:e??0},{enabled:e!==null}),a=n??t??null,[o,s]=c(`identity`);if(e===null||!a)return null;let l=String(a.stableId??``),d=String(a.name??``),f=String(a.type??``),p=String(a.addonId??``),m=a.features??[],h=new Set([`device-status`,`feature-probe`,`device-ops`]),g=(i?.entries??[]).filter(e=>e.kind===`native`&&!h.has(e.capName)).map(e=>e.capName),_=m.length>0?m:g,v=a.location??null,y=a.metadata??null,b=y!==null&&Object.keys(y).length>0;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[u(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),b&&r(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[u(Ir,{active:o===`identity`,onClick:()=>s(`identity`),label:`Identity`}),u(Ir,{active:o===`hardware`,onClick:()=>s(`hardware`),label:`Hardware`})]})]}),(!b||o===`identity`)&&r(`div`,{className:`divide-y divide-border`,children:[u($,{label:`ID`,value:r(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,r(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,l,`)`]})]})}),u(kr,{deviceId:e,initialName:d}),u(Ar,{deviceId:e,initialLocation:v}),u(jr,{deviceId:e}),u($,{label:`Type`,value:f}),u($,{label:`Provider`,value:u(bt,{type:p,size:`sm`,showLabel:!0})}),u($,{label:`Capabilities`,value:_.length>0?u(gt,{capabilities:_,showLabels:!0}):u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),b&&o===`hardware`&&u(Lr,{metadata:y})]})}function Ir({active:e,onClick:t,label:n}){return u(`button`,{type:`button`,onClick:t,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${e?`bg-surface text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`}`,children:n})}function Lr({metadata:e}){let t=Mr.filter(t=>t in e),n=Object.keys(e).filter(e=>!Mr.includes(e)).toSorted(),i=[...t,...n];return r(`div`,{children:[u(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border bg-surface-subtle/40`,children:`Auto-populated by the driver on every connect. Read-only.`}),u(`div`,{className:`divide-y divide-border`,children:i.map(t=>u($,{label:Nr(t),value:u(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:Pr(e[t])})},t))})]})}var Rr=`Notifications`,zr=`This camera never notifies — no rule, no target, no alarm. Existing events, tracks and recordings are unaffected.`;function Br(e){let{mutedDeviceIds:t,deviceId:n}=e,r=t===null?null:!t.includes(n),i=e.pendingOn??null;return{label:Rr,on:r===null?null:i??r,available:r!==null,costWhenOff:zr}}function Vr(e,t){return!e.available||e.on===null?null:{deviceId:t,muted:e.on}}n();function Hr(e){if(typeof e!=`object`||!e)return null;let t={...e}.mutedDeviceIds;return Array.isArray(t)?t.filter(e=>typeof e==`number`):null}function Ur({deviceId:t}){let n=s(),i=Number.isFinite(t),[a,o]=c(null),[l,d]=c(null),f=Br({mutedDeviceIds:Hr(ve({},{enabled:i}).data),deviceId:t,pendingOn:l}),p=He({onError:e=>{console.error(`[DeviceNotificationMute] mute write failed — reverting`,{tags:{deviceId:t},meta:{error:e instanceof Error?e.message:String(e)}}),d(null),o(e instanceof Error?e.message:String(e)),n.invalidateQueries({queryKey:[[`notificationRules`,`listDeviceMutes`]]})},onSuccess:()=>{o(null),d(null),n.invalidateQueries({queryKey:[[`notificationRules`]]})}}),m=e(()=>{let e=Vr(f,t);e!==null&&(d(!e.muted),p.mutate(e))},[t,p,f]),h=f.on===null,g=f.on===!1,_=g?_t:vt;return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`border-b border-border px-4 py-2 flex items-center justify-between gap-2`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Notifications`}),g&&u(`span`,{className:`rounded bg-warning/20 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-warning`,children:`muted`})]}),r(`div`,{className:`px-4 py-3 flex items-start gap-3`,children:[r(`button`,{type:`button`,role:`switch`,"aria-label":f.label,"aria-checked":f.on===!0,disabled:!f.available||p.isPending,onClick:m,title:h?`Notification mute — state unknown; the notification centre did not answer.`:g?`Muted. ${f.costWhenOff}`:`Notifying. Muting it: ${f.costWhenOff}`,className:`inline-flex items-center gap-1.5 rounded-lg border px-2 py-1.5 text-[11px] font-medium transition-colors disabled:cursor-not-allowed ${a===null?h?`border-dashed border-border text-foreground-subtle/50`:g?`border-warning/40 text-warning hover:bg-warning/10`:`border-success/30 text-success hover:bg-success/10`:`border-danger/50 text-danger bg-danger/5`}`,children:[u(_,{className:`h-3.5 w-3.5`}),u(`span`,{children:h?`Unknown`:g?`Muted`:`Notifying`})]}),u(`p`,{className:`flex-1 text-[11px] leading-relaxed text-foreground-subtle`,children:a===null?h?`The notification centre did not answer, so this device’s mute state is unknown.`:f.costWhenOff:`Write failed: ${a}`})]})]})}n();function Wr({deviceId:e}){let[t,n]=c(null),i=it({onSuccess:e=>{n(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>n(`Re-sync failed: ${e.message}`)});return r(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[r(`div`,{className:`flex items-center justify-between gap-3`,children:[r(`div`,{children:[u(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),u(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),r(`button`,{type:`button`,disabled:i.isPending,onClick:()=>{n(null),i.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[u(kt,{className:`h-3 w-3 ${i.isPending?`animate-spin`:``}`}),i.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&u(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}n();var Gr={icon:``,label:``,unit:``,precision:``,hidden:!1};function Kr(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function qr(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function Jr(e){let t=e.precision.trim()===``?void 0:Number.parseInt(e.precision,10),n={...e.icon===``?{}:{icon:e.icon},...e.label.trim()===``?{}:{label:e.label.trim()},...e.unit===``?{}:{unit:e.unit},...t!==void 0&&Number.isFinite(t)?{precision:t}:{},...e.hidden?{hidden:!0}:{}};return Object.keys(n).length===0?null:n}function Yr({deviceId:e}){let t=m(),n=s(),{data:a}=j({deviceId:e},{enabled:e>0}),o=typeof a?.role==`string`?a.role:null,l=o===null?void 0:de[o],d=l?.kind===`numeric`,f=Je(t.trpcClient,e,o??``),p=l?.kind===`numeric`?l.canonicalUnit:void 0,h=qr(f)??p,g=h===void 0?void 0:ht(h),_=i(()=>g===void 0?[]:pt(g),[g]),[v,y]=c(null),b=v??Kr(a?.display),x=qe({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:S}=ct({},{staleTime:6e4}),C=me({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(a===void 0||o===null)return null;let w=e=>{y({...b,...e})},T=()=>{x.mutate({deviceId:e,display:Jr(b)})},E=()=>{y(Gr),x.mutate({deviceId:e,display:null})},D=()=>{let e={...b.icon===``?{}:{icon:b.icon},...b.unit===``?{}:{unit:b.unit},...b.precision.trim()!==``&&Number.isFinite(Number.parseInt(b.precision,10))?{precision:Number.parseInt(b.precision,10)}:{}},t={...S?.defaults,[o]:e};C.mutate({defaults:t})},O=z(o).label,k=Object.keys(ie);return r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[u(`div`,{className:`border-b border-border px-4 py-2`,children:u(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Display`})}),r(`div`,{className:`p-4 space-y-3`,children:[r(`label`,{className:`block`,children:[u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Icon`}),r(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:b.icon,onChange:e=>w({icon:e.target.value}),children:[r(`option`,{value:``,children:[`Default (`,O,`)`]}),k.map(e=>u(`option`,{value:e,children:e},e))]})]}),r(`label`,{className:`block`,children:[u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Label`}),u(`input`,{type:`text`,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:O,value:b.label,onChange:e=>w({label:e.target.value})})]}),d&&r(`div`,{className:`grid grid-cols-2 gap-3`,children:[r(`label`,{className:`block`,children:[u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Unit`}),r(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:b.unit,onChange:e=>w({unit:e.target.value}),disabled:_.length===0,children:[r(`option`,{value:``,children:[`Source`,h?` (${h})`:``]}),_.map(e=>u(`option`,{value:e,children:e},e))]})]}),r(`label`,{className:`block`,children:[u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Precision`}),u(`input`,{type:`number`,min:0,max:10,step:1,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:`inherit`,value:b.precision,onChange:e=>w({precision:e.target.value})})]})]}),r(`label`,{className:`flex items-center gap-2`,children:[u(`input`,{type:`checkbox`,checked:b.hidden,onChange:e=>w({hidden:e.target.checked})}),u(`span`,{className:`text-sm text-foreground`,children:`Hide from device lists`})]}),r(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[u(`button`,{type:`button`,className:`rounded bg-primary px-3 py-1 text-sm font-medium text-primary-foreground disabled:opacity-50`,onClick:T,disabled:x.isPending,children:`Save`}),u(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:E,disabled:x.isPending,children:`Reset`}),r(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:D,disabled:C.isPending,title:`Apply this unit / precision / icon as the default for every ${O} sensor`,children:[`Set as default for all `,O,` sensors`]})]})]})]})}function Xr(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function Zr({device:e}){let t=It(),n=typeof e.id==`number`?e.id:null,i=String(e.type??``),a=i===Y.Camera,o=i===Y.Hub,s=typeof e.role==`string`&&e.role.length>0,c=e.features??[],l=c.includes(mt.Resyncable),{data:d}=q({deviceId:n??0},{enabled:n!==null&&a,refetchInterval:5e3}),f=d?.streams??{},p=Object.entries(f),m=c.includes(mt.DoorbellButton),h=_e(m?{deviceId:n??void 0,historyLimit:10}:void 0),g=h.latest?Date.now()-h.latest.timestamp<3e4:!1;return r(`div`,{className:`space-y-5`,children:[o&&n!==null&&u(at,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),l&&n!==null&&u(Wr,{deviceId:n}),n!==null&&u(Ur,{deviceId:n}),a&&n!==null&&u(N,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),m&&u(tt,{history:h.history,latestIsFresh:g}),a&&n!==null&&u(N,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),a&&p.length>0&&r(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[u(`div`,{className:`border-b border-border px-4 py-2`,children:u(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),u(`div`,{className:`divide-y divide-border`,children:p.map(([e,t])=>r(`div`,{className:`px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 mb-2`,children:[u(Nt,{className:`h-3 w-3 text-foreground-subtle`}),u(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),r(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[u(Qr,{label:`Nominal`,value:Xr(t.nominalBitrateKbps??0)}),u(Qr,{label:`Observed`,value:Xr(t.observedBitrateKbps??0)}),u(Qr,{label:`Peak`,value:Xr(t.peakBitrateKbps??0)}),u(Qr,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),u(Fr,{}),s&&n!==null&&u(Yr,{deviceId:n})]})}function Qr({label:e,value:t,warning:n}){return r(`div`,{children:[u(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),u(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}n();var $r=[{id:`overview`,label:`Overview`,cameraOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1},{id:`detection-pipeline`,label:`Detection pipeline`,cameraOnly:!0},{id:`bindings`,label:`Bindings`,cameraOnly:!0}];function ei(e){let t=e===Y.Camera;return $r.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var ti=[{id:`logs`,icon:Yt,label:`Logs`},{id:`repl`,icon:Gt,label:`REPL`},{id:`events`,icon:zt,label:`Events`},{id:`state`,icon:Lt,label:`State`}];function ni(){let n=Ht(),a=Number(n.deviceId),l=Number.isFinite(a),d=It(),f=s(),h=Le(),g=m(),[v,y]=Vt(),b=v.get(`tab`)??`overview`,x=v.get(`sub`),[S,C]=c(`logs`),T=`device-detail.left-col-width-px`,[E,D]=c(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(T),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),O=t(E);O.current=E;function A(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??E??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{D(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=O.current;if(e!==null)try{window.localStorage.setItem(T,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:ee,isLoading:te,isError:ne}=j({deviceId:a},{enabled:l,refetchInterval:5e3,retry:1}),{data:M}=I({deviceId:a},{enabled:l}),N=i(()=>{let e=M?.settings?.sections??[],t=M?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(tn)&&r.add(nn),[...r].map(e=>e===`export`?{id:e,label:rn,isAddonContrib:!0}:{id:e,label:dt[e]?.label??e,isAddonContrib:!0})},[M]),P=ee,F=String(P?.name??n.deviceId??`Device`),ie=P?.online===!0,L=ie?`online`:`offline`,R=String(P?.addonId??`rtsp`),z=P?.features??[],B=P?.type,ce=B===Y.Camera,{data:V}=xt(l?a:0),H=B===Y.Container,le=i(()=>(V??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[V]),U=i(()=>H?se(le,typeof P?.linkDeviceId==`number`?P.linkDeviceId:null,typeof P?.primaryChildEntityId==`string`?P.primaryChildEntityId:null)?.id??null:null,[H,le,P?.linkDeviceId,P?.primaryChildEntityId]),{data:ue}=I({deviceId:U??0},{enabled:U!==null}),W=i(()=>{if(U===null)return[];let e=ue?.settings?.sections??[],t=ue?.live?.sections??[],n=new Set;for(let r of[...e,...t])r.location===`top-tab`&&r.tab&&n.add(r.tab);return[...n].map(e=>({id:e,label:dt[e]?.label??e,isAddonContrib:!0,childDeviceId:U}))},[U,ue]),G=typeof P?.parentDeviceId==`number`?P.parentDeviceId:null,{data:de}=j({deviceId:G??0},{enabled:G!==null}),K=ke(),q=P?.disabled!==!0,fe=i(()=>{let e=new Set,t=[];for(let n of[...ei(B),...N,...W])e.has(n.id)||(e.add(n.id),t.push(n));return t},[B,N,W]),pe=i(()=>fe.some(e=>e.id===b)?b:`overview`,[fe,b]),me=e(e=>{y(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[y]),_e=e(e=>{y(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[y]),ve=(V??[]).length>0,xe=i(()=>ti.filter(({featureGate:e})=>!e||z.includes(e)),[z]),{data:J}=nt({addonId:R},{enabled:!!R&&R!==`rtsp`}),Ce=k({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]}),d(J?.id?`/integrations/${J.id}`:`/integrations`)}}),we=ae({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Te=w({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ee=Fe(),De=Ne({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Oe=z.includes(mt.Rebootable),Ae=z.includes(mt.BatteryOperated),je=Pe(g.trpcClient,Ae&&l?a:null),[Me,Ie]=c(!1),Re=p(g.trpcClient,l?a:null),Be=async()=>{if(!(Me||!Re)){Ie(!0);try{await Re.snapshot?.invalidateCache({});let e=await Re.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=F.replace(/[^a-zA-Z0-9_.-]+/g,`_`),i=new Date().toISOString().replace(/[:.]/g,`-`),a=document.createElement(`a`);a.href=t,a.download=`${r}-${i}.${n}`,document.body.appendChild(a),a.click(),document.body.removeChild(a)}finally{Ie(!1)}}},Ve=we.isPending||Te.isPending,{data:He}=re({deviceId:a},{enabled:l,refetchInterval:1e4}),Ue=He?.agentNodeId??null,Ge=typeof Ue==`string`&&Ue.length>0&&!Ue.startsWith(`addon:`)?Ue:void 0,{data:qe}=ze({deviceId:a,...Ge?{nodeId:Ge}:{}},{enabled:l,refetchInterval:3e3,retry:!1}),{data:Je}=Ke({deviceId:a},{enabled:l,refetchInterval:3e3,retry:!1}),Ye=Je?.level?.dbfs??null;function Xe(){if(!l)return null;switch(pe){case`overview`:return u(Zr,{device:P??{}});case`config`:return u(gr,{deviceId:a,activeSubTab:x,onSubTabChange:_e});case`detection-pipeline`:return u(Or,{deviceId:a,activeSubTab:x,onSubTabChange:_e});case`bindings`:return u(fr,{deviceId:a});default:{let e=pe,t=N.some(t=>t.id===e),n=W.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??a;if(e===`export`)return u(an,{deviceId:a,sectionFilter:tn,activeSubTab:x,onSubTabChange:_e});let i=u(an,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:x,onSubTabChange:_e});return n!==void 0&&r!==a?u(ye,{deviceId:r,children:i}):i}}}return l?te?r(`div`,{className:`flex flex-col h-full`,children:[r(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[u(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),u(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),u(`div`,{className:`flex-1 p-6`,children:u(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):ne||!ee?r(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[u(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),r(`p`,{className:`text-xs`,children:[`No device with ID`,` `,r(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,a]})]}),u(`button`,{onClick:()=>d(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]}):r(`div`,{className:`absolute inset-0 flex flex-col overflow-hidden`,children:[r(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[u(`div`,{className:`mb-2`,children:u(be,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},{label:J?.name??R,onClick:()=>J?.id&&d(`/integrations/${J.id}`)},{label:F}]})}),r(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[u(bt,{type:R,size:`lg`}),r(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:F}),u(en,{status:L}),Ae&&u(We,{status:je,variant:`full`})]}),G!==null&&de&&r(`button`,{type:`button`,onClick:()=>d(`/devices/${G}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${de.name}`,children:[u(`span`,{children:`↑`}),u(`span`,{className:`truncate`,children:String(de.name??`Device #${G}`)})]}),u(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:z.length>0&&u(gt,{capabilities:z})})]}),qe&&u(`div`,{className:`hidden lg:flex`,children:u(ri,{metrics:qe,dbfs:Ye})}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[r(`button`,{onClick:async()=>{q?await h({title:`Disable "${F}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Te.mutate({deviceId:a}):we.mutate({deviceId:a})},disabled:Ve,title:q?`Disable device`:`Enable device`,className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border transition-colors disabled:opacity-50 ${q?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[u(Ot,{className:`h-3.5 w-3.5`}),u(`span`,{className:`hidden sm:inline`,children:Ve?`Updating…`:q?`Enabled`:`Disabled`})]}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),ce&&r(o,{children:[u(Tn,{deviceId:a}),u(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`})]}),u(ge,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:Bt,disabled:Me,onClick:()=>{Be()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:jt,hidden:!Oe,disabled:Ee.isPending,danger:!0,onClick:async()=>{await h({title:`Reboot "${F}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Ee.mutate({deviceId:a})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${J?.name??R}.`,icon:kt,disabled:De.isPending,danger:!0,onClick:async()=>{await h({title:`Restart "${J?.name??R}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${F}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&De.mutate({addonId:R})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:Xt,separatorBefore:!0,disabled:Ce.isPending,danger:!0,onClick:async()=>{await h({title:`Delete "${F}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Ce.mutate({deviceId:a})}}]})]})]})]}),u(ye,{deviceId:a,device:P??void 0,children:u(oe,{children:u(he,{children:u(_,{children:u(Se,{children:r(`main`,{className:K?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[r(`div`,{className:K?`flex flex-col bg-surface`:`${E===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!K&&E!==null?{width:`${String(E)}px`}:void 0,children:[u(`div`,{className:ce?`flex-shrink-0 border-b border-border-subtle bg-black`:K?`flex-shrink-0 border-b border-border-subtle bg-surface`:`max-h-[55%] shrink-0 overflow-y-auto border-b border-border-subtle bg-surface`,children:ce?u(or,{deviceId:a,intercomAvailable:z.includes(mt.TwoWayAudio)}):u(Zn,{deviceId:a,deviceName:F,deviceType:B??`unknown`,provider:R,isOnline:ie,features:z})}),r(`div`,{className:K?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[u(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:u(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:xe.map(({id:e,label:t,icon:n})=>r(`button`,{onClick:()=>C(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${S===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[u(n,{className:`h-3 w-3`}),t]},e))})}),r(`div`,{className:K?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[S===`logs`&&u(sr,{deviceId:a,containerDeviceId:B===`container`?a:void 0}),S===`repl`&&u(cr,{deviceId:a}),S===`events`&&u(lr,{deviceId:a}),S===`state`&&u(ur,{deviceId:a})]})]})]}),!K&&u(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:A,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:u(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),r(`div`,{className:K?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[u(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:u(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:fe.map(e=>{let t=pe===e.id;return r(`button`,{onClick:()=>me(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&u(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),r(`div`,{className:K?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[pe===`overview`&&ve&&u(On,{parentDeviceId:a}),Xe()]})]})]})})})})})})]}):r(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[u(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),r(`p`,{className:`text-xs`,children:[`The URL segment`,` `,u(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:n.deviceId}),` `,`is not a number.`]}),u(`button`,{onClick:()=>d(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]})}function ri({metrics:e,dbfs:t}){let n=y(e.phase??`idle`);return r(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[r(`div`,{className:`flex items-center gap-1.5`,children:[u(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),u(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),u(`div`,{className:`h-3 w-px bg-border`}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[u(Ft,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),u(`span`,{children:`fps`})]}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[u(Rt,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),u(`span`,{children:`ms`})]}),r(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[u(fn,{className:`h-3 w-3`}),u(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),u(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&r(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{ni as DeviceDetailPage};
@@ -1 +0,0 @@
1
- import{Q as e,S as t,W as n,a as r,b as i,o as a,q as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as c}from"./player-overlays-DN_06_1T.js";import{As as l,Br as u,Cs as d,Dn as f,Ds as p,En as m,Es as h,Lt as g,Ms as _,Ns as v,Os as y,Ps as b,S as x,Ss as S,Ts as C,bs as w,et as T,f as E,js as D,ks as ee,ln as O,p as k,ws as A,x as j,xs as te}from"./src-Dw_YuA21.js";import{c as M,d as N,l as P,u as F}from"./src-5IxHiQXr.js";import{t as I}from"./circle-check-big-B7_QKFSQ.js";import{t as ne}from"./copy-DS7H6-em.js";import{t as re}from"./key-round-DO25vFwm.js";import{t as ie}from"./pencil-C9e8FY_K.js";import{t as ae}from"./plus-5BBPoTgM.js";import{C as L,E as R,I as oe,K as z,R as se,f as B,i as V,k as ce,r as H,s as U,u as W,w as G,z as le}from"./index-B1t00qUp.js";import{t as K}from"./AdminPage-CCD07UMs.js";import{t as ue}from"./AdminTabs-DS0Srvsl.js";import{t as de}from"./AddonCollectionPage-DgxQiC5R.js";import{t as fe}from"./addon-display-names-DvSEQty-.js";var pe=z(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),me=z(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),he=z(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),ge=z(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),_e=z(`shield-alert`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]),ve=z(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);e();function ye({userId:e,username:n,onClose:r}){let o=a(),c=O(),l=A({userId:e}),u=l.data,f=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),p=d({onSuccess:()=>{f(),r()}}),m=l.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[t(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[t(`div`,{className:`flex items-center gap-2`,children:[s(W,{className:`h-4 w-4 text-primary`}),t(`div`,{children:[s(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),t(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,s(`span`,{className:`font-mono`,children:n})]})]})]}),s(`button`,{onClick:r,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:s(V,{className:`h-4 w-4`})})]}),t(`div`,{className:`p-4 space-y-4`,children:[m===`loading`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(L,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),m===`not_enrolled`&&t(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[s(G,{className:`h-4 w-4 mt-0.5 shrink-0`}),t(`div`,{children:[s(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),s(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),m===`enrolled`&&u&&t(i,{children:[t(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[s(I,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),t(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[s(`div`,{className:`font-medium`,children:`2FA is active`}),t(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,u.confirmedAt?new Date(u.confirmedAt).toLocaleString():`—`]})]})]}),s(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),t(`div`,{className:`flex justify-end gap-2`,children:[s(g,{onClick:r,variant:`secondary`,children:`Close`}),t(`button`,{onClick:async()=>{await c({title:`Remove 2FA`,message:`Remove two-factor authentication for "${n}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&p.mutate({userId:e})},disabled:p.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[p.isPending?s(L,{className:`h-3 w-3 animate-spin`}):s(V,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function q({icon:e,label:n,count:r,all:i,total:a}){return t(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[s(e,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(`span`,{className:`min-w-0 flex-1 text-foreground-subtle`,children:n}),s(`span`,{className:r===0?`text-foreground-subtle`:`font-medium text-foreground`,children:r===0?`none`:i?`all ${a}`:`${r} of ${a}`})]})}function be({scopes:e,isAdmin:n,invalidReason:a}){let o=c(),l=r({queryKey:[`auth`,`previewScope`,e,n],enabled:a===null,queryFn:()=>o.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:n})}),{data:d}=u({}),f=d?.length??0;if(a!==null)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:t(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,children:[s(_e,{className:`h-3 w-3 shrink-0`}),a]})});if(l.isLoading)return t(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface p-3 text-[11px] text-foreground-subtle`,children:[s(L,{className:`h-3 w-3 animate-spin`}),`Resolving…`]});if(l.isError||!l.data)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:s(`p`,{className:`text-[11px] text-danger`,children:`Could not resolve this grant set. Saving is still allowed — the server enforces the same rules either way.`})});let p=l.data;return s(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:p.isAdmin?t(`p`,{className:`text-[11px] text-foreground`,children:[s(`span`,{className:`font-medium`,children:`Administrator`}),` — unrestricted. Grants are ignored for an admin.`]}):t(i,{children:[s(q,{icon:ce,label:`Devices they can see`,count:p.device.view.deviceCount,all:p.device.view.all,total:f}),s(q,{icon:ie,label:`Devices they can operate`,count:p.device.create.deviceCount,all:p.device.create.all,total:f}),s(q,{icon:U,label:`Devices they can delete`,count:p.device.delete.deviceCount,all:p.device.delete.all,total:f}),t(`div`,{className:`border-t border-border pt-2 text-[10px] text-foreground-subtle`,children:[`System access: `,p.system.length===0?`none`:p.system.join(`, `),p.capabilities.length>0&&t(i,{children:[` · Extra capabilities: `,p.capabilities.map(e=>e.name).join(`, `)]}),p.addons.length>0&&t(i,{children:[` · Addons: `,p.addons.map(e=>e.name).join(`, `)]})]}),p.device.view.deviceCount===0&&s(`p`,{className:`text-[10px] text-warning`,children:`This user will not be able to see any device.`})]})})}function xe(e){let t=F(e);return t===null?{mode:e.length===0?`role`:`advanced`,roleId:null,selector:{kind:`all`},includeLinked:!0,advancedScopes:e}:{mode:`role`,roleId:t.roleId,selector:t.selector,includeLinked:t.includeLinked,advancedScopes:e}}function Se(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:P({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function Ce({user:e,onClose:r,onSubmit:a,submitting:c,callerScopes:l}){let u=n(()=>xe(e.scopes??[]),[e.scopes]),[d,f]=o(u),[p,m]=o(u.mode===`advanced`),h=n(()=>Se(d),[d]),g=!e.isAdmin&&d.mode===`role`&&d.roleId===null,_=n(()=>e.isAdmin?null:d.mode===`role`&&d.roleId===null?`Pick what this user can do to see the result.`:k(h),[e.isAdmin,d.mode,d.roleId,h]),v=e=>f({...d,...e});return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 pt-[calc(1rem+env(safe-area-inset-top))] pb-[calc(1rem+env(safe-area-inset-bottom))]`,children:t(`div`,{className:`flex max-h-full w-full max-w-2xl flex-col rounded-lg border border-border bg-surface shadow-xl`,children:[t(`div`,{className:`flex shrink-0 items-start justify-between border-b border-border px-4 py-3`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Access — `,e.username]}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`This user is an administrator — they can do everything, and the settings below are ignored.`:`Choose what they can do, then which devices it applies to.`})]}),s(`button`,{onClick:r,className:`shrink-0 text-foreground-subtle hover:text-foreground`,title:`Close`,children:s(V,{className:`h-4 w-4`})})]}),t(`div`,{className:`min-h-0 flex-1 space-y-4 overflow-y-auto px-4 py-4`,children:[g&&t(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[s(_e,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),t(`p`,{className:`text-[11px] text-foreground`,children:[s(`span`,{className:`font-medium`,children:`No access.`}),` `,t(`span`,{className:`text-foreground-subtle`,children:[e.username,` cannot see or do anything yet. Configure it below.`]})]})]}),t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`1 · What can they do`}),s(`div`,{className:`space-y-1.5`,children:M.map(e=>{let n=d.mode===`role`&&d.roleId===e.id;return t(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-lg border p-2.5 transition-colors ${n?`border-primary bg-primary/5`:`border-border hover:bg-foreground-subtle/5`}`,children:[s(`input`,{type:`radio`,name:`access-role`,checked:n,onChange:()=>v({mode:`role`,roleId:e.id}),className:`mt-0.5 border-border focus:ring-primary`}),t(`span`,{className:`min-w-0`,children:[s(`span`,{className:`block text-[12px] font-medium text-foreground`,children:e.label}),s(`span`,{className:`mt-0.5 block text-[10px] text-foreground-subtle`,children:e.description})]})]},e.id)})}),t(`button`,{type:`button`,onClick:()=>{if(!p){f({...d,mode:`advanced`,advancedScopes:h}),m(!0);return}m(!1),f(xe(d.advancedScopes))},className:`inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] text-foreground-subtle transition-colors hover:bg-foreground-subtle/10 hover:text-foreground`,children:[s(p?se:oe,{className:`h-3 w-3`}),`Advanced — edit raw grants`]}),p&&t(`div`,{className:`rounded-lg border border-border p-2`,children:[s(`p`,{className:`mb-2 text-[10px] text-foreground-subtle`,children:`One row per grant. Anything expressible here overrides the three roles above; close this section to go back to them.`}),s(E,{value:d.advancedScopes,onChange:e=>v({mode:`advanced`,advancedScopes:e}),clampToParent:l,emptyHint:t(i,{children:[`No grants.`,` `,s(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until one is added.`]})})]})]}),d.mode===`role`&&t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`2 · On which devices`}),s(j,{value:d.selector,onChange:e=>v({selector:e}),includeLinked:d.includeLinked,onIncludeLinkedChange:e=>v({includeLinked:e}),clampToDeviceIds:null})]}),t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:d.mode===`role`?`3 · Result`:`2 · Result`}),s(be,{scopes:h,isAdmin:e.isAdmin,invalidReason:_})]})]}),t(`div`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[s(`button`,{onClick:r,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>a([...h]),disabled:c||_!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:c?s(L,{className:`h-3 w-3 animate-spin`}):`Save access`})]})]})})}e();function we(){let e=a(),{user:n}=H(),[r,i]=o(!1),[c,l]=o(``),[u,d]=o(``),[f,p]=o(!1),[m,h]=o(null),{data:g,isLoading:_,isError:x}=y(),C=O(),w=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),E=te({onSuccess:()=>{w(),i(!1),l(``),d(``),p(!1),h(null)},onError:e=>{h(e instanceof Error?e.message:`Failed to create user`)}}),D=S({onSuccess:w}),k=b({onSuccess:w}),A=ee({onSuccess:w}),j=v({onSuccess:()=>{w(),N(null)}}),[M,N]=o(null),[P,F]=o(null),I=g??[];async function ne(e){await C({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&D.mutate({id:e.id})}async function re(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}await C({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&A.mutate({id:e.id,newPassword:t})}}function ie(e,t){t!==e.isAdmin&&k.mutate({id:e.id,isAdmin:t})}function R(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return t(K,{children:[s(`div`,{className:`flex items-center justify-end`,children:t(`button`,{onClick:()=>i(!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 shadow-sm hover:bg-primary/90`,children:[s(ae,{className:`h-3.5 w-3.5`}),`Create User`]})}),r&&t(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:[s(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),s(`button`,{onClick:()=>i(!1),className:`text-foreground-subtle hover:text-foreground`,children:s(V,{className:`h-4 w-4`})})]}),t(`div`,{className:`grid grid-cols-3 gap-3`,children:[t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),s(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`john`,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`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),s(`input`,{type:`password`,value:u,onChange:e=>d(e.target.value),placeholder:`••••••••`,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`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),t(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:f,onChange:e=>p(e.target.checked),className:`rounded border-border focus:ring-primary`}),s(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),m&&s(`p`,{className:`text-[10px] text-danger`,children:m}),t(`div`,{className:`flex justify-end gap-2`,children:[s(`button`,{onClick:()=>i(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>E.mutate({username:c,password:u,isAdmin:f}),disabled:E.isPending||!c||!u,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:E.isPending?`Creating...`:`Create`})]})]}),_&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),x&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!_&&!x&&I.length===0&&s(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>D.isPending&&D.variables?.id===e.id||k.isPending&&k.variables?.id===e.id||A.isPending&&A.variables?.id===e.id;return s(T,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:n=>t(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:n.isAdmin,onChange:e=>ie(n,e.target.checked),disabled:e(n),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),s(`span`,{className:n.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:n.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Access`,render:e=>e.isAdmin?s(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`everything (admin)`}):t(`button`,{onClick:()=>N(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] hover:bg-foreground-subtle/10`,title:`Configure access`,children:[s(B,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(Te,{scopes:e.scopes??[]})]})},{key:`createdAt`,header:`Created`,render:e=>s(`span`,{className:`text-foreground-subtle`,children:R(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:r=>{let i=e(r);return t(`div`,{className:`flex items-center justify-end gap-1`,children:[r.id!==n?.id&&r.totpEnabled&&t(`button`,{onClick:()=>F(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[s(W,{className:`h-3 w-3`}),`Remove 2FA`]}),t(`button`,{onClick:()=>re(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[s(he,{className:`h-3 w-3`}),`Reset password`]}),t(`button`,{onClick:()=>ne(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[i?s(L,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:I,rowKey:e=>e.id,minWidthPx:560})})(),P&&s(ye,{userId:P.id,username:P.username,onClose:()=>F(null)}),M&&s(Ee,{user:M,onClose:()=>N(null),onSubmit:e=>j.mutate({userId:M.id,scopes:e}),submitting:j.isPending})]})}function Te({scopes:e}){if(e.length===0)return s(`span`,{className:`font-medium text-warning`,children:`No access`});let n=F(e);return n===null?t(`span`,{className:`text-foreground-subtle`,children:[`Custom · `,e.length,` grant`,e.length===1?``:`s`]}):t(`span`,{className:`text-foreground-subtle`,children:[s(`span`,{className:`font-medium text-foreground`,children:N(n.roleId).label}),` ·`,` `,x(n.selector)]})}function Ee(e){let{user:t}=H(),n=t?.isAdmin===!0;return s(Ce,{...e,callerScopes:n?null:t?.scopes??[]})}e();var De=`bg-primary/10 text-primary`,Oe=`bg-foreground-subtle/10 text-foreground-subtle`;function J(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function ke(e){return e?e===`*`?`*`:e.join(`, `):``}function Ae(){let e=a(),r=O(),{data:i,isLoading:c}=C(),{data:u}=y(),d=n(()=>i??[],[i]),f=n(()=>u??[],[u]),p=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),m=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[h,g]=o(!1),[v,b]=o(null),x=l({onSuccess:p}),S=w({onSuccess:({token:e,record:t})=>{m(),g(!1),b({token:e,label:t.name})}}),T=_({onSuccess:m}),E=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&x.mutate({id:e})},D=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&T.mutate({id:e})};return t(K,{children:[t(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[s(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),t(`button`,{onClick:()=>g(!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 disabled:opacity-50`,disabled:f.length===0,title:f.length===0?`Create a user first`:`Issue a scoped token`,children:[s(B,{className:`h-3.5 w-3.5`}),`New token`]})]}),t(je,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[f.length===0&&s(Ne,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),f.map(e=>s(Fe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{D(e,t)},revokePending:T.isPending,revokeId:T.variables?.id},e.id))]}),d.length>0&&s(je,{title:`Legacy API keys`,subtitle:`${d.length} pre-existing — revoke only`,children:s(Pe,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:d.map(e=>{let n=!!e.isAdmin,r=x.isPending&&x.variables?.id===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${n?De:Oe}`,children:n?`admin`:`regular`})}),t(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:ke(e.allowedProviders)||`all`}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:t(`button`,{onClick:()=>{E(e.id,e.label)},disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[r?s(L,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),c&&s(Me,{}),h&&s(Ie,{users:f.map(e=>({id:e.id,username:e.username})),onClose:()=>g(!1),onSubmit:e=>S.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:S.isPending}),v&&s(Le,{token:v.token,label:v.label,onClose:()=>b(null)})]})}function je({title:e,subtitle:n,children:r}){return t(`div`,{className:`space-y-2`,children:[t(`div`,{className:`flex items-baseline justify-between`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&s(`span`,{className:`text-[10px] text-foreground-subtle`,children:n})]}),r]})}function Me(){return s(`div`,{className:`space-y-2`,children:[1,2].map(e=>s(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function Ne({text:e}){return s(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function Pe({headers:e,rows:n}){return s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:s(`tr`,{children:e.map((t,n)=>s(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),s(`tbody`,{children:n})]})})}function Fe({userId:e,username:n,onRevoke:r,revokePending:i,revokeId:a}){let{data:o,isLoading:c}=p({userId:e}),l=o??[];return c||l.length===0?null:t(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground`,children:n}),s(Pe,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:l.map(e=>{let n=i&&a===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),t(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,n)=>t(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${x(e.selector)}]`:e.target]},n))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.expiresAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:t(`button`,{onClick:()=>r(e.id,e.name),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[n?s(L,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function Ie({users:e,onClose:n,onSubmit:r,submitting:i}){let{user:a}=H(),c=a?.isAdmin===!0?null:a?.scopes??[],[l,u]=o(e[0]?.id??``),[d,f]=o(``),[p,m]=o([{type:`capability`,target:``,access:[`view`,`create`]}]),[h,g]=o(``),_=k(p),v=l!==``&&d.trim().length>0&&p.length>0&&_===null&&!i;return t(Re,{title:`Create scoped token`,onClose:n,children:[t(`div`,{className:`space-y-3`,children:[s(Y,{label:`On behalf of user`,children:s(`select`,{value:l,onChange:e=>u(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>s(`option`,{value:e.id,children:e.username},e.id))})}),s(Y,{label:`Name`,children:s(`input`,{value:d,onChange:e=>f(e.target.value),placeholder:`cloudflare-tunnel-route`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})}),t(Y,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[s(E,{value:p,onChange:m,clampToParent:c}),_&&s(`p`,{className:`mt-1 text-[10px] text-danger`,children:_})]}),s(Y,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:s(`input`,{type:`number`,min:1,value:h,onChange:e=>g(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),t(ze,{children:[s(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),t(`button`,{onClick:()=>{let e=parseInt(h,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;r({userId:l,name:d.trim(),scopes:p,expiresAt:t})},disabled:!v,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?s(L,{className:`h-3.5 w-3.5 animate-spin`}):s(B,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function Le({token:e,label:n,onClose:r}){let[i,a]=o(!1),c=async()=>{try{await navigator.clipboard.writeText(e),a(!0)}catch{}};return t(Re,{title:`Token: ${n}`,onClose:r,children:[t(`div`,{className:`space-y-3`,children:[s(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),s(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),t(ze,{children:[t(`button`,{onClick:()=>{c()},className:`inline-flex items-center gap-1.5 rounded 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:[i?s(le,{className:`h-3.5 w-3.5 text-primary`}):s(ne,{className:`h-3.5 w-3.5`}),i?`Copied`:`Copy`]}),s(`button`,{onClick:r,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function Re({title:e,onClose:n,children:r}){return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),s(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:s(V,{className:`h-4 w-4`})})]}),s(`div`,{className:`p-4`,children:r})]})})}function ze({children:e}){return s(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Y({label:e,hint:n,children:r}){return t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),r,n&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:n})]})}e();function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function Be(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function Ve(){return s(`div`,{className:`space-y-2`,children:[1,2].map(e=>s(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function He({text:e}){return s(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function Ue({headers:e,rows:n}){return s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:s(`tr`,{children:e.map((t,n)=>s(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),s(`tbody`,{children:n})]})})}function We(){let e=a(),r=O(),{data:i,isLoading:o}=h(),c=n(()=>i??[],[i]),l=D({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),u=async(e,t)=>{await r({title:`Revoke "${t}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&l.mutate({id:e})};return t(K,{icon:ge,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[o&&s(Ve,{}),!o&&c.length===0&&s(He,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!o&&c.length>0&&s(Ue,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:c.map(e=>{let n=e.revokedAt!==null,r=(l.isPending?l.variables?.id:void 0)===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>s(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:Be(e)},t))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 border-b border-border`,children:n?t(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,X(e.revokedAt)]}):s(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!n&&t(`button`,{onClick:()=>{u(e.id,e.integrationId)},disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[r?s(L,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}e();var Z=3e4,Q=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],$={title:`Authentication providers`,subtitle:`Every registered authentication surface in one list: login providers (local password, OIDC, SAML, magic-link) and second-factor providers (passkeys / WebAuthn — configure the relying-party RP ID + origin inline; users enroll from My access → Passkeys). Multiple providers run in parallel — enable/disable each independently. Disabling one only removes that method; local password login is unaffected.`,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,installLabel:`Add provider`};function Ge(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:me,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:R,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:R,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:W,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:W,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:B,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Ke(){let e=f({capName:Q[0].capName},{refetchInterval:Z}),t=f({capName:Q[1].capName},{refetchInterval:Z}),r=m(void 0,{refetchInterval:Z}),i=n(()=>fe(r.data??[]),[r.data]),a=n(()=>{let n=[],r=[e.data??[],t.data??[]];for(let[e,t]of Q.entries())for(let a of r[e]??[])n.push({addonId:a.addonId,displayName:i.get(a.addonId)??a.addonId,isActive:a.isActive,capName:t.capName,stageBadge:t.stageBadge});return n},[e.data,t.data,i]);return s(de,{title:$.title,subtitle:$.subtitle,pageIcon:B,itemIcon:B,capability:Q[0].capName,installButtonLabel:$.installLabel,items:a,isLoading:e.isLoading||t.isLoading,emptyTitle:$.emptyTitle,emptyDescription:$.emptyDescription,renderStatusBadges:e=>e.stageBadge===null?null:s(`span`,{className:`inline-flex items-center rounded-full border border-primary/30 bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary`,children:e.stageBadge}),renderExpandedPanel:e=>s(qe,{addonId:e.addonId})})}function qe({addonId:e}){let n=Ge(e),r=n.icon;return t(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[t(`div`,{className:`flex items-start gap-2.5`,children:[s(r,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),s(`div`,{className:`text-xs text-foreground font-medium`,children:n.headline})]}),s(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:n.bullets.map((e,t)=>s(`li`,{children:e},t))}),n.setupSteps&&n.setupSteps.length>0&&t(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[t(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[s(pe,{className:`h-3 w-3`}),`Setup steps`]}),s(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:n.setupSteps.map((e,t)=>s(`li`,{children:e},t))})]}),e===`local-auth`&&t(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[s(G,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),t(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,s(`a`,{href:`/system/my-access`,className:`underline text-primary`,children:`My access`}),` `,`→ “Two-factor authentication” → Enable 2FA. Admins can only remove a user’s active enrollment (lost device) from the`,` `,s(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function Je(){return s(`div`,{className:`flex flex-col p-4`,children:s(ue,{tabs:[{id:`users`,label:`Users`,icon:ve,content:s(we,{})},{id:`api-keys`,label:`Tokens`,icon:re,content:s(Ae,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:ge,content:s(We,{})},{id:`authentication`,label:`Authentication`,icon:B,content:s(Ke,{})}]})})}export{Je as IdentityPage};
@@ -1 +0,0 @@
1
- import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as l}from"./player-overlays-DN_06_1T.js";import{Ai as u,Bi as d,Di as f,Dn as p,En as m,Fi as h,Ft as g,Hi as _,Ii as v,It as y,Ji as b,Li as ee,Lt as x,Mi as te,Mt as S,Ni as ne,Oi as re,Pi as ie,Ri as ae,Ui as C,Vi as w,Wi as oe,Yi as T,Yt as E,et as D,ji as se,ki as ce,nt as O,qi as k,ys as A,zi as j}from"./src-Dw_YuA21.js";import{at as M,et as N}from"./src-5IxHiQXr.js";import{t as P}from"./boxes-OU9o0K_I.js";import{t as F}from"./copy-DS7H6-em.js";import{t as I}from"./play-DHOSTYVl.js";import{t as le}from"./refresh-cw-S_IzGUwN.js";import{t as ue}from"./rotate-ccw-CAAGiLAw.js";import{t as L}from"./server-CouJc0au.js";import{t as R}from"./shield-BLP_9cz7.js";import{t as z}from"./square-DO1rX5dt.js";import{t as B}from"./wifi-B8upcnaM.js";import{C as V,E as H,K as U,S as W,i as de,j as G,l as fe,o as K,x as pe,y as q,z as me}from"./index-B1t00qUp.js";import{t as he}from"./AdminPage-CCD07UMs.js";import{t as ge}from"./AdminTabs-DS0Srvsl.js";import{t as _e}from"./NodeAddonsSettingsPanel-DBFMTvCH.js";import{t as J}from"./AddonCollectionPage-DgxQiC5R.js";import{t as Y}from"./addon-display-names-DvSEQty-.js";var ve=U(`log-in`,[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]),ye=U(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),be=U(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]);t();var X=5e3,xe={connected:!1,endpoint:null};function Se(){let e=a(),t=p({capName:`network-access`},{refetchInterval:X}),n=m(void 0,{refetchInterval:X}),i=r(()=>Y(n.data??[]),[n.data]),c=r(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:i.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,i]),[l,u]=o(null),[d,f]=o({}),h=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),u(null),f(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},g=(e,t)=>{u(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);f(e=>({...e,[n]:r}))},_=b({onSuccess:h,onError:g}),v=T({onSuccess:h,onError:g});return s(J,{title:`Remote Access`,subtitle:`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …). Settings, Logs and Events are docked under every provider.`,pageIcon:H,itemIcon:H,capability:`network-access`,installButtonLabel:`Add tunnel`,items:c,isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>s(we,{addonId:e.addonId}),itemError:e=>d[e.addonId]??null,renderPrimaryAction:e=>s(Te,{addonId:e.addonId,busyId:l,onStart:e=>{u(e),_.mutate({addonId:e})},onStop:e=>{u(e),v.mutate({addonId:e})}})})}function Ce(e){let{data:t}=k({addonId:e},{refetchInterval:X,retry:!1}),n=t?M.safeParse(t):null;return n?.success?n.data:xe}function we({addonId:e}){let t=Ce(e);return n(i,{children:[s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.connected?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.connected?`Connected`:`Disconnected`}),t.endpoint&&n(`a`,{href:t.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-[10px] text-emerald-700 dark:text-emerald-300 hover:underline flex items-center gap-1`,children:[s(G,{className:`h-3 w-3`}),t.endpoint.url]})]})}function Te({addonId:e,busyId:t,onStart:r,onStop:i}){let a=Ce(e),o=t===e;return a.connected?n(x,{size:`sm`,variant:`secondary`,disabled:o,onClick:()=>i(e),children:[o?s(V,{className:`h-3 w-3 animate-spin`}):s(z,{className:`h-3 w-3`}),`Stop`]}):n(x,{size:`sm`,variant:`primary`,disabled:o,onClick:()=>r(e),children:[o?s(V,{className:`h-3 w-3 animate-spin`}):s(I,{className:`h-3 w-3`}),`Start`]})}t();var Ee=3e4;function De(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function Oe(){let e=p({capName:`turn-provider`},{refetchInterval:Ee}),t=m(void 0,{refetchInterval:Ee}),i=A(),a=i.data??[],o=r(()=>Y(t.data??[]),[t.data]);return s(J,{title:`TURN Servers`,subtitle:`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`,pageIcon:q,itemIcon:q,capability:`turn-provider`,installButtonLabel:`Add provider`,items:r(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:o.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,o]),isLoading:e.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>s(ke,{addonId:e.addonId,enabled:e.isActive}),trailing:n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),s(x,{size:`sm`,variant:`secondary`,onClick:()=>i.refetch(),disabled:i.isFetching,children:`Refresh`})]}),s(`div`,{className:`p-4`,children:a.length===0?s(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):s(`div`,{className:`flex flex-col gap-3`,children:a.map((e,t)=>{let r=Array.isArray(e.urls)?e.urls:[e.urls];return n(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&n(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[e.username&&n(`span`,{children:[s(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,s(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&n(`span`,{children:[s(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,s(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),s(`ul`,{className:`divide-y divide-border`,children:r.map(e=>s(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function ke({addonId:e,enabled:t}){let i=A({addonId:e},{enabled:t,retry:!1}),a=r(()=>De(i.data??[]),[i.data]);return!t||a.length===0?null:n(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[n(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,a.length,`)`]}),s(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>s(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}t();var Ae={lan:q,wifi:B,docker:P,vpn:W,loopback:L,other:L},je={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Me=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function Ne(e){let{interfaces:t,disabled:i,hideLoopback:a,ipv4Only:o,emptyMessage:c}=e,l=r(()=>t.filter(e=>!(a&&e.kind===`loopback`||o&&e.family!==`IPv4`)),[t,a,o]),u=r(()=>{let e=new Map;for(let t of l){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Me.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[l]),d=t=>e.mode===`single`?e.value===t:e.value.includes(t),f=t=>{if(i||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let n=new Set(e.value);n.has(t.address)?n.delete(t.address):n.add(t.address),e.onChange([...n])};return l.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic`,children:c??`No addresses available.`}):s(`div`,{className:`flex flex-col gap-3`,children:u.map(({kind:t,items:r})=>n(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[s(Ae[t]??L,{className:`h-3.5 w-3.5 text-foreground-subtle`}),s(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:je[t]??t}),n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),s(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=d(t.address),a=t.kind===`loopback`,o=!t.plausible&&!a;return n(`li`,{className:`flex items-center gap-3 px-3 py-2 ${a?`opacity-60 cursor-not-allowed`:i?`opacity-60`:o?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>f(t),children:[s(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode===`single`?`rounded-full`:`rounded`} border ${r?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:r&&s(me,{className:`h-3 w-3`})}),n(`div`,{className:`flex-1 min-w-0 ${o?`text-foreground-subtle`:``}`,children:[n(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s(`span`,{className:`font-mono text-xs font-semibold ${o?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),s(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),a&&s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),o&&n(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[s(K,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),n(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}t();var Pe={"lan-ipv4":{label:`IPv4`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`},"lan-ipv6":{label:`IPv6`,className:`bg-violet-500/15 text-violet-700 dark:text-violet-300`},public:{label:`Public`,className:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},loopback:{label:`Loopback`,className:`bg-foreground-subtle/15 text-foreground-subtle`}};function Z(e){return e.kind!==`loopback`}function Fe(e){return e.kind!==`loopback`}function Ie(){let e=a(),t=l(),i=te(void 0,{refetchInterval:3e4}),u=f(void 0),d=v({onSuccess:()=>{e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),p=ie({onSuccess:t=>{y(t.addresses),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),m=r(()=>i.data?.interfaces??[],[i.data]),h=re({port:typeof window<`u`?Number(window.location.port)||(window.location.protocol===`https:`?443:80):4e3,scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),[_,y]=o([]),[b,ne]=o(!1);c(()=>{!b&&u.data&&(y(u.data.addresses),ne(!0))},[u.data,b]);let C=u.data?.addresses??[],w=r(()=>{if(_.length!==C.length)return!0;let e=[..._].toSorted(),t=[...C].toSorted();return e.some((e,n)=>e!==t[n])},[_,C]),oe=()=>{d.mutate({addresses:[..._]})},T=()=>{y(C)},E=()=>{y([])},O=()=>{i.refetch(),h.refetch(),u.refetch(),A.refetch(),M.refetch()},k=async()=>{try{let e=await t.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},A=ce(),j=ee({onSuccess:()=>void A.refetch()}),M=se(),N=ae({onSuccess:()=>void M.refetch()}),P=h.data?.endpoints??[],F=A.data?.baseUrl??null,I=A.data?.resolved??null,L=M.data?.baseUrls??[],R=L.length===0,z=F===null,B=e=>R?e.kind===`lan-ipv4`||e.kind===`public`&&e.interfaceKind===`public`:L.includes(e.baseUrl),V=e=>F===null?I===e.baseUrl:F===e.baseUrl,H=e=>{if(!Z(e))return;let t=R?P.filter(e=>Z(e)&&B(e)).map(e=>e.baseUrl):[...L],n=t.includes(e.baseUrl)?t.filter(t=>t!==e.baseUrl):[...t,e.baseUrl];N.mutate({baseUrls:n})},U=e=>{if(Fe(e)){if(V(e)){z||j.mutate({baseUrl:null});return}j.mutate({baseUrl:e.baseUrl})}},W=r(()=>[{key:`url`,header:`Endpoint`,render:e=>n(`div`,{className:`min-w-0 py-0.5`,children:[s(`div`,{className:`font-mono text-[12px] break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),n(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[s(`span`,{children:e.label}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&s(`span`,{className:`uppercase tracking-wide`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&n(`span`,{className:`inline-flex items-center gap-1 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[s(K,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]})]})},{key:`kind`,header:`Kind`,nowrap:!0,render:e=>{let t=Pe[e.kind]??Pe.loopback;return s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.className}`,children:t.label})}},{key:`viewer`,headerRender:()=>n(`span`,{className:`inline-flex items-center gap-1`,children:[`Viewer`,R?s(`span`,{className:`text-[10px] font-normal normal-case text-foreground-subtle`,children:`auto`}):null]}),align:`center`,nowrap:!0,width:`w-24`,render:e=>{let t=Z(e);return s(`label`,{className:`inline-flex justify-center ${t?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:e.kind===`loopback`?`Loopback is not a client route.`:`Use this URL in the API / viewer race.`,children:s(S,{checked:t&&B(e),disabled:!t||N.isPending,onChange:()=>H(e),"aria-label":`Viewer: ${e.baseUrl}`})})}},{key:`notifications`,headerRender:()=>n(`span`,{className:`inline-flex items-center gap-1`,children:[`Notifications`,z?s(`span`,{className:`text-[10px] font-normal normal-case text-foreground-subtle`,children:`auto`}):null]}),align:`center`,nowrap:!0,width:`w-28`,render:e=>{let t=Fe(e);return s(`label`,{className:`inline-flex justify-center ${t?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:t?`Notification links and deep links use this address.`:`Loopback is not a client route.`,children:s(S,{checked:t&&V(e),disabled:!t||j.isPending,onChange:()=>U(e),"aria-label":`Notifications: ${e.baseUrl}`})})}}],[R,z,L,F,I,N.isPending,j.isPending,P]);return n(he,{children:[n(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[s(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pin which host addresses exist, then tick the destinations each URL should serve. Viewer auto is IPv4 + public; every other row (including IPv6) can be ticked on.`}),n(`div`,{className:`flex items-center gap-2 shrink-0`,children:[n(x,{size:`sm`,variant:`secondary`,onClick:O,disabled:i.isLoading,children:[s(le,{className:`h-3 w-3 ${i.isLoading?`animate-spin`:``}`}),`Refresh`]}),s(x,{size:`sm`,variant:`secondary`,onClick:k,children:`Probe race`})]})]}),n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between gap-3 flex-wrap`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:_.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${_.length} pinned`})]}),n(`div`,{className:`flex items-center gap-1`,children:[n(x,{size:`sm`,variant:`secondary`,onClick:()=>p.mutate(void 0),disabled:p.isPending||d.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[s(fe,{className:`h-3 w-3`}),p.isPending?`Detecting…`:`Best match`]}),n(x,{size:`sm`,variant:`secondary`,onClick:E,disabled:_.length===0||d.isPending,children:[s(ue,{className:`h-3 w-3`}),`Clear`]}),w&&s(x,{size:`sm`,variant:`secondary`,onClick:T,disabled:d.isPending,children:`Discard`}),n(x,{size:`sm`,variant:`primary`,onClick:oe,disabled:!w||d.isPending,children:[s(ye,{className:`h-3 w-3`}),d.isPending?`Saving…`:`Save`]})]})]}),s(`div`,{className:`p-4`,children:s(Ne,{mode:`multiple`,interfaces:m,value:_,onChange:y,disabled:d.isPending,emptyMessage:i.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between gap-3 flex-wrap`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:`Ranked URLs this hub advertises. Tick Viewer (many) and Notifications (one).`})]}),n(`div`,{className:`flex items-center gap-1`,children:[!R&&s(x,{size:`sm`,variant:`secondary`,disabled:N.isPending,onClick:()=>N.mutate({baseUrls:[]}),children:`Viewer → auto`}),!z&&s(x,{size:`sm`,variant:`secondary`,disabled:j.isPending,onClick:()=>j.mutate({baseUrl:null}),children:`Notifications → auto`})]})]}),z&&I===null&&s(`p`,{className:`px-4 pt-3 text-[11px] text-amber-600 dark:text-amber-400`,children:`No public address is reachable, so notification media ships as bytes only — a backend that can only take links (WhatsApp, gotify) receives none.`}),s(D,{columns:W,rows:P,rowKey:e=>`${e.priority}-${e.baseUrl}`,minWidthPx:640,bordered:!1,mobileMode:`scroll`,emptyMessage:h.isLoading?`Loading…`:`No endpoints available.`,rowClassName:e=>e.plausible?void 0:`opacity-80`})]})]})}t();var Le={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Q=5e3,Re=3e4,ze={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function Be(){let e=p({capName:`mesh-network`},{refetchInterval:Q}),t=m(void 0,{refetchInterval:Q}),n=r(()=>Y(t.data??[]),[t.data]);return s(J,{title:`Mesh Networks`,subtitle:`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`,pageIcon:P,itemIcon:q,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:r(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No mesh-network providers installed`,emptyDescription:`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`,renderStatusBadges:e=>s(Ve,{addonId:e.addonId}),renderPrimaryAction:e=>s(He,{addonId:e.addonId}),renderExpandedPanel:e=>s(Ue,{addonId:e.addonId})})}function $(e){let{data:t,isLoading:n}=d({addonId:e},{refetchInterval:Q,retry:!1}),r=t?N.safeParse(t):null;return{status:r?.success?r.data:ze,isLoading:n}}function Ve({addonId:e}){let{status:t}=$(e);return n(i,{children:[s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.joined?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.joined?`Joined`:`Not joined`}),t.joined&&n(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:[t.peerCount,` peer`,t.peerCount===1?``:`s`]})]})}function He({addonId:t}){let r=a(),[c,u]=o(!1),[d,f]=o(null),p=l(),{status:m}=$(t),h=e(()=>{r.invalidateQueries({queryKey:[[`meshNetwork`]]})},[r]),g=oe(),_=w({onSuccess:h}),v=C({onSuccess:h}),y=e(async()=>{u(!0);let e={cancelled:!1};f(e);try{let n=await g.mutateAsync({addonId:t});if(e.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!e.cancelled&&(await Xe(2e3),!e.cancelled);){let e=await p.trpcClient.meshNetwork.getStatus.query({addonId:t}).catch(()=>null),n=e?N.safeParse(e):null;if(n?.success&&n.data.joined){h();break}if(Date.now()-r>6e5)break}}finally{u(!1),f(null)}},[t,h,g,p]),b=e(()=>{d&&(d.cancelled=!0),u(!1),f(null)},[d]);return s(i,{children:m.joined?n(i,{children:[n(x,{size:`sm`,variant:`secondary`,disabled:_.isPending,onClick:()=>_.mutate({addonId:t}),children:[_.isPending?s(V,{className:`h-3 w-3 animate-spin`}):s(pe,{className:`h-3 w-3`}),`Disconnect`]}),n(x,{size:`sm`,variant:`ghost`,disabled:v.isPending,onClick:()=>v.mutate({addonId:t}),children:[v.isPending?s(V,{className:`h-3 w-3 animate-spin`}):s(be,{className:`h-3 w-3`}),`Log out`]})]}):c?n(x,{size:`sm`,variant:`ghost`,onClick:b,children:[s(de,{className:`h-3 w-3 mr-1`}),` Cancel`]}):n(i,{children:[n(x,{size:`sm`,variant:`primary`,onClick:()=>void y(),children:[s(ve,{className:`h-3 w-3`}),`Connect`]}),n(x,{size:`sm`,variant:`ghost`,disabled:v.isPending,onClick:()=>v.mutate({addonId:t}),children:[v.isPending?s(V,{className:`h-3 w-3 animate-spin`}):s(be,{className:`h-3 w-3`}),`Log out`]})]})})}function Ue({addonId:e}){let{status:t}=$(e),r=_({addonId:e},{refetchInterval:Re,retry:!1});return n(`div`,{className:`rounded-lg border border-border bg-surface`,children:[n(`div`,{className:`p-4 space-y-4`,children:[t.error&&s(E,{message:t.error}),s(We,{status:t}),t.endpoints.length>0&&n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>n(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[n(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Le[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?s(H,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),n(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[s(G,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),s(`div`,{className:`border-t border-border`,children:s(Ke,{peers:r.data?.peers??[],loading:r.isLoading})})]})}function We({status:e}){return s(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:`Tenant`,value:e.tenantName||`—`},{label:`User`,value:e.userLogin??`—`},{label:`Control plane`,value:e.controlPlaneUrl||`—`},{label:`Mesh IP`,value:e.meshIp||`—`,mono:!0},{label:`MagicDNS`,value:e.magicDnsHostname||`—`,mono:!0},{label:`DNS suffix`,value:e.magicDnsSuffix||`—`,mono:!0},{label:`Peers`,value:String(e.peerCount)},{label:`Key expiry`,value:e.keyExpiry?Ge(e.keyExpiry):`—`}].map(e=>n(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[s(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),s(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Ge(e){let t=e-Date.now();if(t<0)return`Expired ${Ye(e)}`;let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return`in ${n} days`;let r=Math.floor(t/36e5);return r>1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))} min`}function Ke({peers:t,loading:i}){let a=r(()=>t.map(e=>({...e,_id:e.id})),[t]),o=e(e=>{e&&navigator.clipboard?.writeText(e)},[]),c=r(()=>[{key:`hostname`,header:`Hostname`,render:e=>n(`div`,{className:`flex flex-col`,children:[n(`div`,{className:`flex items-center gap-1.5`,children:[s(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&s(y,{variant:`info`,children:`self`}),e.exitNodeOption&&s(y,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&s(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?n(`div`,{className:`flex items-center gap-1`,children:[s(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),s(`button`,{onClick:()=>o(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:s(F,{className:`h-3 w-3 text-foreground-subtle`})})]}):s(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?n(`div`,{className:`flex items-center gap-1`,children:[s(`span`,{className:`font-mono text-xs`,children:t}),s(`button`,{onClick:()=>o(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:s(F,{className:`h-3 w-3 text-foreground-subtle`})})]}):s(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>n(`div`,{className:`flex items-center gap-1.5`,children:[s(y,{variant:qe(e.connection),children:e.connection}),e.relay&&s(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?s(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):s(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>n(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Je(e.txBytes),` · ↓ `,Je(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>s(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?Ye(e.lastSeenMs):`—`})}],[o]);return i&&t.length===0?n(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[s(V,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):t.length===0?s(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):s(`div`,{className:`p-4`,children:s(D,{columns:c,rows:a,rowKey:e=>e._id,minWidthPx:820})})}function qe(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Je(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function Ye(e){let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}function Xe(e){return new Promise(t=>setTimeout(t,e))}t();function Ze(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function Qe(){let e=a(),t=u(void 0,{refetchInterval:15e3}),r=ne({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),i=h({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),c=j({onSuccess:()=>{f(!1),m(``),v(``),b(``),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),l=t.data,[d,f]=o(!1),[p,m]=o(``),[_,v]=o(``),[y,b]=o(``),ee=()=>{if(!l?.caCertPem)return;let e=new Blob([l.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},te=l?.mode===`uploaded`?`Uploaded`:l?.mode===`generated`?`Generated local CA`:`TLS disabled`;return n(`div`,{className:`flex flex-col gap-4`,children:[s(_e,{nodeId:`hub`,addonIds:[`local-network`],level:`global`,title:`LAN HTTP`,description:`Native apps on this Wi-Fi use http:// and skip the private certificate. The tunnel and this admin UI stay on HTTPS.`}),n(g,{className:`p-4 space-y-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(R,{className:`h-4 w-4 text-foreground-subtle`}),s(`h3`,{className:`text-sm font-semibold`,children:`Certificate`})]}),t.isError&&s(`p`,{className:`text-xs text-danger`,children:`Could not read TLS status.`}),l?.reissueError&&s(`p`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:l.reissueError}),l?.restartRequired&&s(`p`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Restart the hub to apply the new certificate.`}),n(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Mode`}),s(`dd`,{className:`font-medium`,children:te})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Valid to`}),s(`dd`,{className:`font-mono`,children:l?.validTo?new Date(l.validTo).toLocaleString():`—`})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Leaf SHA-256`}),s(`dd`,{className:`font-mono`,title:l?.leafFingerprintSha256??void 0,children:Ze(l?.leafFingerprintSha256??null)})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`CA SHA-256`}),s(`dd`,{className:`font-mono`,title:l?.caFingerprintSha256??void 0,children:Ze(l?.caFingerprintSha256??null)})]})]}),l&&l.sans.length>0&&s(`div`,{className:`flex flex-wrap gap-1`,children:l.sans.map(e=>s(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),n(`div`,{className:`flex flex-wrap gap-2`,children:[s(O,{label:`Regenerate`,title:`Issue a new leaf?`,description:`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`,confirmLabel:`Regenerate`,disabled:l?.mode===`uploaded`||r.isPending,action:()=>r.mutateAsync({})}),s(x,{size:`sm`,variant:`outline`,onClick:()=>f(e=>!e),children:`Upload`}),l?.caCertPem&&s(x,{size:`sm`,variant:`outline`,onClick:ee,children:`Download CA`}),l?.mode===`uploaded`&&s(O,{label:`Revert to generated`,title:`Drop the uploaded certificate?`,description:`Deletes the uploaded pair and returns to the generated local CA.`,confirmLabel:`Revert`,confirmVariant:`danger`,disabled:i.isPending,action:()=>i.mutateAsync({})})]}),d&&n(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`Certificate PEM`,s(`textarea`,{value:p,onChange:e=>m(e.target.value),rows:6,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`Private key PEM`,s(`textarea`,{value:_,onChange:e=>v(e.target.value),rows:6,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`CA PEM (optional)`,s(`textarea`,{value:y,onChange:e=>b(e.target.value),rows:4,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),s(x,{size:`sm`,disabled:!p.trim()||!_.trim()||c.isPending,onClick:()=>c.mutate({certPem:p,keyPem:_,...y.trim()?{caPem:y}:{}}),children:`Save certificate`}),c.isError&&s(`p`,{className:`text-xs text-danger`,children:c.error instanceof Error?c.error.message:`Upload failed`})]})]})]})}function $e(){return s(`div`,{className:`flex flex-col p-4`,children:s(ge,{defaultTab:`addresses`,tabs:[{id:`local-access`,label:`Local access`,icon:B,content:s(Qe,{})},{id:`addresses`,label:`Network Addresses`,icon:L,content:s(Ie,{})},{id:`remote-access`,label:`Remote Access`,icon:H,content:s(Se,{})},{id:`mesh`,label:`Mesh Networks`,icon:P,content:s(Be,{})},{id:`turn`,label:`TURN Servers`,icon:q,content:s(Oe,{})}]})})}export{$e as NetworkPage};