@camstack/addon-admin-ui 1.1.21 → 1.1.22

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 (88) hide show
  1. package/dist/assets/{AddLocationWizard-CtHh4Ucy.js → AddLocationWizard-hVwjbOvf.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-D7eIR9NV.js → AddonCollectionPage-CTsqn59E.js} +1 -1
  3. package/dist/assets/Addons-CCbeVMQt.js +1 -0
  4. package/dist/assets/{AdminTabs-SHELeszh.js → AdminTabs-H2eHA_BP.js} +1 -1
  5. package/dist/assets/{BrokerForm-Acer17Cj.js → BrokerForm-I-2eiXTD.js} +1 -1
  6. package/dist/assets/{Capabilities-F8EOFDyp.js → Capabilities-KNxdGU5R.js} +1 -1
  7. package/dist/assets/{CapabilityBadges-uN4xnNt9.js → CapabilityBadges-Bp9qwWAG.js} +1 -1
  8. package/dist/assets/{Cluster-Br54rXlE.js → Cluster-ChnNCri_.js} +1 -1
  9. package/dist/assets/{Dashboard-Ds4y9hsA.js → Dashboard-CgzNKw4S.js} +1 -1
  10. package/dist/assets/{Data-BadX573w.js → Data-GY9aNQ1Y.js} +1 -1
  11. package/dist/assets/{DetectionIntelligence-Crlw81K-.js → DetectionIntelligence-CbBEvocZ.js} +1 -1
  12. package/dist/assets/DeviceDetail-sgGEfTXB.js +2 -0
  13. package/dist/assets/{Devices-CSuhWvHj.js → Devices-2wZcDSXn.js} +1 -1
  14. package/dist/assets/EmbedPlayerPage-BSfF5HmG.js +1 -0
  15. package/dist/assets/{FormBuilder-CegbdtFO.js → FormBuilder-CO6H7q61.js} +1 -1
  16. package/dist/assets/Identity-Ctx_yZtf.js +1 -0
  17. package/dist/assets/IntegrationDetail-DQI58WRY.js +1 -0
  18. package/dist/assets/{Integrations-DiaCWNDC.js → Integrations-Dee1SHhr.js} +1 -1
  19. package/dist/assets/Integrations-rZdfMVdZ.js +1 -0
  20. package/dist/assets/{Logs-BLu18FYD.js → Logs-BJ61UdxK.js} +1 -1
  21. package/dist/assets/{MotionZonesSettings-CQu6k79T.js → MotionZonesSettings-CYzimYmN.js} +1 -1
  22. package/dist/assets/{MyAccess-CLaxbnXE.js → MyAccess-Bgewpx3A.js} +1 -1
  23. package/dist/assets/Network-Dc_a0WJ9.js +1 -0
  24. package/dist/assets/NodeAddonsSettingsPanel-CWrLPV6J.js +1 -0
  25. package/dist/assets/{NotificationTargets-C7ekw4dH.js → NotificationTargets-lEW7Zldv.js} +1 -1
  26. package/dist/assets/Pipeline-CbfX9p5j.js +1 -0
  27. package/dist/assets/{PrivacyMaskSettings-CyaPh6bF.js → PrivacyMaskSettings-CzPxZHZ1.js} +1 -1
  28. package/dist/assets/{ProviderIcon-BVyDFfZQ.js → ProviderIcon-Dm-sZ7Df.js} +1 -1
  29. package/dist/assets/{ScanNetworkModal-CAWMDwou.js → ScanNetworkModal-Vcr_-aIb.js} +1 -1
  30. package/dist/assets/{Settings-vLhU6eIs.js → Settings-WQCzalu_.js} +1 -1
  31. package/dist/assets/{Showroom-CyXCqK1A.js → Showroom-BxISco8h.js} +1 -1
  32. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DAX7XSx3.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CKTRvTR8.js} +1 -1
  33. package/dist/assets/circle-check-big-B9mpY_ym.js +1 -0
  34. package/dist/assets/{copy-B6IIL8kT.js → copy-CjMMaCPu.js} +1 -1
  35. package/dist/assets/{dist-DwxrMREn.js → dist-DsiSY20Z.js} +1 -1
  36. package/dist/assets/dist-u_nf627j.js +7 -0
  37. package/dist/assets/{download-H_XK0DLj.js → download-35ioIRtw.js} +1 -1
  38. package/dist/assets/{esm-C1lbdX0r.js → esm-DPIMznCO.js} +1 -1
  39. package/dist/assets/{hostInit-BhkWchBW.js → hostInit-BQK5GXsV.js} +1 -1
  40. package/dist/assets/index-BQGzI2C-.css +2 -0
  41. package/dist/assets/index-BdGL2J0e.js +4 -0
  42. package/dist/assets/{key-round-Dyj4n5xw.js → key-round-CHE1k3cQ.js} +1 -1
  43. package/dist/assets/{mf-entry-bootstrap-0-efb2b672.js → mf-entry-bootstrap-0-5940e459.js} +2 -2
  44. package/dist/assets/{pencil-D4eE6uEV.js → pencil-C1w2uLp9.js} +1 -1
  45. package/dist/assets/{player-overlays-BH6aBUe-.js → player-overlays-DlPIT9xj.js} +1 -1
  46. package/dist/assets/plus-D9QBDEjM.js +1 -0
  47. package/dist/assets/{radio-CfQ90vM2.js → radio-DpwfMzDk.js} +1 -1
  48. package/dist/assets/{refresh-cw-DCVnt6DS.js → refresh-cw-DfSn-i0F.js} +1 -1
  49. package/dist/assets/remoteEntry-CIdYQQ-f.js +1 -0
  50. package/dist/assets/{rotate-ccw-D6a6yNNE.js → rotate-ccw--rHGluty.js} +1 -1
  51. package/dist/assets/rotate-cw-DtSHMNUL.js +1 -0
  52. package/dist/assets/search-DgJL1Gey.js +1 -0
  53. package/dist/assets/{server-DglCnPiH.js → server-BlM9U_dS.js} +1 -1
  54. package/dist/assets/{sparkles-Cfbrs3IH.js → sparkles-COBUjBX-.js} +1 -1
  55. package/dist/assets/square-VsNW1mnX.js +1 -0
  56. package/dist/assets/{square-check-big-DkE6GAlP.js → square-check-big-Dej4DiE7.js} +1 -1
  57. package/dist/assets/src-C9eW94dA.js +7 -0
  58. package/dist/assets/src-CtvTbpOC.js +61 -0
  59. package/dist/assets/{upload-D2GIH0tS.js → upload-BJzZajFJ.js} +1 -1
  60. package/dist/assets/useDevice-CjqFlWNw.js +1 -0
  61. package/dist/assets/{useEventInvalidation-B-rUQp_C.js → useEventInvalidation-CY1yyH4R.js} +1 -1
  62. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Im2hSrP1.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Dl7HuNe3.js} +2 -2
  63. package/dist/assets/{wifi-TvDBvENo.js → wifi-Dj3gSpzs.js} +1 -1
  64. package/dist/assets/{zap-Cb9KqtLJ.js → zap-DLkdpIj9.js} +1 -1
  65. package/dist/index.html +6 -6
  66. package/dist/server/addon.js +703 -25
  67. package/package.json +1 -1
  68. package/dist/assets/Addons-BoCfiheF.js +0 -1
  69. package/dist/assets/DeviceDetail-DLlQRj_v.js +0 -2
  70. package/dist/assets/EmbedPlayerPage-ChE8oSUc.js +0 -1
  71. package/dist/assets/Identity-CVFKJESU.js +0 -1
  72. package/dist/assets/IntegrationDetail-DsUKq3z5.js +0 -1
  73. package/dist/assets/Integrations-CuVxDYIj.js +0 -1
  74. package/dist/assets/Network-kXez-Kpm.js +0 -1
  75. package/dist/assets/NodeAddonsSettingsPanel-BOqWOM7_.js +0 -1
  76. package/dist/assets/Pipeline-iwj4d4DN.js +0 -1
  77. package/dist/assets/circle-check-big-CgdBZ1l7.js +0 -1
  78. package/dist/assets/dist-BAhtRh_d.js +0 -6
  79. package/dist/assets/index-Bvv3nxPc.css +0 -2
  80. package/dist/assets/index-DjbbJhB4.js +0 -4
  81. package/dist/assets/plus-CDeS7IvC.js +0 -1
  82. package/dist/assets/remoteEntry-D3SUgyps.js +0 -1
  83. package/dist/assets/rotate-cw-BZnE1cAg.js +0 -1
  84. package/dist/assets/search-DGzI_eqI.js +0 -1
  85. package/dist/assets/square-Cgyuo7em.js +0 -1
  86. package/dist/assets/src-BVMxsNe8.js +0 -61
  87. package/dist/assets/src-CCmaAR6i.js +0 -6
  88. package/dist/assets/useDevice-CAq7iz29.js +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-admin-ui",
3
- "version": "1.1.21",
3
+ "version": "1.1.22",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "CamStack Admin UI — Vite frontend build and server-side addon",
@@ -1 +0,0 @@
1
- import{St as e,Tr as t,Wi as n,Xi as r,_t as i,at as a,bt as o,dt as s,et as c,ft as l,g as u,gt as d,ht as f,it as p,lt as m,m as ee,nt as h,ot as te,pt as ne,qi as g,rt as re,st as _,tt as ie,ut as ae,v as oe,xt as v,yr as se,yt as ce}from"./src-BVMxsNe8.js";import{I as y,K as b,Q as x,R as le,S,W as C,b as w,o as T,q as E,x as D,z as O}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as ue}from"./player-overlays-BH6aBUe-.js";import{D as k}from"./src-CCmaAR6i.js";import{t as A}from"./download-H_XK0DLj.js";import{t as de}from"./plus-CDeS7IvC.js";import{t as j}from"./refresh-cw-DCVnt6DS.js";import{t as M}from"./search-DGzI_eqI.js";import{t as N}from"./upload-D2GIH0tS.js";import{A as fe,F as P,G as F,P as I,U as pe,V as L,f as me,h as R,i as he,o as z,p as B,s as ge,x as V}from"./index-DjbbJhB4.js";import{t as H}from"./AdminPage-BwmGKnRf.js";import{t as _e}from"./NodeAddonsSettingsPanel-BOqWOM7_.js";var ve=L(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),U=L(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`polyline`,{points:`12 6 12 12 16 14`,key:`68esgv`}]]),W=L(`octagon-alert`,[[`path`,{d:`M12 16h.01`,key:`1drbdi`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z`,key:`1fd625`}]]),ye=L(`package`,[[`path`,{d:`M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z`,key:`1a0edw`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}],[`polyline`,{points:`3.29 7 12 12 20.71 7`,key:`ousv84`}],[`path`,{d:`m7.5 4.27 9 5.15`,key:`1c824w`}]]),G=L(`skip-forward`,[[`polygon`,{points:`5 4 15 12 5 20 5 4`,key:`16p6eg`}],[`line`,{x1:`19`,x2:`19`,y1:`5`,y2:`19`,key:`futhcm`}]]);x();var K=new Set([`completed`,`failed`,`partially-failed`,`cancelled`]),q=new Set([`done`,`failed`,`skipped`]);function J(e){return!q.has(e.phase)&&!K.has(e.jobState)}function Y(e,t){let n=new Map,r=[...e].sort((e,t)=>e.createdAtMs-t.createdAtMs);for(let e of r){let r=K.has(e.state);for(let i of e.tasks)r&&i.finishedAtMs!==null&&t-i.finishedAtMs>6e4||n.set(i.packageName,{jobId:e.jobId,packageName:i.packageName,phase:i.phase,fromVersion:i.fromVersion,toVersion:i.toVersion,error:i.error,jobState:e.state,finishedAtMs:i.finishedAtMs})}return n}function be(){let{data:e}=ae({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=r(k.AddonsJobProgress,e=>e.job.jobId);return C(()=>{let n=new Map;for(let t of e??[])n.set(t.jobId,t);for(let[e,r]of t)n.set(e,r.job);return Y([...n.values()],Date.now())},[e,t])}var X={queued:{icon:U,cls:`bg-muted text-foreground-subtle`,label:`queued`},fetching:{icon:V,cls:`bg-primary/10 text-primary`,label:`fetching`,spin:!0},staged:{icon:V,cls:`bg-primary/10 text-primary`,label:`staged`,spin:!0},validating:{icon:V,cls:`bg-primary/10 text-primary`,label:`validating`,spin:!0},applying:{icon:V,cls:`bg-primary/10 text-primary`,label:`applying`,spin:!0},restarting:{icon:V,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:`restarting`,spin:!0},applied:{icon:V,cls:`bg-primary/10 text-primary`,label:`finalizing`,spin:!0},done:{icon:P,cls:`bg-success/10 text-success`,label:`updated`},failed:{icon:W,cls:`bg-danger/10 text-danger`,label:`failed`},skipped:{icon:G,cls:`bg-muted text-foreground-subtle`,label:`skipped`}};function xe({progress:e}){let t=X[e.phase],n=t.icon,r=e.error??`${e.packageName}: ${e.fromVersion??`?`} → ${e.toVersion}`;return S(`span`,{"data-testid":`addon-job-progress`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded shrink-0 ${t.cls}`,title:r,children:[D(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label,S(`span`,{className:`font-mono`,children:[`→ `,e.toVersion]})]})}function Se({packageName:e,currentVersion:t,installSource:n,onInstall:r,onClose:i,onSelect:o,selectedVersion:s}){let c=n===`upload`||n===`local`,{data:l,isLoading:u}=a({name:e});return S(`div`,{className:`fixed z-50 w-72 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,style:{top:`auto`,bottom:`auto`},ref:e=>{if(!e)return;let t=e.parentElement?.getBoundingClientRect();if(!t)return;let n=window.innerHeight-t.bottom,r=t.top;n<280&&r>n?(e.style.bottom=`${window.innerHeight-t.top+4}px`,e.style.top=`auto`):(e.style.top=`${t.bottom+4}px`,e.style.bottom=`auto`),e.style.right=`${window.innerWidth-t.right}px`},onClick:e=>e.stopPropagation(),children:[S(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[D(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Versions`}),D(`button`,{type:`button`,onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:D(he,{className:`h-3 w-3`})})]}),c&&S(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[D(N,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),S(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[S(`span`,{className:`font-semibold`,children:[n===`upload`?`Uploaded copy`:`Local copy`,` in place.`]}),` `,`Re-install `,D(`span`,{className:`font-mono`,children:t}),` from npm to track upstream releases again.`]})]}),u&&S(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[D(V,{className:`h-3.5 w-3.5 animate-spin`}),`Loading versions...`]}),l&&D(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:l.map(e=>{let n=e.version===t,i=o!==void 0&&e.version===s,a=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version),l=S(w,{children:[D(`span`,{className:`font-mono flex-1 text-left ${n?`text-primary font-semibold`:a?`text-amber-400`:`text-foreground`}`,children:e.version}),n&&D(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium bg-primary/10 text-primary`,children:`current`}),e.distTags.map(e=>D(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e===`latest`?`bg-emerald-500/15 text-emerald-400`:e===`beta`?`bg-amber-500/15 text-amber-400`:`bg-gray-500/15 text-gray-400`}`,children:e},e)),e.deprecated&&D(`span`,{className:`text-[9px] text-red-400 line-through`,children:`deprecated`}),D(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return o?S(`button`,{type:`button`,"aria-label":`Select ${e.version}`,onClick:()=>o(e.version),className:`w-full flex items-center gap-2 px-3 py-2 text-[11px] ${i?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[l,i?D(P,{className:`h-3 w-3 text-primary shrink-0`}):D(`span`,{className:`w-3 shrink-0`})]},e.version):S(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${n?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[l,n&&!c?D(P,{className:`h-3 w-3 text-primary shrink-0`}):D(`button`,{type:`button`,onClick:()=>r(e.version),className:`shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors`,title:n?`Re-install ${e.version} from npm`:`Install ${e.version}`,children:D(A,{className:`h-3 w-3`})})]},e.version)})}),l&&l.length===0&&D(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:`No versions found`})]})}var Z={queued:{icon:U,bg:`bg-muted text-foreground-subtle`,label:`queued`},updating:{icon:V,bg:`bg-primary/10 text-primary`,label:`updating`,spin:!0},"done-pending-restart":{icon:j,bg:`bg-amber-500/10 text-amber-700`,label:`pending restart`},done:{icon:P,bg:`bg-success/10 text-success`,label:`done`},failed:{icon:W,bg:`bg-danger/10 text-danger`,label:`failed`}};function Ce({item:e}){let t=Z[e.status],n=t.icon;return S(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${t.bg}`,title:e.error,children:[D(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label]})}x();var we=`device-export`;function Te(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===we)}function Ee({isBundle:e,installSource:t,addonId:n,iconPath:r,color:i}){let[a,o]=E(!1),s=i?{backgroundColor:`${i.startsWith(`#`)?i:`#${i}`}26`}:void 0,c=e?`bg-indigo-500/20 text-indigo-700 dark:text-indigo-300`:`bg-purple-500/20 text-purple-700 dark:text-purple-300`,l=n&&r?`/api/addon-assets/${n}/${r}`:null,u=!!l&&!a;return S(`div`,{className:`relative flex-shrink-0`,children:[D(`div`,{className:`h-9 w-9 rounded-lg flex items-center justify-center ${s?``:c}`,style:s,children:u?D(`img`,{src:l,alt:n,className:`h-5 w-5`,onError:()=>o(!0)}):D(e?ye:R,{className:`h-4 w-4`})}),t===`local`&&D(`span`,{className:`absolute -top-1.5 -left-1.5 text-[7px] font-bold leading-none bg-orange-500 text-white px-1 py-0.5 rounded -rotate-12 shadow-sm`,children:`DEV`}),t===`npm`&&D(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:D(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:D(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),t===`upload`&&D(`span`,{className:`absolute -top-1.5 -left-1.5 flex items-center justify-center h-4 w-4 rounded bg-cyan-500 -rotate-12 shadow-sm`,children:D(N,{className:`h-2.5 w-2.5 text-white`})})]})}function De({version:e,availableUpdate:t,selectedVersion:n,isUpdating:r,installSource:i,disabled:a,onUpdate:o,onOpenPicker:s,children:c}){if(r)return S(`span`,{className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-blue-500/30 bg-blue-500/10 text-blue-400 shrink-0`,children:[D(V,{className:`h-3 w-3 animate-spin`}),`Updating…`]});if(t){let r=n??t;return S(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[o&&S(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},disabled:a,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-semibold border border-blue-500/30 bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,title:`Update to ${r}`,children:[D(A,{className:`h-3 w-3`}),`Update`]}),S(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:a,"aria-label":`Select version to install`,title:`Installed ${e} — update available. Selected ${r}; tap to choose another version.`,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-bold font-mono border border-amber-500/40 bg-amber-500/15 text-amber-500 hover:bg-amber-500/25 animate-pulse disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[D(`span`,{className:`font-normal opacity-70`,children:e}),D(`span`,{className:`font-normal opacity-70`,children:`→`}),r,D(I,{className:`h-3 w-3`})]}),c]})}return S(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[S(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:a,className:[`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-bold font-mono border transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,i===`local`?`border-orange-500/30 bg-orange-500/10 text-orange-400 hover:bg-orange-500/20`:`border-emerald-500/30 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20`].join(` `),title:`Version ${e} — tap to view all versions`,children:[e,D(I,{className:`h-3 w-3 opacity-50`})]}),c]})}function Oe({addonId:e}){let t=T(),{data:n=`inherit`}=h({addonId:e}),r=i({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return D(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>D(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),r.mutate({addonId:e,channel:t})},disabled:r.isPending,className:`px-2.5 py-1 transition-colors capitalize ${n===t?t===`inherit`?`bg-gray-700/50 text-gray-700 dark:text-gray-300`:t===`off`?`bg-gray-700 text-gray-700 dark:text-gray-300`:t===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${t===`inherit`?``:`border-l border-border`}`,children:t},t))})}function ke({addon:e,agents:t=[],clusterStatus:r,hideVersion:i,availableUpdate:a,onUpdate:s,isUpdating:c,jobProgress:l,bundle:d,bulkItem:p,disabledByBulk:m,isSystem:h}){let[g,re]=E(!1),[_,ie]=E(!1),[ae,v]=E(!1),[se,ce]=E(null);O(()=>{ce(null)},[a]);let y=se??a,[b,x]=E(!1),[le,C]=E(!1),[k,A]=E(`logs`),M=T(),N=ue(),fe=pe(),P=n(),{manifest:F}=e,L=e.installedOn??[],R=!d&&!F.protected&&F.removable!==!1,z=!!d,V=d?.displayName??F.name,H=d?.packageName??F.packageName,U=d?.version??F.packageVersion??F.version,G=d?.installSource??e.installSource,K=d?d.bundle?.description??d.addons[0]?.manifest.description:F.description,q=o({onSuccess:()=>{M.invalidateQueries({queryKey:[[`addons`]]}),M.invalidateQueries({queryKey:[[`addonPages`]]}),M.invalidateQueries({queryKey:[[`capabilities`]]})}}),J=ne({onSuccess:()=>{M.invalidateQueries({queryKey:[[`addons`]]})}}),Y=te({onSuccess:()=>{M.invalidateQueries({queryKey:[[`addons`]]}),M.invalidateQueries({queryKey:[[`addonPages`]]}),M.invalidateQueries({queryKey:[[`capabilities`]]}),M.invalidateQueries({queryKey:[[`integrations`]]})}}),be=f({onSuccess:()=>{M.invalidateQueries({queryKey:[[`addons`]]}),M.invalidateQueries({queryKey:[[`alerts`]]})}}),X=e.health,Z=X?.phase===`failed`&&!X.inGracePeriod,we=Z&&X?.nextRetryAt&&!X.retrying;return S(`div`,{className:`rounded-lg border bg-surface overflow-hidden ${Z?`border-red-500/50`:`border-border`}`,children:[Z&&X&&S(`div`,{className:`bg-danger/10 border-b border-danger/30 px-4 py-2.5 flex items-start gap-2.5`,children:[D(W,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),S(`div`,{className:`flex-1 min-w-0`,children:[S(`div`,{className:`text-xs font-semibold text-danger`,children:[`Failed to load (attempt #`,X.retryCount,`)`]}),D(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:X.lastError?.message??`Unknown error`}),we&&X.nextRetryAt&&S(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:[`Auto-retry at `,new Date(X.nextRetryAt).toLocaleTimeString()]})]}),S(`button`,{type:`button`,disabled:be.isPending||X.retrying,onClick:e=>{e.stopPropagation(),be.mutate({packageName:H})},className:`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] font-semibold border border-red-400/40 bg-red-400/10 text-red-700 dark:text-red-300 hover:bg-red-400/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0`,title:`Reset retry counter and force immediate reload`,children:[D(j,{className:`h-3 w-3 ${be.isPending||X.retrying?`animate-spin`:``}`}),`Retry now`]})]}),S(`div`,{className:`flex items-start gap-3 px-4 py-3`,children:[D(Ee,{isBundle:z||!!F.components&&F.components.length>1,installSource:G,addonId:z?d.addons[0]?.manifest.id:F.id,iconPath:z?d.bundle?.icon??d.addons[0]?.manifest.icon:F.icon,color:z?d.addons[0]?.manifest.color:F.color}),S(`div`,{className:`flex-1 min-w-0`,children:[S(`div`,{className:`flex items-start justify-between gap-2`,children:[D(`span`,{className:`text-sm font-semibold text-foreground truncate min-w-0`,children:V}),!i&&D(De,{version:U,availableUpdate:a,...y===void 0?{}:{selectedVersion:y},isUpdating:c,installSource:G,disabled:m,...s&&y!==void 0?{onUpdate:()=>s(y)}:{},onOpenPicker:()=>v(e=>!e),children:ae&&D(Se,{packageName:H,currentVersion:U,...G?{installSource:G}:{},...a!==void 0&&y!==void 0?{selectedVersion:y,onSelect:e=>{ce(e),v(!1)}}:{},onInstall:e=>{v(!1),Y.mutate({packageName:H,version:e})},onClose:()=>v(!1)})})]}),S(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[H!==V&&D(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:H}),z&&S(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,children:[D(ye,{className:`h-3 w-3`}),d.addons.length]}),h&&S(`span`,{className:`text-[10px] rounded-full bg-amber-500/15 text-amber-700 dark:text-amber-300 px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,title:`System package — updating restarts the hub`,children:[D(j,{className:`h-3 w-3`}),`System`]}),p!=null&&D(Ce,{item:p}),l!=null&&D(xe,{progress:l})]}),K&&D(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:K}),!z&&e.process&&S(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[D(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.mode===`forked`?`bg-blue-500/15 text-blue-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.mode===`forked`?`forked`:`in-process`}),e.process.pid!=null&&S(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),D(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.state===`running`?`bg-emerald-500/15 text-emerald-400`:e.process.state===`crashed`||e.process.state===`failed`?`bg-red-500/15 text-red-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.state})]})]})]}),!z&&S(`div`,{className:`flex items-center gap-1 px-4 py-1.5 border-t border-border/50 bg-surface-hover/20`,children:[S(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),J.mutate({addonId:F.id})},disabled:J.isPending||m,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-blue-400 hover:border-blue-500/30 hover:bg-blue-500/10 disabled:opacity-50 transition-colors`,children:[D(j,{className:`h-3 w-3 ${J.isPending?`animate-spin`:``}`}),`Restart`]}),S(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),x(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${b?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[D(B,{className:`h-3 w-3`}),`Logs`]}),!z&&S(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),C(!0)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${le?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[D(me,{className:`h-3 w-3`}),`Settings`]}),D(`div`,{className:`flex-1`}),R&&S(`button`,{type:`button`,onClick:async e=>{e.stopPropagation(),await P({title:`Uninstall ${F.name}?`,message:`This will remove the addon package and all its data. This action cannot be undone.`,confirmLabel:`Uninstall`,variant:`danger`})&&q.mutate({packageName:F.packageName})},disabled:q.isPending||m,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-red-400 hover:border-red-500/30 hover:bg-red-500/10 disabled:opacity-50 transition-colors`,children:[D(ge,{className:`h-3 w-3`}),q.isPending?`Removing...`:`Uninstall`]})]}),r&&r.nodes.length>1&&!z&&S(`div`,{className:`border-t border-border px-4 py-2 bg-muted/10`,children:[D(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:`Cluster Deployment`}),D(`div`,{className:`space-y-1`,children:r.nodes.map(e=>S(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[D(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`offline`?`bg-muted-foreground/30`:e.synced?`bg-success`:`bg-amber-500`}`}),D(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),D(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&D(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20`,children:`outdated`}),e.status===`offline`&&D(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:`offline`}),e.synced&&e.status!==`offline`&&D(`span`,{className:`text-[9px] text-success`,children:`synced`})]},e.nodeId))})]}),b&&!z&&S(`div`,{className:`border-t border-border`,children:[S(`div`,{className:`flex items-center px-4 py-1 bg-surface-hover/20 border-b border-border/50`,children:[S(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[D(`button`,{type:`button`,onClick:()=>A(`logs`),className:`px-2 py-0.5 transition-colors ${k===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Logs`}),D(`button`,{type:`button`,onClick:()=>A(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${k===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Events`})]}),D(`div`,{className:`flex-1`}),D(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),x(!1)},className:`text-foreground-subtle hover:text-foreground`,children:D(he,{className:`h-3.5 w-3.5`})})]}),k===`logs`&&D(u,{addonId:F.id,maxHeight:`max-h-64`,showFilters:!1}),k===`events`&&D(ee,{addonId:F.id,category:`addon.*`,maxHeight:`max-h-64`})]}),z&&S(w,{children:[D(`button`,{type:`button`,onClick:()=>re(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:D(g?ve:I,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),g&&D(`div`,{className:`border-t border-border px-3 py-2 space-y-2`,children:d.addons.map(e=>D(ke,{addon:e,agents:t,hideVersion:!0},e.manifest.id))})]}),le&&!z&&D(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,onClick:()=>C(!1),children:S(`div`,{className:`w-full max-w-lg max-h-[80vh] rounded-xl border border-border bg-surface shadow-2xl flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[S(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0`,children:[S(`div`,{className:`flex items-center gap-2`,children:[D(me,{className:`h-4 w-4 text-primary`}),S(`h2`,{className:`text-sm font-semibold text-foreground`,children:[V,` Settings`]})]}),D(`button`,{onClick:()=>C(!1),className:`text-foreground-subtle hover:text-foreground transition-colors p-1 rounded`,children:D(he,{className:`h-4 w-4`})})]}),S(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-4`,children:[D(_e,{nodeId:`hub`,addonIds:[F.id],level:`global`}),Te(F)&&S(`div`,{children:[D(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Device export`}),D(oe,{addonId:F.id,trpc:N.trpcClient,onOpenDevice:e=>fe(`/devices/${e}`)})]}),G===`npm`&&S(`div`,{children:[D(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Auto-Update`}),D(Oe,{addonId:F.id})]}),F.components&&F.components.length>0&&S(`div`,{children:[S(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Components (`,F.components.length,`)`]}),D(`div`,{className:`flex flex-wrap gap-1`,children:F.components.map(e=>D(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]}),t.length>=2&&S(`div`,{children:[D(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Installed on`}),S(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[L.length===0&&D(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Hub (local)`}),L.map(e=>D(`span`,{className:`rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle`,children:e},e)),S(`div`,{className:`relative`,children:[S(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ie(e=>!e)},className:`inline-flex items-center gap-1 rounded-full border border-dashed border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:border-primary transition-colors`,title:`Install on more agents`,children:[D(de,{className:`h-3 w-3`}),`Add agent`]}),_&&S(`div`,{className:`absolute left-0 top-full mt-1 z-10 min-w-[160px] rounded-md border border-border bg-surface shadow-lg overflow-hidden`,children:[t.filter(e=>!e.isHub&&!L.includes(e.name)).map(e=>D(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ie(!1)},className:`w-full text-left px-3 py-1.5 text-[10px] text-foreground hover:bg-surface-hover transition-colors`,children:e.name},e.id)),t.filter(e=>!e.isHub&&!L.includes(e.name)).length===0&&D(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle`,children:`No available agents`})]})]})]})]})]}),D(`div`,{className:`flex items-center justify-end px-5 py-3 border-t border-border flex-shrink-0`,children:D(`button`,{type:`button`,onClick:()=>C(!1),className:`rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:`Close`})})]})})]})}x();var Ae=`.tgz,.tar.gz,.zip`;function je({onUploadSuccess:e}){let[t,n]=E(!1),r=b(null),i=y(async t=>{n(!0);let r=new FormData;r.append(`file`,t);let i=localStorage.getItem(`camstack_admin_token`)??``;try{(await(await fetch(`/api/addons/upload`,{method:`POST`,headers:{Authorization:`Bearer ${i}`},body:r})).json()).success&&e()}finally{n(!1)}},[e]);return S(w,{children:[D(`input`,{ref:r,type:`file`,accept:Ae,onChange:y(e=>{let t=e.target.files?.[0];t&&i(t),e.target.value=``},[i]),className:`hidden`}),S(`button`,{type:`button`,onClick:()=>r.current?.click(),disabled:t,className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[t?D(V,{className:`w-3.5 h-3.5 animate-spin`}):D(N,{className:`w-3.5 h-3.5`}),t?`Uploading...`:`Upload`]})]})}function Me({pending:e,onCancel:t,onConfirm:n,isPending:r,error:i}){return D(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,children:S(`div`,{className:`bg-surface border border-border rounded-md shadow-xl p-5 max-w-md w-full mx-4 space-y-3`,children:[S(`div`,{className:`flex items-center gap-2`,children:[D(z,{className:`w-4 h-4 text-amber-700`}),D(`h3`,{className:`text-sm font-medium text-foreground`,children:`Update system package?`})]}),S(`div`,{className:`space-y-2 text-[11px] text-foreground-subtle`,children:[S(`div`,{children:[D(`span`,{className:`font-mono text-foreground`,children:e.packageName}),D(`span`,{className:`mx-1`,children:`·`}),S(`span`,{className:`font-mono`,children:[`v`,e.fromVersion]}),D(`span`,{className:`mx-1`,children:`→`}),S(`span`,{className:`font-mono text-amber-700`,children:[`v`,e.toVersion]})]}),D(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 p-2 text-amber-800`,children:`The hub will restart immediately after the install. Any in-flight requests will be dropped. The reconnect typically takes ~10 seconds.`}),i!==null&&D(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-2 text-danger`,children:i})]}),S(`div`,{className:`flex justify-end gap-2 pt-1`,children:[D(`button`,{type:`button`,onClick:t,disabled:r,className:`px-3 py-1.5 text-[11px] rounded bg-surface hover:bg-surface-hover border border-border disabled:opacity-50`,children:`Cancel`}),S(`button`,{type:`button`,onClick:n,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] rounded bg-amber-500/20 text-amber-800 hover:bg-amber-500/30 border border-amber-500/40 font-medium disabled:opacity-50`,children:[r?D(V,{className:`w-3 h-3 animate-spin`}):D(A,{className:`w-3 h-3`}),`Update & restart`]})]})]})})}x();function Ne(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function Q(e){let t=e;if(!t?.manifest)return null;let n={...t.manifest,name:t.manifest.name??t.manifest.id,version:t.manifest.version??`0.0.0`,capabilities:t.manifest.capabilities??[]},r=t.process,i=r?{pid:r.pid,mode:r.mode===`forked`?`forked`:`in-process`,state:r.state??`unknown`}:void 0,a=t.health,o=t.declaration?.execution,s=t.manifest.execution,c=o?.placement??s?.placement;return{manifest:n,enabled:!0,source:t.source,installSource:t.installSource,installedOn:[],...i?{process:i}:{},hasBackup:t.hasBackup,...a?{health:a}:{},...c?{placement:c}:{}}}function Pe(e){let t=new Map,n=[];for(let r of e){let e=r.manifest.packageName;if(!e){n.push(r);continue}let i=t.get(e);if(i)i.addons.push(r);else{let n=r.manifest.bundle,i={packageName:e,displayName:n?.displayName??r.manifest.packageDisplayName??r.manifest.name,version:r.manifest.packageVersion,addons:[r],...r.installSource===void 0?{}:{installSource:r.installSource},...n===void 0?{}:{bundle:n}};t.set(e,i)}}let r=[];for(let e of t.values())e.bundle!==void 0||e.addons.length>=2?r.push({bundle:e,representative:e.addons[0]}):r.push(e.addons[0]);return r.push(...n),r}function $(e){return`bundle`in e}function Fe({addons:t,clusterStatus:r,selectedNode:i,onRefresh:a,isRefreshing:o}){let l=T(),[u,f]=E(``),ee=le(u),[h,ne]=E(!1),g=b(null);O(()=>{if(!h)return;let e=e=>{g.current&&!g.current.contains(e.target)&&ne(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[h]);let{data:_}=s({nodeId:i.id}),ie=C(()=>{let e=new Map;for(let t of _??[])e.set(t.name,t.latestVersion);return e},[_]),[ae,oe]=E(()=>new Set),[se,x]=E(()=>new Map),w=y(e=>{oe(t=>new Set(t).add(e))},[]),ue=y(e=>{oe(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),k=y((e,t)=>{x(n=>new Map(n).set(e,t))},[]),de=y(e=>{x(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),N=e({onMutate:e=>{w(e.name),de(e.name)},onSuccess:(e,t)=>{ue(t.name);let n=e;if(n&&n.success===!1){k(t.name,n.error??`Update failed (no error message returned by server)`);return}l.invalidateQueries({queryKey:[[`addons`]]}),l.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{ue(t.name),k(t.name,e instanceof Error?e.message:String(e))}}),I=be(),pe=b(new Set);O(()=>{let e=new Set;for(let[t,n]of I)J(n)&&e.add(t);let t=[...pe.current].some(t=>!e.has(t));pe.current=e,t&&(l.invalidateQueries({queryKey:[[`addons`]]}),l.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[I,l]);let{data:L}=re(void 0),me=c({onSuccess:()=>{l.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:R,isFetching:he}=d({query:ee||void 0},{enabled:h}),z=ce(),{data:B}=p(void 0),ge=B?.requestedAt,[H,_e]=E(null),[ve,U]=E(!1);O(()=>{if(B?.kind===`framework-bulk-update`&&B.requestedAt!==H){_e(B.requestedAt),U(!0);let e=window.setTimeout(()=>U(!1),6e3);return()=>window.clearTimeout(e)}},[ge,H,B]);let{data:W}=m(void 0),ye=C(()=>new Map((W??[]).map(e=>[e.packageName,e])),[W]),[G,K]=E(null),[q,Y]=E(null),X=v({onSuccess:()=>{K(null),l.invalidateQueries({queryKey:[[`addons`]]})},onError:e=>{Y(e instanceof Error?e.message:String(e))}}),xe=n(),Se=y(async()=>{let e=_??[];e.length!==0&&(e.some(e=>e.isSystem)&&!await xe({title:`Update all — includes a system package`,message:`This batch updates a system package (@camstack/system). The hub will restart automatically once the framework update completes. In-flight requests are dropped; reconnect typically takes ~10 seconds.`,confirmLabel:`Update all & restart`,variant:`warning`})||await z.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[i.id]}))},[_,i.id,z,xe]),Z=te({onSuccess:()=>{l.invalidateQueries({queryKey:[[`addons`]]}),l.invalidateQueries({queryKey:[[`addonPages`]]}),l.invalidateQueries({queryKey:[[`capabilities`]]}),l.invalidateQueries({queryKey:[[`integrations`]]})}}),[Ce,we]=E(`type`),[Te,Ee]=E(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),De=e=>{Ee(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[Oe,Ae]=F(),Q=Oe.get(`capability`),Fe=C(()=>{let e=i.isHub?t:t.filter(e=>Ne(e.placement,i.isHub));return Q&&(e=e.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===Q))),e},[t,i.isHub,Q]),Ie=()=>{let e=new URLSearchParams(Oe);e.delete(`capability`),Ae(e,{replace:!0})},Le=Te===`flat`?Fe:Pe(Fe),Re=C(()=>{let e=[...Le];switch(Ce){case`type`:e.sort((e,t)=>{let n=+!$(e),r=+!$(t);if(n!==r)return n-r;let i=$(e)?e.bundle.displayName:e.manifest.name,a=$(t)?t.bundle.displayName:t.manifest.name;return i.localeCompare(a)});break;case`name`:e.sort((e,t)=>{let n=$(e)?e.bundle.displayName:e.manifest.name,r=$(t)?t.bundle.displayName:t.manifest.name;return n.localeCompare(r)});break;case`source`:e.sort((e,t)=>{let n=$(e)?e.bundle.installSource??``:e.installSource??``,r=$(t)?t.bundle.installSource??``:t.installSource??``;return n.localeCompare(r)});break}return e},[Le,Ce]);return S(`div`,{className:`space-y-4`,children:[[...se.entries()].map(([e,t])=>D(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px]`,children:S(`div`,{className:`flex items-start justify-between gap-3`,children:[S(`div`,{className:`space-y-0.5`,children:[S(`div`,{className:`font-medium text-danger`,children:[`Failed to update `,e]}),D(`div`,{className:`text-foreground-subtle font-mono`,children:t})]}),D(`button`,{type:`button`,onClick:()=>de(e),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:`dismiss`})]})},e)),S(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[S(`div`,{className:`flex items-center gap-1.5`,children:[D(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Sort:`}),S(`select`,{value:Ce,onChange:e=>we(e.target.value),className:`rounded-md border border-border bg-surface px-2 py-1.5 text-[11px] text-foreground focus:outline-none focus:border-primary/50`,children:[D(`option`,{value:`type`,children:`Bundles first`}),D(`option`,{value:`name`,children:`Name`}),D(`option`,{value:`source`,children:`Install source`})]})]}),S(`div`,{className:`flex items-center gap-1.5`,children:[D(`span`,{className:`text-[10px] text-foreground-subtle`,children:`View:`}),D(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>D(`button`,{type:`button`,onClick:()=>De(e),className:`px-2.5 py-1.5 transition-colors capitalize ${Te===e?`bg-primary/10 text-primary`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`}`,title:e===`grouped`?`Group multi-addon packages into a bundle card`:`Show every addon as its own card`,children:e},e))})]}),i.isHub&&S(`div`,{className:`flex items-center gap-1.5`,children:[D(j,{className:`h-3 w-3 text-foreground-subtle`}),D(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Auto-Update:`}),D(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>D(`button`,{type:`button`,onClick:()=>me.mutate({channel:e}),disabled:me.isPending,className:`px-2.5 py-1.5 transition-colors capitalize ${L?.channel===e?e===`off`?`bg-gray-700 text-gray-200`:e===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${e===`off`?``:`border-l border-border`}`,children:e},e))})]}),(_?.length??0)>0&&S(`button`,{type:`button`,onClick:()=>void Se(),disabled:z.isPending,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 border border-blue-500/30 disabled:opacity-50 transition-colors font-medium`,children:[z.isPending?D(V,{className:`w-3 h-3 animate-spin`}):D(A,{className:`w-3 h-3`}),z.isPending?`Updating…`:`Update All (${_.length})`]}),S(`button`,{type:`button`,onClick:a,disabled:o||z.isPending,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[D(j,{className:`w-3 h-3 ${o?`animate-spin`:``}`}),`Refresh`]})]}),S(`div`,{className:`flex items-center gap-3`,children:[S(`div`,{className:`relative flex-1 min-w-[200px]`,ref:g,children:[D(M,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),D(`input`,{type:`text`,value:u,onChange:e=>{f(e.target.value),ne(!0)},onFocus:()=>ne(!0),placeholder:`Search addons on npm...`,disabled:z.isPending,className:`w-full rounded-lg border border-border bg-background pl-9 pr-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-50 disabled:cursor-not-allowed`}),he&&D(V,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin`}),h&&R&&R.length>0&&S(`div`,{className:`absolute left-0 right-0 top-full mt-1 z-40 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,children:[R.length>0&&S(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[`npm results (`,R.length,`)`]}),R&&R.length>0&&D(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:R.map(e=>S(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[D(`div`,{className:`w-6 h-6 rounded-md bg-primary/10 flex items-center justify-center text-primary text-[9px] font-bold shrink-0`,children:e.name.replace(`@camstack/addon-`,``).charAt(0).toUpperCase()}),S(`div`,{className:`flex-1 min-w-0`,children:[S(`div`,{className:`flex items-center gap-2`,children:[D(`span`,{className:`text-[11px] font-semibold truncate`,children:e.name}),S(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`v`,e.version]})]}),e.description&&D(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?S(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md border border-emerald-500/30 bg-emerald-500/10 text-emerald-400 shrink-0`,children:[D(P,{className:`h-3 w-3`}),e.installedVersion??`Installed`]}):S(`button`,{type:`button`,onClick:()=>Z.mutate({packageName:e.name}),disabled:Z.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[Z.isPending?D(V,{className:`h-3 w-3 animate-spin`}):D(A,{className:`h-3 w-3`}),`Install`]})]},e.name))})]})]}),D(je,{onUploadSuccess:()=>{l.invalidateQueries({queryKey:[[`addons`]]}),a()}})]}),Q&&S(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-primary/10 border border-primary/30 text-sm`,children:[D(`span`,{className:`text-foreground-subtle`,children:`Filtering by capability:`}),D(`span`,{className:`font-mono text-primary font-semibold`,children:Q}),D(`button`,{type:`button`,onClick:Ie,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:`Clear`})]}),ve&&S(`div`,{className:`fixed top-4 right-4 z-50 flex items-start gap-2 px-3 py-2.5 rounded-md border border-green-500/30 bg-green-500/10 shadow-lg backdrop-blur-sm max-w-sm pointer-events-auto`,children:[D(fe,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),S(`div`,{children:[D(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Bulk update completed`}),D(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`System packages updated — hub restarted successfully.`})]})]}),Fe.length===0&&D(`div`,{className:`text-xs text-foreground-subtle`,children:t.length===0?`No addons installed`:Q?`No installed addons declare the "${Q}" capability. Browse the npm catalog above to find a compatible addon.`:`No addons compatible with ${i.name} (placement filter active)`}),D(`div`,{className:`space-y-2`,children:Re.map(e=>{let t=$(e)?e.bundle.packageName:e.manifest.packageName,n=ie.get(t),a=$(e)?e.representative:e,o=ye.has(t),s=n?o?e=>K({packageName:t,fromVersion:ye.get(t)?.currentVersion??a.manifest.packageVersion??a.manifest.version,toVersion:e}):e=>N.mutate({name:t,version:e,nodeId:i.id}):void 0,c=I.get(t)??null,l=c!==null&&J(c);return D(ke,{addon:a,clusterStatus:r?.[a.manifest.id],bundle:$(e)?e.bundle:void 0,availableUpdate:n,isUpdating:ae.has(t)||l,jobProgress:c,onUpdate:s,isSystem:o,disabledByBulk:z.isPending},$(e)?t:e.manifest.id)})}),G!==null&&D(Me,{pending:G,onCancel:()=>{K(null),Y(null)},onConfirm:()=>{Y(null),X.mutate({packageName:G.packageName,version:G.toVersion})},isPending:X.isPending,error:q})]})}function Ie(){let e=T(),{data:n,isLoading:r,isError:i}=_(),{data:a}=se(void 0),{data:o}=t(void 0,{refetchInterval:1e4}),s=C(()=>{let e=new Map;e.set(`hub`,{id:`hub`,name:`Hub`,isHub:!0});for(let t of o??[]){let n=String(t.id??``);n&&e.set(n,{id:n,name:String(t.name??n),isHub:!!t.isHub})}return[...e.values()]},[o]),[c,u]=E(`hub`),d=s.find(e=>e.id===c)??s[0],f=ie(),p=l(),m=f.isPending||p.isPending,ee=async()=>{await f.mutateAsync({nodeId:c}),await p.mutateAsync(),e.invalidateQueries({queryKey:[[`addons`]]})},h=b(f);h.current=f,O(()=>{h.current.mutate({nodeId:`hub`})},[]);let te=(n??[]).map(Q).filter(e=>e!==null);return S(H,{children:[S(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[D(g,{selectedNodeId:c,onSelect:u}),S(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[!r&&!i&&S(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:[te.length,` installed`]}),S(`button`,{type:`button`,onClick:()=>void ee(),disabled:m,className:`inline-flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,title:`Re-fetch addons + check npm for new versions`,children:[D(j,{className:`w-3 h-3 ${m?`animate-spin`:``}`}),`Check for updates`]})]})]}),!d.isHub&&S(`div`,{className:`rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-[11px] text-foreground-subtle`,children:[`Showing only addons compatible with`,` `,D(`span`,{className:`font-medium text-foreground`,children:d.name}),` — agents only run`,` `,D(`code`,{className:`font-mono`,children:`agent-only`}),` and`,` `,D(`code`,{className:`font-mono`,children:`any-node`}),` addons. Install / uninstall is hub-driven; agents auto-sync from the hub.`]}),r&&D(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading…`}),i&&D(`div`,{className:`text-xs text-danger`,children:`Failed to load addons`}),!r&&!i&&D(Fe,{addons:te,clusterStatus:a,selectedNode:d,onRefresh:()=>void ee(),isRefreshing:m})]})}export{Ie as AddonsPage};
@@ -1,2 +0,0 @@
1
- import{An as e,Ar as t,B as n,Bi as r,Cn as i,D as a,Dn as o,E as s,En as c,G as l,J as u,Jn as d,Jr as f,K as p,M as m,N as h,O as g,Oa as _,On as v,R as y,Ri as b,T as x,Tn as S,U as C,Ur as w,W as T,Wi as E,Xr as ee,Xt as D,Y as O,Zt as k,_n as te,a as ne,aa as re,bi as A,bn as j,ca as ie,di as ae,dn as oe,ea as se,er as ce,f as M,fn as N,g as P,gn as le,hn as F,i as I,ia as ue,ii as de,in as fe,j as pe,jn as me,ka as he,kn as ge,kt as _e,l as ve,m as ye,n as be,na as L,nr as xe,o as Se,on as Ce,p as we,pi as Te,pt as Ee,q as De,r as Oe,ta as ke,tr as Ae,u as je,vn as Me,vr as Ne,wn as R,y as Pe,yi as Fe,yn as Ie,z as Le,zi as Re,zr as ze}from"./src-BVMxsNe8.js";import{I as z,K as B,Q as V,S as H,W as U,b as Be,o as W,q as G,t as Ve,x as K,z as q}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{c as He,k as Ue,p as J,r as We,t as Ge,u as Ke}from"./player-overlays-BH6aBUe-.js";import{C as qe,E as Je,b as Y,g as Ye,v as Xe}from"./src-CCmaAR6i.js";import{t as Ze}from"./CapabilityBadges-uN4xnNt9.js";import{n as Qe,t as $e}from"./rotate-ccw-D6a6yNNE.js";import{t as et}from"./ProviderIcon-BVyDFfZQ.js";import{t as tt}from"./pencil-D4eE6uEV.js";import{t as nt}from"./plus-CDeS7IvC.js";import{t as rt}from"./refresh-cw-DCVnt6DS.js";import{t as it}from"./rotate-cw-BZnE1cAg.js";import{t as at}from"./server-DglCnPiH.js";import{t as ot}from"./wifi-TvDBvENo.js";import{B as st,F as ct,G as lt,I as ut,O as dt,R as ft,U as pt,V as X,W as mt,_ as ht,a as gt,c as _t,i as vt,k as yt,p as bt,r as xt,s as St,t as Ct,v as wt,x as Tt}from"./index-DjbbJhB4.js";import{n as Et,t as Dt}from"./useDevice-CAq7iz29.js";import{t as Ot}from"./StatusBadge-Dcr2bw58.js";import{t as kt}from"./useEventInvalidation-B-rUQp_C.js";import{n as At,r as jt,t as Mt}from"./SchemaTabBar-Lx0lVN3x.js";import{t as Nt}from"./FormBuilder-CegbdtFO.js";var Pt=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`}]]),Ft=X(`layers`,[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]]),It=X(`link-2-off`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7`,key:`10o201`}],[`path`,{d:`M15 7h2a5 5 0 0 1 4 8`,key:`1d3206`}],[`line`,{x1:`8`,x2:`12`,y1:`12`,y2:`12`,key:`rvw6j4`}],[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}]]),Lt=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`}]]),Rt=X(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]),zt=X(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),Bt=X(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),Vt=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`}]]);V();function Ht({parentDeviceId:e}){let{t}=Ct(),n=pt(),r=J(),{data:i,isLoading:a,isError:o}=Et(e),{data:s}=F({deviceId:e},{enabled:Number.isFinite(e)});if(a)return K(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:K(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(o)return K(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:K(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let c=i??[];if(c.length===0)return null;let u=T(s?.stableId??``,c,s?.childLayout),d=u.ungrouped,f=e=>n(`/devices/${String(e)}`),p=s?.name??``,m=e=>{let t=`${p} `;return p.length>0&&e.startsWith(t)?e.slice(t.length):e},h=(e,t)=>K(C,{trpc:r.trpcClient,device:{...t,name:m(t.name)},variant:`minimal`,onNavigate:f},e),g=d.some(e=>!!e.role),_=d.some(e=>!e.role),v=g&&!_?t(`device.accessories`,{defaultValue:`Accessories`}):!g&&_?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),y=d.length>0?H(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[K(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:v}),K(`div`,{className:`space-y-1`,children:d.map(e=>h(e.id,e))})]}):null,b=u.disabledSection===void 0?null:K(l,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:u.disabledSection.children.length,defaultOpen:!1,children:K(`div`,{className:`opacity-60 space-y-1`,children:u.disabledSection.children.map(e=>h(e.id,e))})},u.disabledSection.title);return u.sections.length===0?b===null?y:H(`div`,{className:`space-y-2`,children:[y,b]}):H(`div`,{className:`space-y-2`,children:[u.sections.map(e=>K(l,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>h(e.id,e))},e.title)),y,b]})}function Ut({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){return H(`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:[K(et,{type:n,size:`lg`}),H(`div`,{children:[K(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),K(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),H(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[K(Ot,{status:r?`online`:`offline`}),i.length>0&&K(Ze,{capabilities:i})]}),K(`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.`})]})}function Wt({deviceId:e}){let t=W(),n=D({deviceId:e},{refetchInterval:1e4,retry:!1}),r=k({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=U(()=>Gt(n.data??[]),[n.data]);return H(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[H(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[K(Kt,{label:`Discovered`,value:i.total,icon:K(ht,{className:`h-3.5 w-3.5`})}),K(Kt,{label:`Adopted`,value:i.adopted,accent:`success`}),K(Kt,{label:`Available`,value:i.available,accent:i.available>0?`primary`:void 0}),H(`button`,{type:`button`,onClick:()=>{r.mutateAsync({deviceId:e}).catch(()=>{})},disabled:r.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:[r.isPending?K(Tt,{className:`h-3.5 w-3.5 animate-spin`}):K(rt,{className:`h-3.5 w-3.5`}),K(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),H(`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:[K(qt,{icon:K(ot,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),K(qt,{icon:K(wt,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),K(qt,{icon:K(gt,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?K(qt,{icon:K(Pt,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function Gt(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 Kt({label:e,value:t,icon:n,accent:r}){return H(`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 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[H(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,K(`span`,{className:`truncate`,children:e})]}),K(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function qt({icon:e,label:t}){return H(`span`,{className:`inline-flex items-center gap-1`,children:[e,K(`span`,{children:t})]})}function Jt({deviceId:e,features:t}){return K(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:K(Re,{trpc:J().trpcClient,deviceId:e,features:t})})}function Yt({deviceId:e,features:t}){return K(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:K(b,{trpc:J().trpcClient,deviceId:e,features:t})})}function Z({deviceId:e,deviceType:t,features:r}){let i=J(),a=O(t)?.HeroCard??b,o=Ke(He(i.trpcClient,e)?.state.deviceStatus),s=o!==void 0&&o.online===!1,c=s?o.lastChangedAt:null;return H(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[s?K(`div`,{className:`flex justify-center`,children:K(n,{lastChangedAt:c})}):null,K(a,{trpc:i.trpcClient,deviceId:e,features:r})]})}function Xt({deviceId:e}){let t=J(),{data:n,isLoading:r}=Dt(e),{data:i,isLoading:a}=Et(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?K(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):K(`div`,{className:`flex h-full w-full flex-col`,children:K(Le,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}var Zt={[Y.Switch]:Z,[Y.Siren]:Z,[Y.Light]:Z,[Y.Sensor]:Z,[Y.Button]:Z,[Y.Hub]:Wt,[Y.Cover]:Jt,[Y.Valve]:Z,[Y.Humidifier]:Z,[Y.WaterHeater]:Z,[Y.Container]:Xt,[Y.Lock]:Z,[Y.Fan]:Z,[Y.Thermostat]:Z,[Y.Climate]:Z,[Y.MediaPlayer]:Z,[Y.Control]:Z,[Y.AlarmPanel]:Yt,[Y.EventEmitter]:Yt,[Y.Notifier]:Yt,[Y.Script]:Yt,[Y.Automation]:Yt,[Y.Presence]:Z,[Y.Update]:Z,[Y.Vacuum]:Z,[Y.LawnMower]:Z,[Y.Weather]:Z,[Y.Image]:Z};function Qt(e){return K(Zt[e.deviceType]??Ut,{...e})}function $t(e){return ne(J().trpcClient,e)}V();function en(e){let[t,n]=G(`idle`),[r,i]=G(null),a=B(null),o=B(null),s=B(null),c=B(!0),l=Ae(),u=ce(),d=xe(),f=z(()=>{if(a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null},[]),p=z(async()=>{if(t===`idle`)return;n(`stopping`);let r=s.current;if(r&&e!==null)try{await Promise.race([d.mutateAsync({deviceId:e,sessionId:r}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}f(),c.current&&(n(`idle`),i(null))},[t,e,d,f]),m=z(async()=>{if(e===null||t!==`idle`&&t!==`error`)return;i(null);let r=null,f=null,m=null;try{n(`requesting-mic`),r=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),o.current=r,n(`starting`);let t=await l.mutateAsync({deviceId:e});m=t.sessionId,s.current=m,n(`connecting`),f=new RTCPeerConnection,a.current=f,f.oniceconnectionstatechange=()=>{if(!c.current)return;let e=f.iceConnectionState;e===`connected`||e===`completed`?n(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&c.current&&(i(e===`failed`?`WebRTC connection failed`:null),p())};for(let e of r.getAudioTracks())f.addTrack(e,r);await f.setRemoteDescription({type:`offer`,sdp:t.sdpOffer});let d=await f.createAnswer();await f.setLocalDescription(d);let h=f.localDescription?.sdp??d.sdp??``;await u.mutateAsync({deviceId:e,sessionId:m,sdpAnswer:h})}catch(t){let l=t instanceof Error?t.message:String(t);if(console.warn(`[intercom] start failed`,t),f)try{f.close()}catch{}if(r)for(let e of r.getTracks())try{e.stop()}catch{}if(a.current=null,o.current=null,m!==null)try{await d.mutateAsync({deviceId:e,sessionId:m})}catch{}s.current=null,c.current&&(i(l),n(`error`))}},[e,t,l,u,d,p]);return q(()=>(c.current=!0,()=>{c.current=!1;let t=s.current;if(t!==null&&e!==null&&d.mutate({deviceId:e,sessionId:t}),a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null}),[e]),{state:t,error:r,start:m,stop:p,isTalking:t===`talking`}}V();var tn=0;function Q(){return++tn}function nn(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function rn(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 an(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 on(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 sn({scope:e,greeting:t,className:n}){let r=J(),[i,a]=G(()=>{let n=[];return t&&n.push({id:Q(),kind:`info`,text:t}),n.push({id:Q(),kind:`info`,text:`scope: ${nn(e)} — type help or context for available commands`}),n}),[o,s]=G(``),[c,l]=G([]),[u,d]=G(-1),f=B(null),p=B(null);q(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=z(()=>{f.current?.focus()},[]),h=Ve({mutationFn:t=>r.trpcClient.repl.execute.mutate({code:t,scope:e}),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`;a(e=>[...e,{id:Q(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);a(e=>[...e,{id:Q(),kind:`error`,text:t}])}});function g(t){let n=t.trim();if(n){if(n===`clear`){a([{id:Q(),kind:`info`,text:`scope: ${nn(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...rn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...on(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...an(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}l(e=>[...e,n]),d(-1),a(e=>[...e,{id:Q(),kind:`input`,text:`> ${n}`}]),s(``),h.mutate(n)}}function _(t){if(t.key===`Enter`){t.preventDefault(),g(o);return}if(t.key===`ArrowUp`){if(t.preventDefault(),c.length===0)return;let e=u===-1?c.length-1:Math.max(0,u-1);d(e),s(c[e]??``);return}if(t.key===`ArrowDown`){if(t.preventDefault(),u===-1)return;let e=u+1;e>=c.length?(d(-1),s(``)):(d(e),s(c[e]??``));return}t.ctrlKey&&t.key===`l`&&(t.preventDefault(),a([{id:Q(),kind:`info`,text:`scope: ${nn(e)}`}]))}let v={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return H(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??``}`,onClick:m,children:[H(`div`,{ref:p,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[i.map(e=>K(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&K(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),H(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[K(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),K(`input`,{ref:f,value:o,onChange:e=>s(e.target.value),onKeyDown:_,disabled:h.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 cn({deviceId:e,intercomAvailable:t=!1}){let n=J(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=$t(i?e:null),{streams:o,pipelineMetrics:s,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h}=I(n.trpcClient,i?e:null),_=De(n.trpcClient,i?e:null),v=en(i&&t?e:null),y=v.state===`requesting-mic`||v.state===`starting`||v.state===`connecting`||v.state===`stopping`,b=v.isTalking||y,x=()=>{v.state===`idle`||v.state===`error`?v.start():v.state!==`stopping`&&v.stop()},S=We(),C=g(),w=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,T=S.length>0?K(Be,{children:S.map(e=>K(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return K(Pe,{serverUrl:r,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h,...C.request?{playbackUrl:C.request.url,playbackAuthToken:w,...C.request.label?{playbackLabel:C.request.label}:{},onExitPlayback:()=>C.clear()}:{},streams:o,pipelineMetrics:s,phase:a.phase,detections:a,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:_.src,..._.src?{posterUrl:_.src}:{},snapshotLoading:_.loading,onRefreshSnapshot:_.refresh,intercomAvailable:t,intercomShown:b,onIntercomToggle:x,extraOverlay:T,chromeless:!0,className:`h-full`})}function ln({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full`,children:K(P,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function un({deviceId:e}){if(!Number.isFinite(e))return H(`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 K(sn,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function dn({deviceId:e}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:K(ye,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function fn({deviceId:e}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:K(M,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function pn({deviceId:e}){let t=W(),n=Number.isFinite(e),{data:r}=F({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;kt([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:a,isLoading:o,isError:s,error:c}=N({deviceId:e},{enabled:n}),{data:l}=Ie({deviceType:i},{enabled:!!i}),u=ge({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(o)return K(`div`,{className:`p-4`,children:K(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(s)return H(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,c instanceof Error?c.message:String(c)]});let d=new Map,f={};for(let e of l??[])f[e.capName]=e.wrappers;for(let e of a?.entries??[])d.set(e.capName,{...e,wrappers:f[e.capName]??[]});for(let e of l??[])d.has(e.capName)||d.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let p=[...d.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(p.length===0)return H(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[K(Qe,{className:`h-8 w-8 opacity-40`}),K(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),K(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let m=p.filter(e=>e.kind!==`unbound`).length;return H(`div`,{className:`flex flex-col gap-3 p-1`,children:[H(`div`,{className:`text-[11px] text-foreground-subtle`,children:[K(`span`,{className:`font-medium text-foreground`,children:m}),` of `,p.length,` capabilit`,p.length===1?`y`:`ies`,` bound — rows marked `,K(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),K(ue,{columns:[{key:`capability`,header:`Capability`,render:e=>K(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>K(mn,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>K(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||K(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?K(hn,{nodeId:e.providerNodeId}):K(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>K(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||K(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return K(gn,{wrappers:t.wrappers,activeWrapperId:n,disabled:u.isPending,onPick:r=>{let i=n===r;u.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:p,rowKey:e=>e.capName,minWidthPx:720})]})}function mn({kind:e}){return e===`native`?H(`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:[K(at,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?H(`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:[K(Ft,{className:`h-3 w-3`}),`wrapped`]}):e===`linked`?H(`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:[K(Lt,{className:`h-3 w-3`}),`linked`]}):H(`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:[K(zt,{className:`h-3 w-3`}),`unbound`]})}function hn({nodeId:e}){return K(`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 gn({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?K(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):K(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let i=e===t;return H(`button`,{disabled:n,onClick:()=>r(e),title:i?`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 ${i?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[K(i?ct:$e,{className:`h-3 w-3`}),e]},e)})})}V();function _n({schema:e,values:t,pendingKeys:n,onChange:r,onAction:i,onSave:a,onDiscard:o,disabled:s,activeSubTab:c,onSubTabChange:l,flattenTabs:u=!1}){let d=e.tabs??[],f=U(()=>{let t=new Map;for(let n of e.sections){let e=n.tab??`general`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t},[e.sections]),p=new Set(d.map(e=>e.id)),m=[...d,...[...f.keys()].filter(e=>!p.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],h=m[0]?.id??`general`,[g,_]=G(h),v=l!==void 0,y=new Set(m.map(e=>e.id)),b=v?c&&y.has(c)?c:h:y.has(g)?g:h,x=e=>{v?l(e):_(e)},S=f.get(b)??[],C={sections:S.length<=1?S.length===1?[{...S[0],title:``}]:S:S.every(e=>!e.title)?[{...S[0],title:``,fields:S.flatMap(e=>e.fields)}]:S},w=K(At,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:s});if(u||m.length<=1)return H(`div`,{className:`flex flex-col gap-3`,children:[K(Nt,{schema:e,values:t,onChange:r,onAction:i,disabled:s}),w]});let T=new Map,E=new Map;for(let[e,t]of f){T.set(e,t.length);let r=new Set,i=e=>{for(let t of e)if(`key`in t&&typeof t.key==`string`&&r.add(t.key),t.type===`group`)i(t.fields);else if(t.type===`sub-tabs`)for(let e of t.tabs)i(e.fields)};for(let e of t)i(e.fields);let a=n.filter(e=>r.has(e)).length;a>0&&E.set(e,a)}return H(`div`,{className:`flex flex-col gap-3`,children:[K(Mt,{tabs:m.map(e=>({id:e.id,label:e.label})),activeId:b,onChange:x,countByTab:T,pendingByTab:E}),K(Nt,{schema:C,values:t,onChange:r,onAction:i,disabled:s}),w]})}var vn=`device-export`,yn=`export`,bn=`Export`;function xn(e){return e.type===`separator`||e.type===`info`||e.type===`object-array`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`?!1:e.type===`group`?e.fields.some(xn):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(xn)):e.writerCapName===vn}function Sn(e){return e.fields.some(xn)}V();function Cn(e,t){return t&&t===`admin`?e:!0}function wn(e){if(!e)return null;let t={sections:[...e.sections].toSorted((e,t)=>{let n=e.tab??`general`,r=t.tab??`general`;return n===r?Sn(e)&&Sn(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function Tn(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`}function En(e){return e.key}function Dn(e){if(!Tn(e))return e.value}function On(e){return Tn(e)?null:e}function kn(e,t){for(let n of e)if(t(n),n.type===`group`)kn(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)kn(e.fields,t)}function An(e){if(!e)return{};let t={};for(let n of e.sections)kn(n.fields,e=>{let n=En(e);n!==null&&(t[n]=Dn(e))});return t}function jn(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(kn(r.fields,e=>{if(n!==null||En(e)!==t)return;let r=On(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function Mn(e){return{...e,fields:e.fields.map(Nn)}}function Nn(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function Pn(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=On(e);return n?Cn(t,n.minRole)?e:Nn(e):e})}))}}function Fn({deviceId:t,sectionFilter:n,activeSubTab:r,onSubTabChange:i,flattenSubTabs:a}){let o=W(),{user:s}=xt(),c=s?.isAdmin===!0,l=B(!1),{data:u,isLoading:d}=le({deviceId:t},{refetchInterval:()=>l.current?!1:2500,enabled:Number.isFinite(t)}),{data:f}=F({deviceId:t},{enabled:Number.isFinite(t)}),p=u?.settings??null,m=u?.live??null,h=U(()=>{if(!p&&!m)return null;let e=p?.sections??[],t=(m?.sections??[]).map(Mn),r=[...e,...t],i=n?r.filter(n):r.filter(e=>e.location!==`top-tab`&&!Sn(e));if(i.length===0)return null;let a=new Set;for(let e of i)a.add(e.tab??`general`);let o=[...p?.tabs??[],...(m?.tabs??[]).filter(e=>!(p?.tabs??[]).some(t=>t.id===e.id))].filter(e=>a.has(e.id));return o.length>0?{tabs:o,sections:i}:{sections:i}},[p,m,n]),g=U(()=>wn(h),[h]),_=U(()=>Pn(g,c),[g,c]),v=U(()=>An(_),[_]),y=A(),b=Fe(),x=e(),S=R(),C=me({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),w={isPending:C.isPending,mutate:e=>{C.mutate({deviceId:t,changes:[...e]})}},T=jt({schema:_,serverValues:v,onImmediateSave:z(e=>{let t=Object.entries(e).map(([e,t])=>{let n=jn(_,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&w.mutate(t)},[_,w]),onDeferredSave:z(e=>{let t=Object.entries(e).map(([e,t])=>{let n=jn(_,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&w.mutate(t)},[_,w])}),{values:E,pendingKeys:ee,handleChange:D,handleSave:O,handleDiscard:k}=T;if(l.current=T.editingPaused,d)return H(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[K(Tt,{className:`h-4 w-4 animate-spin mr-2`}),K(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!_||_.sections.length===0)return K(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:`No aggregate contributions for this device.`});async function te(e,n,r){if(e===`regenerate-rtsp-token`){let e=[`rtspUrl:`,`regenerateToken:`].find(e=>n.startsWith(e));if(!e)throw Error(`regenerate-rtsp-token: unrecognised key "${n}" (expected "rtspUrl:<streamId>" or "regenerateToken:<streamId>")`);let r=n.slice(e.length);if(!r)throw Error(`regenerate-rtsp-token: key "${n}" has no streamId after prefix`);let i=qe(t,r);await y.mutateAsync({brokerId:i}),o.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(e===`test-probe`){if(!f)return{status:`error`,error:`Device metadata not loaded yet`};try{return await x.mutateAsync({addonId:f.addonId,type:f.type,key:n,value:r})}catch(e){return{status:`error`,error:e instanceof Error?e.message:String(e)}}}if(e===`refresh-probe`){if(!n.startsWith(`probedInfo:`))throw Error(`refresh-probe: unrecognised key "${n}" (expected "probedInfo:<streamId>")`);let e=n.slice(11);if(!e)throw Error(`refresh-probe: key "${n}" has no streamId after prefix`);let r=qe(t,e),i=await b.mutateAsync({brokerId:r});return o.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),i}if(e===`device-custom-action`){let e=await S.mutateAsync({deviceId:t,action:n,input:r});return o.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),e}throw Error(`[device-aggregate] unknown action "${e}"`)}return K(_n,{schema:_,values:E,pendingKeys:ee,onChange:D,onAction:te,onSave:O,onDiscard:k,disabled:w.isPending,activeSubTab:r,onSubTabChange:i,flattenTabs:a})}function In({deviceId:e,activeSubTab:t,onSubTabChange:n}){return K(`div`,{className:`flex flex-col gap-3`,children:K(Fn,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}V();function Ln(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 Rn(e,t,n){let r=e?.stepOverridesByAgent?.[t]?.[n];if(r)return r.enabled===!1?`off`:(r.enabled,`on`);let i=e?.stepToggles?.[n];return i===!1?`off`:i===!0?`on`:`inherit`}function zn({agents:e,currentAgent:t,onPick:n}){let[r,i]=G(!1);return H(`div`,{className:`relative`,children:[K(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>i(e=>!e),children:`Mirror from ▾`}),r&&K(`div`,{className:`absolute top-full left-0 mt-1 min-w-[140px] bg-surface border border-border rounded shadow-lg z-10`,children:e.filter(e=>e!==t).map(e=>K(`button`,{type:`button`,className:`w-full text-left px-3 py-1.5 text-xs hover:bg-muted`,onClick:()=>{i(!1),n(e)},children:e},e))})]})}function Bn({deviceId:e,refreshToken:n}){let r=W(),[i,a]=G(null),[o,s]=G(null),[c,l]=G(null),[u,d]=G(null),p=w({deviceId:e}),m=ee(),h=f({deviceId:e}),g=ze(),_=U(()=>h.data?.agentNodeId||g.data?.find(e=>e.online)?.nodeId||`hub`,[h.data?.agentNodeId,g.data]),v=o??_,y=t({nodeId:v??``},{enabled:!!v}),b=de({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),l(null)}}),x=U(()=>y.data?L(y.data):[],[y.data]),S=U(()=>{let e=p.data??null,t={};for(let n of m.data??[])for(let r of Object.keys(n.settings.addonDefaults)){let i=t[r]??[];i.push({agentNodeId:n.nodeId,state:Rn(e,n.nodeId,r)}),t[r]=i}return t},[p.data,m.data]),C=i?Ln(y.data??null,i):null,T=v?m.data?.find(e=>e.nodeId===v)??null:null,E=i&&T?T.settings.addonDefaults[i]??null:null,D=i&&v?p.data?.stepOverridesByAgent?.[v]?.[i]??null:null,O=y.data?.selectedEngine.format??`coreml`,k=e=>{s(e),l(null),d(null)};return m.isLoading||y.isLoading?K(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`}):y.data?K(`div`,{className:`@container h-full`,style:{containerType:`inline-size`},children:H(`div`,{className:`flex flex-col @[720px]:flex-row h-full`,children:[K(`aside`,{className:`w-full @[720px]:w-[300px] @[720px]:flex-shrink-0 border-b @[720px]:border-b-0 @[720px]:border-r border-border overflow-y-auto max-h-[40vh] @[720px]:max-h-none`,children:K(ke,{tree:x,selectedAddonId:i,onSelect:e=>{a(e),l(null),d(null)},agentDots:S})}),K(`section`,{className:`flex-1 min-w-0 p-4 overflow-y-auto`,children:!i||!C?K(`div`,{className:`text-sm text-foreground-subtle`,children:`Select a step on the left to configure it for this camera.`}):H(`div`,{className:`space-y-4`,children:[H(`div`,{children:[K(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle`,children:`Selected step`}),K(`div`,{className:`text-base font-semibold`,children:C.name})]}),H(`div`,{className:`flex items-end gap-3 flex-wrap`,children:[H(`div`,{children:[K(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle mb-1`,children:`Agent`}),K(`div`,{className:`flex rounded border border-border overflow-hidden`,children:(m.data??[]).map(e=>K(`button`,{type:`button`,onClick:()=>k(e.nodeId),className:`px-3 py-1 text-xs ${v===e.nodeId?`bg-primary text-primary-foreground`:`bg-surface hover:bg-muted`}`,children:e.nodeId},e.nodeId))})]}),K(zn,{agents:(m.data??[]).map(e=>e.nodeId),currentAgent:v,onPick:e=>{if(!v||!i||!y.data||!m.data)return;let t=m.data.find(t=>t.nodeId===e),n=m.data.find(e=>e.nodeId===v);if(!t||!n)return;let[r]=he({source:{nodeId:t.nodeId,engine:{format:O},defaults:t.settings.addonDefaults},target:{nodeId:n.nodeId,engine:{format:O},defaults:n.settings.addonDefaults},catalog:y.data,addonIds:[i]});if(!r){d(`no mirror result`);return}if(r.outcome===`skip`){d(`skipped: ${r.reason??`no candidate`}`);return}l(r.patch),d(`${r.outcome} from ${e}`)}}),u&&K(`div`,{className:`text-[10px] text-foreground-subtle`,children:u})]}),E&&K(se,{mode:`device`,addon:C,agentDefault:E,agentNodeId:v??``,currentPatch:c??D,engineFormat:O,onChangePatch:l}),H(`div`,{className:`flex items-center justify-between gap-2 pt-4 border-t border-border`,children:[K(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle`,disabled:!D||b.isPending,onClick:()=>{!v||!i||b.mutate({deviceId:e,agentNodeId:v,addonId:i,patch:null})},children:`Clear override`}),H(`div`,{className:`flex items-center gap-2`,children:[K(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>l(null),children:`Reset draft`}),K(`button`,{type:`button`,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,disabled:!v||!i||b.isPending,onClick:()=>{!v||!i||b.mutate({deviceId:e,agentNodeId:v,addonId:i,patch:c})},children:b.isPending?`Saving…`:`Save`})]})]})]})})]})}):K(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`})}function $({label:e,value:t}){return H(`div`,{className:`${Ue} flex items-start gap-2 sm:gap-3`,children:[K(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),K(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}V();function Vn({deviceId:e,initialName:t}){let n=W(),[r,i]=G(!1),[a,s]=G(t),[c,l]=G(!1),u=B(null);q(()=>{r||s(t)},[t,r]),q(()=>{r&&u.current?.focus()},[r]);let d=o({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),f=async()=>{let n=a.trim();if(n.length===0||n===t){i(!1),s(t);return}l(!0);try{await d.mutateAsync({deviceId:e,name:n}),i(!1)}catch{}finally{l(!1)}},p=()=>{s(t),i(!1)};return r?K($,{label:`Name`,value:H(`div`,{className:`flex items-center gap-1`,children:[K(`input`,{ref:u,type:`text`,value:a,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`?f():e.key===`Escape`&&p()},disabled:c,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`}),K(`button`,{type:`button`,onClick:()=>void f(),disabled:c,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:K(ct,{className:`h-3 w-3`})}),K(`button`,{type:`button`,onClick:p,disabled:c,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:K(vt,{className:`h-3 w-3`})})]})}):K($,{label:`Name`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[K(`span`,{className:`truncate`,children:t}),K(`button`,{type:`button`,onClick:()=>i(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit name`,children:K(tt,{className:`h-3.5 w-3.5`})})]})})}V();function Hn({deviceId:e,initialLocation:t}){let n=W(),[r,i]=G(!1),[a,o]=G(t??``),[s,l]=G(!1),u=B(null),{data:d}=j(void 0,{enabled:r}),f=d??[];q(()=>{r||o(t??``)},[t,r]),q(()=>{r&&u.current?.focus()},[r]);let p=c({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),m=U(()=>{let e=a.trim().toLowerCase();return e.length===0?f:f.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[f,a]),h=a.trim().length>0&&!f.some(e=>e.toLowerCase()===a.trim().toLowerCase()),g=async n=>{let r=(n??a).trim(),o=r.length===0?null:r;if(o===(t??null)){i(!1);return}l(!0);try{await p.mutateAsync({deviceId:e,location:o}),i(!1)}catch{}finally{l(!1)}},_=()=>{o(t??``),i(!1)};return r?K($,{label:`Location`,value:H(`div`,{className:`relative`,children:[H(`div`,{className:`flex items-center gap-1`,children:[K(`input`,{ref:u,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?g():e.key===`Escape`&&_()},disabled:s,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`}),K(`button`,{type:`button`,onClick:()=>void g(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:K(ct,{className:`h-3 w-3`})}),K(`button`,{type:`button`,onClick:_,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:K(vt,{className:`h-3 w-3`})})]}),(m.length>0||h)&&H(`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:[m.map(e=>H(`button`,{type:`button`,onClick:()=>{o(e),g(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[K(Rt,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),K(`span`,{className:`truncate`,children:e})]},e)),h&&H(`button`,{type:`button`,onClick:()=>void g(),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:[K(`span`,{className:`text-foreground-subtle`,children:`Create`}),H(`span`,{className:`font-medium truncate`,children:[`"`,a.trim(),`"`]})]})]})]})}):K($,{label:`Location`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[t?K(`span`,{className:`truncate`,children:t}):K(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),K(`button`,{type:`button`,onClick:()=>i(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit location`,children:K(tt,{className:`h-3.5 w-3.5`})})]})})}V();function Un({deviceId:e}){let t=W(),{data:n}=Dt(e),{data:i}=Et(e),[a,o]=G(null),s=v({onSuccess:()=>{o(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{o(`Could not change primary child: ${e.message}`)}});if(n==null||String(n.type??``)!==Y.Container)return null;let c=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(c.length<=1)return null;let l=r(c,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return H(Be,{children:[K($,{label:`Primary child`,value:K(y,{childrenList:c,selectedId:l===null?c[0].id:l.id,onSetPrimary:t=>s.mutate({deviceId:e,primaryChildEntityId:t}),disabled:s.isPending})}),a!==null&&K(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:a})]})}V();var Wn=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function Gn(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function Kn(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function qn(){let e=m(),t=h(),{data:n}=F({deviceId:e??0},{enabled:e!==null}),{data:r}=N({deviceId:e??0},{enabled:e!==null}),i=n??t??null,[a,o]=G(`identity`);if(e===null||!i)return null;let s=String(i.stableId??``),c=String(i.name??``),l=String(i.type??``),u=String(i.addonId??``),d=i.features??[],f=new Set([`device-status`,`feature-probe`,`device-ops`]),p=(r?.entries??[]).filter(e=>e.kind===`native`&&!f.has(e.capName)).map(e=>e.capName),g=d.length>0?d:p,_=i.location??null,v=i.metadata??null,y=v!==null&&Object.keys(v).length>0;return H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[H(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[K(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),y&&H(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[K(Jn,{active:a===`identity`,onClick:()=>o(`identity`),label:`Identity`}),K(Jn,{active:a===`hardware`,onClick:()=>o(`hardware`),label:`Hardware`})]})]}),(!y||a===`identity`)&&H(`div`,{className:`divide-y divide-border`,children:[K($,{label:`ID`,value:H(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,H(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,s,`)`]})]})}),K(Vn,{deviceId:e,initialName:c}),K(Hn,{deviceId:e,initialLocation:_}),K(Un,{deviceId:e}),K($,{label:`Type`,value:l}),K($,{label:`Provider`,value:K(et,{type:u,size:`sm`,showLabel:!0})}),K($,{label:`Capabilities`,value:g.length>0?K(Ze,{capabilities:g,showLabels:!0}):K(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),y&&a===`hardware`&&K(Yn,{metadata:v})]})}function Jn({active:e,onClick:t,label:n}){return K(`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 Yn({metadata:e}){let t=Wn.filter(t=>t in e),n=Object.keys(e).filter(e=>!Wn.includes(e)).toSorted(),r=[...t,...n];return H(`div`,{children:[K(`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.`}),K(`div`,{className:`divide-y divide-border`,children:r.map(t=>K($,{label:Gn(t),value:K(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:Kn(e[t])})},t))})]})}V();function Xn({deviceId:e}){let[t,n]=G(null),r=fe({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 H(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[H(`div`,{className:`flex items-center justify-between gap-3`,children:[H(`div`,{children:[K(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),K(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),H(`button`,{type:`button`,disabled:r.isPending,onClick:()=>{n(null),r.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:[K(rt,{className:`h-3 w-3 ${r.isPending?`animate-spin`:``}`}),r.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&K(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}function Zn(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function Qn({device:e}){let t=pt(),n=typeof e.id==`number`?e.id:null,r=String(e.type??``),i=r===Y.Camera,a=r===Y.Hub,o=e.features??[],s=o.includes(Xe.Resyncable),{data:c}=Ne({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),l=c?.streams??{},u=Object.entries(l),d=o.includes(Xe.DoorbellButton),f=Oe(d?{deviceId:n??void 0,historyLimit:10}:void 0),p=f.latest?Date.now()-f.latest.timestamp<3e4:!1;return H(`div`,{className:`space-y-5`,children:[a&&n!==null&&K(we,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),s&&n!==null&&K(Xn,{deviceId:n}),i&&n!==null&&K(x,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),d&&K(je,{history:f.history,latestIsFresh:p}),i&&n!==null&&K(x,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),i&&u.length>0&&H(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[K(`div`,{className:`border-b border-border px-4 py-2`,children:K(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),K(`div`,{className:`divide-y divide-border`,children:u.map(([e,t])=>H(`div`,{className:`px-4 py-2.5`,children:[H(`div`,{className:`flex items-center gap-2 mb-2`,children:[K(ot,{className:`h-3 w-3 text-foreground-subtle`}),K(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),H(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[K($n,{label:`Nominal`,value:Zn(t.nominalBitrateKbps??0)}),K($n,{label:`Observed`,value:Zn(t.observedBitrateKbps??0)}),K($n,{label:`Peak`,value:Zn(t.peakBitrateKbps??0)}),K($n,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),K(qn,{})]})}function $n({label:e,value:t,warning:n}){return H(`div`,{children:[K(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),K(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}V();function er(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function tr(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=er(r.value,t));return n}function nr(e,t){return e?.kind===`enum-map`?Object.entries(e.mapping).map(([e,t])=>({key:e,value:String(t)})):t?.kind===`enum`&&t.enumValues?t.enumValues.map(e=>({key:e,value:``})):[{key:``,value:``}]}function rr(e){return e?.kind===`linear`?{scale:String(e.scale),offset:String(e.offset),clampMin:e.clamp?String(e.clamp[0]):``,clampMax:e.clamp?String(e.clamp[1]):``,useClamp:e.clamp!=null}:{scale:`1`,offset:`0`,clampMin:``,clampMax:``,useClamp:!1}}function ir(e){return e==null?`identity`:e.kind}function ar({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=G(()=>ir(e)),[o,s]=G(()=>nr(e,n)),[c,l]=G(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=G(()=>rr(e));q(()=>{if(i===`enum-map`&&n?.kind===`enum`&&n.enumValues){let e=n.enumValues;s(t=>e.map(e=>({key:e,value:t.find(t=>t.key===e)?.value??``})))}},[n,i]),q(()=>{if(i===`identity`){t(void 0);return}if(i===`enum-map`){let e=tr(o,r),n=c===``?void 0:er(c,r);t({kind:`enum-map`,mapping:e,...n===void 0?{}:{fallback:n}});return}if(i===`linear`){let e=Number(u.scale),n=Number(u.offset);if(Number.isNaN(e)||Number.isNaN(n))return;let r=Number(u.clampMin),i=Number(u.clampMax),a=u.useClamp&&!Number.isNaN(r)&&!Number.isNaN(i)?[r,i]:void 0;t({kind:`linear`,scale:e,offset:n,...a?{clamp:a}:{}})}},[i,o,c,u,r,t]);let f=e=>{a(e),e===`enum-map`&&s(nr(void 0,n)),e===`linear`&&d(rr(void 0))},p=(e,t,n)=>{s(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r))},m=()=>s(e=>[...e,{key:``,value:``}]),h=e=>s(t=>t.filter((t,n)=>n!==e));return H(`div`,{className:`flex flex-col gap-3`,children:[H(`div`,{children:[K(`p`,{className:`text-[11px] font-medium text-foreground-subtle mb-1.5`,children:`Transform`}),K(`div`,{className:`flex items-center gap-4`,children:[`identity`,`enum-map`,`linear`].map(e=>H(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[K(`input`,{type:`radio`,name:`transform-kind`,value:e,checked:i===e,onChange:()=>f(e),className:`accent-primary`}),e===`identity`?`None`:e]},e))})]}),i===`enum-map`&&H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[K(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Key → Value mapping`}),o.map((e,t)=>H(`div`,{className:`flex items-center gap-1.5`,children:[K(`input`,{"aria-label":`enum key ${t}`,type:`text`,value:e.key,readOnly:n?.kind===`enum`,onChange:e=>p(t,`key`,e.target.value),placeholder:`source value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none read-only:opacity-70`}),K(`span`,{className:`text-foreground-subtle/50 text-xs`,children:`→`}),r===`boolean`?H(`select`,{"aria-label":`enum value ${t}`,value:e.value,onChange:e=>p(t,`value`,e.target.value),className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`,children:[K(`option`,{value:``,children:`—`}),K(`option`,{value:`true`,children:`true`}),K(`option`,{value:`false`,children:`false`})]}):K(`input`,{"aria-label":`enum value ${t}`,type:r===`number`?`number`:`text`,value:e.value,onChange:e=>p(t,`value`,e.target.value),placeholder:`target value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none`}),n?.kind!==`enum`&&K(`button`,{type:`button`,onClick:()=>h(t),className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] border border-border/80 text-foreground-subtle hover:text-danger hover:border-danger/50 transition-colors`,children:`✕`})]},t)),n?.kind!==`enum`&&K(`button`,{type:`button`,onClick:m,className:`self-start text-[10px] text-primary/70 hover:text-primary transition-colors`,children:`+ Add row`}),H(`div`,{className:`flex items-center gap-2 pt-1 border-t border-border/50`,children:[K(`label`,{className:`text-[10px] text-foreground-subtle/70 whitespace-nowrap`,children:`Fallback:`}),K(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`(leave empty for none)`,className:`flex-1 rounded border border-border bg-background px-2 py-0.5 text-xs font-mono text-foreground focus:border-primary outline-none`})]})]}),i===`linear`&&H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[K(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Linear: value × scale + offset`}),H(`div`,{className:`grid grid-cols-2 gap-2`,children:[H(`label`,{className:`flex flex-col gap-0.5`,children:[K(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Scale`}),K(`input`,{type:`number`,value:u.scale,onChange:e=>d(t=>({...t,scale:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),H(`label`,{className:`flex flex-col gap-0.5`,children:[K(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Offset`}),K(`input`,{type:`number`,value:u.offset,onChange:e=>d(t=>({...t,offset:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]}),H(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[K(`input`,{type:`checkbox`,checked:u.useClamp,onChange:e=>d(t=>({...t,useClamp:e.target.checked})),className:`accent-primary`}),K(`span`,{className:`text-foreground-subtle`,children:`Clamp output`})]}),u.useClamp&&H(`div`,{className:`grid grid-cols-2 gap-2`,children:[H(`label`,{className:`flex flex-col gap-0.5`,children:[K(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Min`}),K(`input`,{type:`number`,value:u.clampMin,onChange:e=>d(t=>({...t,clampMin:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),H(`label`,{className:`flex flex-col gap-0.5`,children:[K(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Max`}),K(`input`,{type:`number`,value:u.clampMax,onChange:e=>d(t=>({...t,clampMax:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]})]})]})}V();function or(e,t,n){return(n===void 0?[e,t]:[e,n,t]).map(e=>e.replace(/[^a-z0-9]/gi,`-`)).join(`-`)}function sr(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function cr(e,t){return t.find(t=>t.stableId===e)?.id??null}function lr(e){return e==null?`sibling`:e.source.kind===`literal`?`literal`:e.source.kind===`global`?`global`:`sibling`}function ur(e){if(e==null||e.source.kind!==`literal`)return`string`;let t=e.source.value;return t===null?`null`:typeof t==`number`?`number`:typeof t==`boolean`?`boolean`:`string`}function dr(e){if(e==null||e.source.kind!==`literal`)return``;let t=e.source.value;return t===null?``:String(t)}function fr(e,t){switch(e){case`null`:return{value:null};case`string`:return t===``?null:{value:t};case`number`:{if(t.trim()===``)return null;let e=Number(t);return Number.isFinite(e)?{value:e}:null}case`boolean`:return t===`true`?{value:!0}:t===`false`?{value:!1}:null}}function pr({deviceId:e,parentDeviceId:t,deviceStableId:n,initial:r,onSave:i,onCancel:a}){let{data:o}=Me({}),s=o??[],c=t==null?n:s.find(e=>e.id===t)?.stableId??n,l=s.filter(n=>n.parentDeviceId===t&&n.id!==e),{data:u}=te({deviceId:e,includeSynthesizable:!0}),d=u?.caps??[],f=r!=null&&r.source.kind!==`literal`&&r.source.kind!==`global`?r.source:null,p=r!=null&&r.source.kind===`global`?r.source:null,m=f??p,h=f==null?p==null?null:cr(p.sourceStableId,s):sr(f.sourceKey,c,s),[g,_]=G(lr(r)),[v,y]=G(r?.target.cap??``),[b,x]=G(r?.target.fieldPath??``),[S,C]=G(r?.target.itemKey??``),[w,T]=G(h),[E,ee]=G(m?.cap??``),[D,O]=G(m?.fieldPath??``),[k,ne]=G(``),[re,A]=G(ur(r)),[j,ie]=G(dr(r)),[ae,oe]=G(r?.transform);q(()=>{if(m==null||w!==null||s.length===0)return;let e=f==null?p==null?null:cr(p.sourceStableId,s):sr(f.sourceKey,c,s);e!==null&&T(e)},[m,f,p,w,s,c]);let{data:se}=te({deviceId:w??0},{enabled:w!=null&&g!==`literal`}),ce=se?.caps??[],M=d.find(e=>e.cap===v)?.fields??[],N=M.find(e=>e.path===b),P=N?.item===!0,le=ce.find(e=>e.cap===E)?.fields??[],F=le.find(e=>e.path===D),I=k.trim().toLowerCase(),ue=s.filter(t=>t.id===e?!1:I===``?!0:t.name.toLowerCase().includes(I)||t.stableId.toLowerCase().includes(I)||String(t.id).includes(I)),de=g===`global`?ue:l,fe=e=>{y(e),x(``),C(``)},pe=e=>{e!==`sibling`&&e!==`global`&&e!==`literal`||(_(e),T(null),ee(``),O(``),ne(``))},me=e=>{T(e===``?null:Number(e)),ee(``),O(``)},he=e=>{ee(e),O(``)},ge=fr(re,j),_e=g===`literal`?ge!==null:w!=null&&E!==``&&D!==``,ve=v!==``&&b!==``&&(!P||S.trim()!==``)&&_e,ye=()=>{if(g===`literal`)return ge===null?null:{kind:`literal`,value:ge.value};let e=s.find(e=>e.id===w);if(!e||E===``||D===``)return null;if(g===`global`)return{kind:`global`,sourceStableId:e.stableId,cap:E,fieldPath:D};let t=`${c}-`;return{sourceKey:e.stableId.startsWith(t)?e.stableId.slice(t.length):``,cap:E,fieldPath:D}},be=()=>{if(!ve)return;let e=ye();if(e===null)return;let t=P?S.trim():void 0;i({id:r?.id??or(v,b,t),source:e,target:{cap:v,fieldPath:b,...t===void 0?{}:{itemKey:t}},...ae==null?{}:{transform:ae}})},L=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`;return H(`div`,{className:`flex flex-col gap-4 p-3`,children:[H(`fieldset`,{className:`flex flex-col gap-3`,children:[K(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Target (this device)`}),H(`div`,{children:[K(`label`,{htmlFor:`link-target-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target cap`}),H(`select`,{id:`link-target-cap`,value:v,onChange:e=>fe(e.target.value),className:L,children:[K(`option`,{value:``,children:`— select a cap —`}),d.map(e=>K(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),H(`div`,{children:[K(`label`,{htmlFor:`link-target-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target field`}),H(`select`,{id:`link-target-field`,value:b,disabled:v===``,onChange:e=>x(e.target.value),className:L,children:[K(`option`,{value:``,children:`— select a field —`}),M.map(e=>K(`option`,{value:e.path,children:e.item===!0?`${e.path} (per item, ${e.kind})`:`${e.path} (${e.kind})`},e.path))]})]}),P&&H(`div`,{children:[K(`label`,{htmlFor:`link-target-item-key`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Item key`}),K(`input`,{id:`link-target-item-key`,type:`text`,value:S,placeholder:`e.g. main-brush`,onChange:e=>C(e.target.value),className:L}),K(`p`,{className:`mt-1 text-[10px] text-foreground-subtle/60`,children:`Links sharing the same item key build one item (e.g. one consumable).`})]})]}),H(`fieldset`,{className:`flex flex-col gap-3`,children:[K(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Source`}),H(`div`,{children:[K(`label`,{htmlFor:`link-source-mode`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source mode`}),H(`select`,{id:`link-source-mode`,value:g,onChange:e=>pe(e.target.value),className:L,children:[K(`option`,{value:`sibling`,children:`Sibling device (same container)`}),K(`option`,{value:`global`,children:`Any device`}),K(`option`,{value:`literal`,children:`Literal constant`})]})]}),g===`literal`?H(Be,{children:[H(`div`,{children:[K(`label`,{htmlFor:`link-literal-type`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal type`}),H(`select`,{id:`link-literal-type`,value:re,onChange:e=>{let t=e.target.value;(t===`string`||t===`number`||t===`boolean`||t===`null`)&&(A(t),t===`boolean`&&ie(`true`),t===`null`&&ie(``))},className:L,children:[K(`option`,{value:`string`,children:`string`}),K(`option`,{value:`number`,children:`number`}),K(`option`,{value:`boolean`,children:`boolean`}),K(`option`,{value:`null`,children:`null`})]})]}),re!==`null`&&(re===`boolean`?H(`div`,{children:[K(`label`,{htmlFor:`link-literal-value`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal value`}),H(`select`,{id:`link-literal-value`,value:j,onChange:e=>ie(e.target.value),className:L,children:[K(`option`,{value:`true`,children:`true`}),K(`option`,{value:`false`,children:`false`})]})]}):H(`div`,{children:[K(`label`,{htmlFor:`link-literal-value`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal value`}),K(`input`,{id:`link-literal-value`,type:`text`,value:j,placeholder:re===`number`?`e.g. 42`:`e.g. main-brush`,onChange:e=>ie(e.target.value),className:L})]}))]}):H(Be,{children:[g===`global`&&H(`div`,{children:[K(`label`,{htmlFor:`link-source-search`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Search devices`}),K(`input`,{id:`link-source-search`,type:`text`,value:k,placeholder:`Filter by name, stable id or #id`,onChange:e=>ne(e.target.value),className:L})]}),H(`div`,{children:[K(`label`,{htmlFor:`link-source-device`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source device`}),H(`select`,{id:`link-source-device`,value:w??``,onChange:e=>me(e.target.value),className:L,children:[K(`option`,{value:``,children:`— select a device —`}),de.map(e=>H(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),H(`div`,{children:[K(`label`,{htmlFor:`link-source-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source cap`}),H(`select`,{id:`link-source-cap`,value:E,disabled:w==null,onChange:e=>he(e.target.value),className:L,children:[K(`option`,{value:``,children:`— select a cap —`}),ce.map(e=>K(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),H(`div`,{children:[K(`label`,{htmlFor:`link-source-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source field`}),H(`select`,{id:`link-source-field`,value:D,disabled:E===``,onChange:e=>O(e.target.value),className:L,children:[K(`option`,{value:``,children:`— select a field —`}),le.map(e=>H(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]})]}),K(ar,{value:ae,onChange:oe,sourceField:g===`literal`?void 0:F,targetKind:N?.kind}),H(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[K(`button`,{type:`button`,onClick:a,className:`px-3 py-1.5 rounded-md text-xs font-medium border border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,children:`Cancel`}),K(`button`,{type:`button`,disabled:!ve,onClick:be,className:`px-3 py-1.5 rounded-md text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:`Save`})]})]})}V();function mr({deviceId:e}){let t=J(),n=W(),r=Number.isFinite(e),{data:i,isLoading:a}=F({deviceId:e},{enabled:r,refetchInterval:1e4}),{data:o}=te({deviceId:e,includeSynthesizable:!0},{enabled:r}),s=new Map;for(let e of o?.caps??[])e.itemArray&&s.set(e.cap,e.itemArray);let c=S({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),l=i?.deviceLinks??[],u=typeof i?.parentDeviceId==`number`?i.parentDeviceId:null,d=typeof i?.stableId==`string`?i.stableId:``,[f,p]=G(null),m=t=>{c.mutate({deviceId:e,deviceLinks:l.filter(e=>e.id!==t)})};return a?K(`div`,{className:`p-4`,children:K(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})}):f===null?H(`div`,{className:`flex flex-col gap-3 p-1`,children:[H(`div`,{className:`flex items-center justify-between`,children:[K(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Wiring`}),H(`button`,{type:`button`,onClick:()=>p(`new`),title:`Add a cross-device link`,className:`inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[K(nt,{className:`h-3 w-3`}),`Add link`]})]}),l.length===0?H(`div`,{className:`flex flex-col items-center justify-center gap-2 py-8 text-foreground-subtle`,children:[K(It,{className:`h-8 w-8 opacity-30`}),K(`p`,{className:`text-xs`,children:`No links yet.`}),K(`p`,{className:`text-[10px] opacity-60`,children:`Cross-device field wirings will appear here once authored.`})]}):K(`div`,{className:`flex flex-col divide-y divide-border rounded-lg border border-border overflow-hidden`,children:l.map(n=>K(gr,{deviceId:e,link:n,itemArray:s.get(n.target.cap),trpcClient:t.trpcClient,onDelete:()=>m(n.id),onEdit:()=>p(n),isPending:c.isPending},n.id))})]}):H(`div`,{className:`flex flex-col gap-3 p-1`,children:[K(`div`,{className:`flex items-center justify-between`,children:K(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:f===`new`?`Add link`:`Edit link`})}),K(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:K(pr,{deviceId:e,parentDeviceId:u,deviceStableId:d,initial:f===`new`?null:f,onSave:t=>{let n=l.some(e=>e.id===t.id)?l.map(e=>e.id===t.id?t:e):[...l,t];c.mutate({deviceId:e,deviceLinks:n}),p(null)},onCancel:()=>{p(null)}})})]})}function hr(e,t,n,r){let i=Ye(e,t.path);if(!Array.isArray(i))return;let a=i.find(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Reflect.get(e,t.keyField)===n);return a===void 0?void 0:Ye(a,r)}function gr({deviceId:e,link:t,itemArray:n,trpcClient:r,onDelete:i,onEdit:a,isPending:o}){let s=be(r,e,t.target.cap),c=t.target.itemKey,l=s===void 0?void 0:c!==void 0&&n!==void 0?hr(s,n,c,t.target.fieldPath):c===void 0?Ye(s,t.target.fieldPath):void 0,u=l==null?`—`:String(l);return H(`div`,{className:`flex items-center gap-3 px-3 py-2.5 bg-surface hover:bg-surface-hover transition-colors`,children:[K(Lt,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle/40`}),H(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[H(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[K(`span`,{className:`font-mono text-[11px] font-medium text-foreground`,children:t.target.cap}),K(`span`,{className:`text-[10px] text-foreground-subtle/60`,children:`.`}),K(`span`,{className:`font-mono text-[11px] text-foreground-subtle`,children:t.target.fieldPath}),c!==void 0&&K(`span`,{className:`rounded bg-surface-hover px-1 py-px font-mono text-[9px] text-foreground-subtle`,title:`Item key — links sharing it build one array item`,children:c})]}),H(`div`,{className:`flex items-baseline gap-1 flex-wrap text-[10px] text-foreground-subtle/70`,children:[K(`span`,{children:`←`}),t.source.kind===`literal`?H(`span`,{className:`font-mono`,children:[`literal: `,String(t.source.value)]}):H(Be,{children:[K(`span`,{className:`font-mono`,children:t.source.kind===`global`?t.source.sourceStableId:t.source.sourceKey}),K(`span`,{className:`opacity-60`,children:`/`}),K(`span`,{className:`font-mono`,children:t.source.cap}),K(`span`,{className:`opacity-60`,children:`.`}),K(`span`,{className:`font-mono`,children:t.source.fieldPath})]})]})]}),t.transform&&K(_r,{kind:t.transform.kind}),K(`span`,{className:`font-mono text-[11px] tabular-nums min-w-[2.5rem] text-right text-foreground-subtle`,title:`Live resolved value (from this device's runtime-state slice)`,children:u}),K(`button`,{type:`button`,"aria-label":`Edit link`,title:`Edit this link`,disabled:o,onClick:a,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:`Edit`}),K(`button`,{type:`button`,"aria-label":`Delete link`,title:`Remove this link`,disabled:o,onClick:i,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-danger hover:border-danger/50 hover:bg-danger/5 transition-colors disabled:opacity-50`,children:`Delete`})]})}function _r({kind:e}){return K(`span`,{className:`inline-flex items-center rounded-md border border-primary/20 bg-primary/5 px-1.5 py-0.5 font-mono text-[10px] text-primary/80 shrink-0`,children:e})}V();var vr=[{id:`overview`,label:`Overview`,cameraOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1},{id:`pipeline`,label:`Pipeline steps`,cameraOnly:!0},{id:`bindings`,label:`Bindings`,cameraOnly:!0},{id:`wiring`,label:`Wiring`,cameraOnly:!1}];function yr(e){let t=e===Y.Camera;return vr.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var br=[{id:`logs`,icon:bt,label:`Logs`},{id:`repl`,icon:_t,label:`REPL`},{id:`events`,icon:ft,label:`Events`},{id:`state`,icon:dt,label:`State`}];function xr(){let e=mt(),t=Number(e.deviceId),n=Number.isFinite(t),o=pt(),c=W(),l=E(),m=J(),[h,g]=lt(),_=h.get(`tab`)??`overview`,v=h.get(`sub`),[y,b]=G(`logs`),x=`device-detail.left-col-width-px`,[S,C]=G(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(x),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),w=B(S);w.current=S;function T(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??S??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{C(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=w.current;if(e!==null)try{window.localStorage.setItem(x,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:D,isError:O}=F({deviceId:t},{enabled:n,refetchInterval:5e3,retry:1}),{data:k}=le({deviceId:t},{enabled:n}),ne=U(()=>{let e=k?.settings?.sections??[],t=k?.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(Sn)&&r.add(yn),[...r].map(e=>e===`export`?{id:e,label:bn,isAddonContrib:!0}:{id:e,label:Je[e]?.label??e,isAddonContrib:!0})},[k]),A=ee,j=String(A?.name??e.deviceId??`Device`),se=A?.online===!0,ce=se?`online`:`offline`,M=String(A?.addonId??`rtsp`),N=A?.features??[],P=A?.type,I=P===Y.Camera,{data:ue}=Et(n?t:0),de=P===Y.Container,fe=U(()=>(ue??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[ue]),me=U(()=>de?r(fe,typeof A?.linkDeviceId==`number`?A.linkDeviceId:null,typeof A?.primaryChildEntityId==`string`?A.primaryChildEntityId:null)?.id??null:null,[de,fe,A?.linkDeviceId,A?.primaryChildEntityId]),{data:he}=le({deviceId:me??0},{enabled:me!==null}),ge=U(()=>{if(me===null)return[];let e=he?.settings?.sections??[],t=he?.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:Je[e]?.label??e,isAddonContrib:!0,childDeviceId:me}))},[me,he]),ye=typeof A?.parentDeviceId==`number`?A.parentDeviceId:null,{data:be}=F({deviceId:ye??0},{enabled:ye!==null}),L=ie(),xe=A?.disabled!==!0,{data:we}=te({deviceId:t},{enabled:n}),De=(we?.caps.length??0)>0,Oe=U(()=>{let e=new Set,t=[];for(let n of[...yr(P),...ne,...ge])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!De)&&t.push(n));return t},[P,ne,ge,De]),ke=U(()=>Oe.some(e=>e.id===_)?_:`overview`,[Oe,_]),Ae=z(e=>{g(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[g]),je=z(e=>{g(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[g]),Me=(ue??[]).length>0,Ne=U(()=>br.filter(({featureGate:e})=>!e||N.includes(e)),[N]),{data:R}=d({addonId:M},{enabled:!!M&&M!==`rtsp`}),Pe=i({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]}),o(R?.id?`/integrations/${R.id}`:`/integrations`)}}),Fe=oe({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=Ce({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=Te(),Re=Ee({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ze=N.includes(Xe.Rebootable),V=N.includes(Xe.BatteryOperated),Be=u(m.trpcClient,V&&n?t:null),[Ve,q]=G(!1),Ue=He(m.trpcClient,n?t:null),We=async()=>{if(!(Ve||!Ue)){q(!0);try{await Ue.snapshot?.invalidateCache({});let e=await Ue.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=j.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{q(!1)}}},Ke=Fe.isPending||Ie.isPending,{data:qe}=f({deviceId:t},{enabled:n,refetchInterval:1e4}),Ye=qe?.agentNodeId??null,Qe=typeof Ye==`string`&&Ye.length>0&&!Ye.startsWith(`addon:`)?Ye:void 0,{data:$e}=ae({deviceId:t,...Qe?{nodeId:Qe}:{}},{enabled:n,refetchInterval:3e3,retry:!1}),{data:tt}=_e({deviceId:t},{enabled:n,refetchInterval:3e3,retry:!1}),nt=tt?.level?.dbfs??null;function at(){if(!n)return null;switch(ke){case`overview`:return K(Qn,{device:A??{}});case`config`:return K(In,{deviceId:t,activeSubTab:v,onSubTabChange:je});case`pipeline`:return K(Bn,{deviceId:t,refreshToken:0});case`bindings`:return K(pn,{deviceId:t});case`wiring`:return K(mr,{deviceId:t});default:{let e=ke,n=ne.some(t=>t.id===e),r=ge.find(t=>t.id===e);if(!n&&r===void 0)return null;let i=r?.childDeviceId??t;if(e===`export`)return K(Fn,{deviceId:t,sectionFilter:Sn,activeSubTab:v,onSubTabChange:je});let a=K(Fn,{deviceId:i,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:v,onSubTabChange:je});return r!==void 0&&i!==t?K(pe,{deviceId:i,children:a}):a}}}return n?D?H(`div`,{className:`flex flex-col h-full`,children:[H(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[K(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),K(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),K(`div`,{className:`flex-1 p-6`,children:K(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):O||!ee?H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[K(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),H(`p`,{className:`text-xs`,children:[`No device with ID`,` `,H(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,t]})]}),K(`button`,{onClick:()=>o(`/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`})]}):H(`div`,{className:`absolute inset-0 flex flex-col overflow-hidden`,children:[H(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[K(`div`,{className:`mb-2`,children:K(re,{items:[{label:`Integrations`,onClick:()=>o(`/integrations`)},{label:R?.name??M,onClick:()=>R?.id&&o(`/integrations/${R.id}`)},{label:j}]})}),H(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[K(et,{type:M,size:`lg`}),H(`div`,{className:`min-w-0 flex-1`,children:[H(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[K(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:j}),K(Ot,{status:ce}),V&&K(p,{status:Be,variant:`full`})]}),ye!==null&&be&&H(`button`,{type:`button`,onClick:()=>o(`/devices/${ye}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${be.name}`,children:[K(`span`,{children:`↑`}),K(`span`,{className:`truncate`,children:String(be.name??`Device #${ye}`)})]}),K(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:N.length>0&&K(Ze,{capabilities:N})})]}),$e&&K(`div`,{className:`hidden lg:flex`,children:K(Sr,{metrics:$e,dbfs:nt})}),H(`div`,{className:`flex items-center gap-1 shrink-0`,children:[H(`button`,{onClick:async()=>{xe?await l({title:`Disable "${j}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Ie.mutate({deviceId:t}):Fe.mutate({deviceId:t})},disabled:Ke,title:xe?`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 ${xe?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[K(Bt,{className:`h-3.5 w-3.5`}),K(`span`,{className:`hidden sm:inline`,children:Ke?`Updating…`:xe?`Enabled`:`Disabled`})]}),K(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),K(ve,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:ut,disabled:Ve,onClick:()=>{We()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:it,hidden:!ze,disabled:Le.isPending,danger:!0,onClick:async()=>{await l({title:`Reboot "${j}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Le.mutate({deviceId:t})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${R?.name??M}.`,icon:rt,disabled:Re.isPending,danger:!0,onClick:async()=>{await l({title:`Restart "${R?.name??M}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${j}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Re.mutate({addonId:M})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:St,separatorBefore:!0,disabled:Pe.isPending,danger:!0,onClick:async()=>{await l({title:`Delete "${j}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Pe.mutate({deviceId:t})}}]})]})]})]}),K(pe,{deviceId:t,device:A??void 0,children:K(a,{children:K(s,{children:K(Ge,{children:K(Se,{children:H(`main`,{className:L?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[H(`div`,{className:L?`flex flex-col bg-surface`:`${S===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!L&&S!==null?{width:`${String(S)}px`}:void 0,children:[K(`div`,{className:I?`flex-shrink-0 border-b border-border-subtle bg-black`:L?`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:I?K(cn,{deviceId:t,intercomAvailable:N.includes(Xe.TwoWayAudio)}):K(Qt,{deviceId:t,deviceName:j,deviceType:P??`unknown`,provider:M,isOnline:se,features:N})}),H(`div`,{className:L?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[K(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:K(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:Ne.map(({id:e,label:t,icon:n})=>H(`button`,{onClick:()=>b(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${y===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[K(n,{className:`h-3 w-3`}),t]},e))})}),H(`div`,{className:L?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[y===`logs`&&K(ln,{deviceId:t,containerDeviceId:P===`container`?t:void 0}),y===`repl`&&K(un,{deviceId:t}),y===`events`&&K(dn,{deviceId:t}),y===`state`&&K(fn,{deviceId:t})]})]})]}),!L&&K(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:T,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:K(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),H(`div`,{className:L?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[K(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:K(`div`,{className:`flex flex-wrap items-center gap-0`,children:Oe.map(e=>{let t=ke===e.id;return H(`button`,{onClick:()=>Ae(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&&K(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),H(`div`,{className:L?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[ke===`overview`&&Me&&K(Ht,{parentDeviceId:t}),at()]})]})]})})})})})})]}):H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[K(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),H(`p`,{className:`text-xs`,children:[`The URL segment`,` `,K(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:e.deviceId}),` `,`is not a number.`]}),K(`button`,{onClick:()=>o(`/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 Sr({metrics:e,dbfs:t}){let n=_(e.phase??`idle`);return H(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[H(`div`,{className:`flex items-center gap-1.5`,children:[K(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),K(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),K(`div`,{className:`h-3 w-px bg-border`}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[K(st,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),K(`span`,{children:`fps`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[K(yt,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),K(`span`,{children:`ms`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[K(Vt,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),K(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&H(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{xr as DeviceDetailPage};
@@ -1 +0,0 @@
1
- import{I as e,Qi as t,b as n,i as r}from"./src-BVMxsNe8.js";import{Q as i,S as a,W as o,d as s,q as c,u 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-DTufy7Ue.js";import{d as f}from"./player-overlays-BH6aBUe-.js";import{C as p,D as m,S as h,g,k as _,w as v}from"./schemas-CuE8EXQ7.js";import{S as y}from"./src-CCmaAR6i.js";i();var b=_([v({kind:h(`adaptive`)}),v({kind:h(`profile`),profile:y})]),x=v({serverUrl:m().min(1),token:m().min(1),deviceId:p().int().nonnegative(),target:b,muted:g()});function S(e,t){let n=t===void 0?{type:`state`,state:e}:{type:`state`,state:e,message:t};window.ReactNativeWebView?.postMessage(JSON.stringify(n))}function C(e){switch(e){case`playing`:return`playing`;case`error`:return`error`;case`connecting`:case`disconnected`:case`idle`:return`connecting`}}function w(e){return e.kind===`adaptive`?{kind:`adaptive`}:{kind:`profile`,profile:e.profile}}function T(e){return e.kind===`adaptive`?`embed:adaptive`:`embed:profile:${e.profile}`}function E(){let e=window.__CAMSTACK_EMBED__;if(e==null)return{ok:!1,error:`window.__CAMSTACK_EMBED__ is not set`};let t=x.safeParse(e);return t.success?{ok:!0,config:t.data}:{ok:!1,error:t.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `)}}function D({message:e}){return d(()=>{S(`error`,e)},[e]),a(`div`,{style:{position:`fixed`,inset:0,display:`flex`,alignItems:`center`,justifyContent:`center`,background:`#000`,color:`#f87171`,fontFamily:`system-ui, sans-serif`,fontSize:13,padding:16,textAlign:`center`},children:[`Embed config error: `,e]})}function O({system:e,deviceId:t,initialTarget:i,initialMuted:a}){let[s,l]=c(i),[f,p]=c(a),{handleOffer:m,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,getSessionState:y}=r(e.trpcClient,t),x=o(()=>w(s),[s]),E=o(()=>(e,t)=>m(x,e,t),[m,x]),D=o(()=>(e,t,n)=>m(n,t,e),[m]);d(()=>(window.__camstackEmbed={setMuted:e=>p(e),setTarget:e=>{let t=b.safeParse(e);t.success&&l(t.data)}},()=>{window.__camstackEmbed&&delete window.__camstackEmbed}),[]);let O=T(s);return u(`div`,{style:{position:`fixed`,inset:0,width:`100vw`,height:`100vh`,background:`#000`},children:u(n,{serverUrl:e.serverUrl,streamKey:O,autoPlay:!0,muted:f,showControls:!1,className:`w-full h-full`,handleOffer:E,reoffer:D,getSessionState:y,getIceServers:h,addIceCandidate:g,getIceCandidates:_,closeSession:v,onStateChange:e=>S(C(e)),onError:e=>S(`error`,e)},O)})}function k(){let n=o(()=>E(),[]),r=o(()=>n.ok?{system:e({serverUrl:n.config.serverUrl,token:n.config.token}),queryClient:new s({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1}}})}:null,[n]);return d(()=>{if(r)return()=>{r.system.close()}},[r]),n.ok?r?u(f,{system:r.system,children:u(l,{client:r.queryClient,children:u(t.Provider,{client:r.system.trpcClient,queryClient:r.queryClient,children:u(O,{system:r.system,deviceId:n.config.deviceId,initialTarget:n.config.target,initialMuted:n.config.muted})})})}):u(D,{message:`Failed to initialise the embed player`}):u(D,{message:n.error})}export{k as EmbedPlayerPage};
@@ -1 +0,0 @@
1
- import{Ai as e,Ca as t,Ci as n,Di as r,Ei as i,Fi as a,Ii as o,Li as s,Mi as c,Ni as l,Oi as u,Pi as d,Ti as f,Wi as p,c as m,ct as h,ia as g,ji as _,ki as v,s as y,st as b,wi as x}from"./src-BVMxsNe8.js";import{Q as S,S as C,W as w,b as T,o as E,q as D,x as O}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as k}from"./circle-check-big-CgdBZ1l7.js";import{t as A}from"./copy-B6IIL8kT.js";import{t as j}from"./key-round-Dyj4n5xw.js";import{t as M}from"./AddonCollectionPage-D7eIR9NV.js";import{t as ee}from"./plus-CDeS7IvC.js";import{C as N,F as P,V as F,d as I,i as L,l as R,r as z,s as B,w as V,x as H}from"./index-DjbbJhB4.js";import{t as U}from"./AdminPage-BwmGKnRf.js";import{t as W}from"./AdminTabs-SHELeszh.js";var G=F(`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`}]]),te=F(`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`}]]),ne=F(`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`}]]),K=F(`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`}]]),q=F(`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`}]]);S();function re({userId:e,username:n,onClose:a}){let o=E(),s=p(),c=r({userId:e}),l=c.data,u=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),d=i({onSuccess:()=>{u(),a()}}),f=c.isLoading?`loading`:l?.enabled?`enrolled`:`not_enrolled`;return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[C(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[C(`div`,{className:`flex items-center gap-2`,children:[O(R,{className:`h-4 w-4 text-primary`}),C(`div`,{children:[O(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),C(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,O(`span`,{className:`font-mono`,children:n})]})]})]}),O(`button`,{onClick:a,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:O(L,{className:`h-4 w-4`})})]}),C(`div`,{className:`p-4 space-y-4`,children:[f===`loading`&&C(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[O(H,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),f===`not_enrolled`&&C(`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:[O(N,{className:`h-4 w-4 mt-0.5 shrink-0`}),C(`div`,{children:[O(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),O(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),f===`enrolled`&&l&&C(T,{children:[C(`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:[O(k,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),C(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[O(`div`,{className:`font-medium`,children:`2FA is active`}),C(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,l.confirmedAt?new Date(l.confirmedAt).toLocaleString():`—`]})]})]}),O(`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.`}),C(`div`,{className:`flex justify-end gap-2`,children:[O(t,{onClick:a,variant:`secondary`,children:`Close`}),C(`button`,{onClick:async()=>{await s({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`})&&d.mutate({userId:e})},disabled:d.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:[d.isPending?O(H,{className:`h-3 w-3 animate-spin`}):O(L,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function J(){let e=E(),{user:t}=z(),[n,r]=D(!1),[i,a]=D(``),[l,u]=D(``),[d,m]=D(!1),[h,v]=D(null),{data:y,isLoading:b,isError:S}=_(),w=p(),T=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),k=x({onSuccess:()=>{T(),r(!1),a(``),u(``),m(!1),v(null)},onError:e=>{v(e instanceof Error?e.message:`Failed to create user`)}}),A=f({onSuccess:T}),j=s({onSuccess:T}),M=c({onSuccess:T}),N=o({onSuccess:()=>{T(),F(null)}}),[P,F]=D(null),[V,W]=D(null),G=y??[];async function te(e){await w({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`})&&A.mutate({id:e.id})}async function K(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 w({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&M.mutate({id:e.id,newPassword:t})}}function q(e,t){t!==e.isAdmin&&j.mutate({id:e.id,isAdmin:t})}function J(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return C(U,{children:[O(`div`,{className:`flex items-center justify-end`,children:C(`button`,{onClick:()=>r(!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:[O(ee,{className:`h-3.5 w-3.5`}),`Create User`]})}),n&&C(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[C(`div`,{className:`flex items-center justify-between`,children:[O(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),O(`button`,{onClick:()=>r(!1),className:`text-foreground-subtle hover:text-foreground`,children:O(L,{className:`h-4 w-4`})})]}),C(`div`,{className:`grid grid-cols-3 gap-3`,children:[C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),O(`input`,{type:`text`,value:i,onChange:e=>a(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`})]}),C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),O(`input`,{type:`password`,value:l,onChange:e=>u(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`})]}),C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),C(`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:[O(`input`,{type:`checkbox`,checked:d,onChange:e=>m(e.target.checked),className:`rounded border-border focus:ring-primary`}),O(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),h&&O(`p`,{className:`text-[10px] text-danger`,children:h}),C(`div`,{className:`flex justify-end gap-2`,children:[O(`button`,{onClick:()=>r(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),O(`button`,{onClick:()=>k.mutate({username:i,password:l,isAdmin:d}),disabled:k.isPending||!i||!l,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:k.isPending?`Creating...`:`Create`})]})]}),b&&O(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),S&&O(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!b&&!S&&G.length===0&&O(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>A.isPending&&A.variables?.id===e.id||j.isPending&&j.variables?.id===e.id||M.isPending&&M.variables?.id===e.id;return O(g,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:t=>C(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[O(`input`,{type:`checkbox`,checked:t.isAdmin,onChange:e=>q(t,e.target.checked),disabled:e(t),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),O(`span`,{className:t.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:t.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Scopes`,render:e=>{if(e.isAdmin)return O(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`unscoped`});let t=e.scopes??[];return C(`button`,{onClick:()=>F(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground`,title:`Edit scope grants`,children:[O(I,{className:`h-3 w-3`}),t.length===0?`no access`:`${t.length} grant${t.length===1?``:`s`}`]})}},{key:`createdAt`,header:`Created`,render:e=>O(`span`,{className:`text-foreground-subtle`,children:J(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:n=>{let r=e(n);return C(`div`,{className:`flex items-center justify-end gap-1`,children:[n.id!==t?.id&&n.totpEnabled&&C(`button`,{onClick:()=>W(n),disabled:r,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:[O(R,{className:`h-3 w-3`}),`Remove 2FA`]}),C(`button`,{onClick:()=>K(n),disabled:r,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:[O(ne,{className:`h-3 w-3`}),`Reset password`]}),C(`button`,{onClick:()=>te(n),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:`Delete user`,children:[r?O(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:G,rowKey:e=>e.id,minWidthPx:560})})(),V&&O(re,{userId:V.id,username:V.username,onClose:()=>W(null)}),P&&O(ie,{user:P,onClose:()=>F(null),onSubmit:e=>N.mutate({userId:P.id,scopes:e}),submitting:N.isPending})]})}function ie(e){let{user:t}=z(),n=t?.isAdmin===!0;return O(ae,{...e,callerScopes:n?null:t?.scopes??[]})}function ae({user:e,onClose:t,onSubmit:n,submitting:r,callerScopes:i}){let[a,o]=D(w(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),s=m(a);return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:C(`div`,{className:`w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl`,children:[C(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-3`,children:[C(`div`,{children:[C(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Edit scopes — `,e.username]}),O(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`Admin users bypass the scope check; this list is ignored.`:`Pick which capabilities this user can call, and which access flavours within each.`})]}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(L,{className:`h-4 w-4`})})]}),C(`div`,{className:`px-4 py-4`,children:[O(y,{value:a,onChange:o,clampToParent:i,emptyHint:C(T,{children:[`No scopes granted.`,` `,O(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until a scope is added.`]})}),s&&O(`p`,{className:`mt-2 text-[10px] text-danger`,children:s})]}),C(`div`,{className:`flex items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),O(`button`,{onClick:()=>n(a),disabled:r||s!==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:r?O(H,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}S();var oe=`bg-primary/10 text-primary`,se=`bg-foreground-subtle/10 text-foreground-subtle`;function Y(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function ce(e){return e?e===`*`?`*`:e.join(`, `):``}function le(){let e=E(),t=p(),{data:r,isLoading:i}=u(),{data:o}=_(),s=w(()=>r??[],[r]),c=w(()=>o??[],[o]),d=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),f=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[m,h]=D(!1),[g,v]=D(null),y=l({onSuccess:d}),b=n({onSuccess:({token:e,record:t})=>{f(),h(!1),v({token:e,label:t.name})}}),x=a({onSuccess:f}),S=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&y.mutate({id:e})},T=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&x.mutate({id:e})};return C(U,{children:[C(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[O(`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.`}),C(`button`,{onClick:()=>h(!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:c.length===0,title:c.length===0?`Create a user first`:`Issue a scoped token`,children:[O(I,{className:`h-3.5 w-3.5`}),`New token`]})]}),C(X,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[c.length===0&&O(de,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),c.map(e=>O(fe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{T(e,t)},revokePending:x.isPending,revokeId:x.variables?.id},e.id))]}),s.length>0&&O(X,{title:`Legacy API keys`,subtitle:`${s.length} pre-existing — revoke only`,children:O(Z,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:s.map(e=>{let t=!!e.isAdmin,n=y.isPending&&y.variables?.id===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${t?oe:se}`,children:t?`admin`:`regular`})}),C(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:ce(e.allowedProviders)||`all`}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:Y(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:Y(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:C(`button`,{onClick:()=>{S(e.id,e.label)},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`,title:`Revoke`,children:[n?O(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),i&&O(ue,{}),m&&O(pe,{users:c.map(e=>({id:e.id,username:e.username})),onClose:()=>h(!1),onSubmit:e=>b.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:b.isPending}),g&&O(me,{token:g.token,label:g.label,onClose:()=>v(null)})]})}function X({title:e,subtitle:t,children:n}){return C(`div`,{className:`space-y-2`,children:[C(`div`,{className:`flex items-baseline justify-between`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&O(`span`,{className:`text-[10px] text-foreground-subtle`,children:t})]}),n]})}function ue(){return O(`div`,{className:`space-y-2`,children:[1,2].map(e=>O(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function de({text:e}){return O(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function Z({headers:e,rows:t}){return O(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[O(`thead`,{children:O(`tr`,{children:e.map((t,n)=>O(`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))})}),O(`tbody`,{children:t})]})})}function fe({userId:t,username:n,onRevoke:r,revokePending:i,revokeId:a}){let{data:o,isLoading:s}=e({userId:t}),c=o??[];return s||c.length===0?null:C(`div`,{className:`space-y-1.5`,children:[O(`div`,{className:`text-[11px] font-medium text-foreground`,children:n}),O(Z,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:c.map(e=>{let t=i&&a===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),C(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>C(`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`?`[${e.targets.join(`,`)}]`:e.target]},t))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:Y(e.expiresAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:Y(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:Y(e.createdAt)}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:C(`button`,{onClick:()=>r(e.id,e.name),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[t?O(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function pe({users:e,onClose:t,onSubmit:n,submitting:r}){let{user:i}=z(),a=i?.isAdmin===!0?null:i?.scopes??[],[o,s]=D(e[0]?.id??``),[c,l]=D(``),[u,d]=D([{type:`capability`,target:``,access:[`view`,`create`]}]),[f,p]=D(``),h=m(u),g=o!==``&&c.trim().length>0&&u.length>0&&h===null&&!r;return C(he,{title:`Create scoped token`,onClose:t,children:[C(`div`,{className:`space-y-3`,children:[O(Q,{label:`On behalf of user`,children:O(`select`,{value:o,onChange:e=>s(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=>O(`option`,{value:e.id,children:e.username},e.id))})}),O(Q,{label:`Name`,children:O(`input`,{value:c,onChange:e=>l(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`})}),C(Q,{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:[O(y,{value:u,onChange:d,clampToParent:a}),h&&O(`p`,{className:`mt-1 text-[10px] text-danger`,children:h})]}),O(Q,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:O(`input`,{type:`number`,min:1,value:f,onChange:e=>p(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`})})]}),C(ge,{children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),C(`button`,{onClick:()=>{let e=parseInt(f,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;n({userId:o,name:c.trim(),scopes:u,expiresAt:t})},disabled:!g,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:[r?O(H,{className:`h-3.5 w-3.5 animate-spin`}):O(I,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function me({token:e,label:t,onClose:n}){let[r,i]=D(!1),a=async()=>{try{await navigator.clipboard.writeText(e),i(!0)}catch{}};return C(he,{title:`Token: ${t}`,onClose:n,children:[C(`div`,{className:`space-y-3`,children:[O(`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.`}),O(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),C(ge,{children:[C(`button`,{onClick:()=>{a()},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:[r?O(P,{className:`h-3.5 w-3.5 text-primary`}):O(A,{className:`h-3.5 w-3.5`}),r?`Copied`:`Copy`]}),O(`button`,{onClick:n,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function he({title:e,onClose:t,children:n}){return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[C(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(L,{className:`h-4 w-4`})})]}),O(`div`,{className:`p-4`,children:n})]})})}function ge({children:e}){return O(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Q({label:e,hint:t,children:n}){return C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),n,t&&O(`p`,{className:`text-[10px] text-foreground-subtle`,children:t})]})}S();function $(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function _e(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 O(`div`,{className:`space-y-2`,children:[1,2].map(e=>O(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function ye({text:e}){return O(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function be({headers:e,rows:t}){return O(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[O(`thead`,{children:O(`tr`,{children:e.map((t,n)=>O(`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))})}),O(`tbody`,{children:t})]})})}function xe(){let e=E(),t=p(),{data:n,isLoading:r}=v(),i=w(()=>n??[],[n]),a=d({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),o=async(e,n)=>{await t({title:`Revoke "${n}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&a.mutate({id:e})};return C(U,{icon:K,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[r&&O(ve,{}),!r&&i.length===0&&O(ye,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!r&&i.length>0&&O(be,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:i.map(e=>{let t=e.revokedAt!==null,n=(a.isPending?a.variables?.id:void 0)===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>O(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:_e(e)},t))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 border-b border-border`,children:t?C(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,$(e.revokedAt)]}):O(`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`})}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!t&&C(`button`,{onClick:()=>{o(e.id,e.integrationId)},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`,title:`Revoke`,children:[n?O(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}S();var Se=3e4;function Ce(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function we(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:te,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA can be enrolled per-user from the Users page (added in v0.4).`,`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:V,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:V,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:R,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:R,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:I,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Te(){let e=h({capName:`auth-provider`},{refetchInterval:Se}),t=b(void 0,{refetchInterval:Se}),n=w(()=>Ce(t.data??[]),[t.data]);return O(M,{title:`Authentication`,subtitle:`Identity providers exposed to the admin UI. Multiple providers can run in parallel — operators pick which to enable. Disabling a provider only removes that external login method; local password login is unaffected. Each provider’s settings + live logs are inline below.`,pageIcon:I,itemIcon:I,capability:`auth-provider`,installButtonLabel:`Add provider`,items:w(()=>(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 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.`,renderExpandedPanel:e=>O(Ee,{addonId:e.addonId})})}function Ee({addonId:e}){let t=we(e),n=t.icon;return C(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[C(`div`,{className:`flex items-start gap-2.5`,children:[O(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),O(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),O(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>O(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&C(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[C(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[O(G,{className:`h-3 w-3`}),`Setup steps`]}),O(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>O(`li`,{children:e},t))})]}),e===`local-auth`&&C(`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:[O(N,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),C(`span`,{children:[`TOTP / 2FA settings are exposed per-user from the`,` `,O(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page (added in v0.4). Enable for each user via the Actions column → “Enable TOTP”.`]})]})]})}function De(){return O(`div`,{className:`flex flex-col p-4`,children:O(W,{tabs:[{id:`users`,label:`Users`,icon:q,content:O(J,{})},{id:`api-keys`,label:`Tokens`,icon:j,content:O(le,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:K,content:O(xe,{})},{id:`authentication`,label:`Authentication`,icon:I,content:O(Te,{})}]})})}export{De as IdentityPage};
@@ -1 +0,0 @@
1
- import{$n as e,An as t,Cn as n,Gn as r,H as i,Hi as a,Kn as o,V as s,Vi as c,Yn as l,Z as u,Zn as d,aa as f,an as p,d as m,dn as ee,en as h,g,mn as _,nn as v,on as y,pt as b,qn as te,rn as x,tn as S,un as C,vn as w,x as ne,xn as T,ya as E}from"./src-BVMxsNe8.js";import{I as D,K as re,Q as O,S as k,W as A,b as j,o as M,q as N,x as P,z as ie}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as F}from"./player-overlays-BH6aBUe-.js";import{b as I}from"./src-CCmaAR6i.js";import{t as L}from"./ProviderIcon-BVyDFfZQ.js";import{t as R}from"./plus-CDeS7IvC.js";import{n as z,r as B,t as ae}from"./ScanNetworkModal-CAWMDwou.js";import{t as oe}from"./refresh-cw-DCVnt6DS.js";import{t as V}from"./rotate-cw-BZnE1cAg.js";import{t as se}from"./wifi-TvDBvENo.js";import{E as H,F as U,G as ce,M as W,P as G,T as le,U as ue,V as de,W as fe,f as pe,i as me,o as K,p as he,s as ge,t as _e,x as q,z as ve}from"./index-DjbbJhB4.js";import{t as J}from"./FormBuilder-CegbdtFO.js";var ye=de(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);O();function be(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...be(n.fields));return t}function xe(e,t,n){let[r,i]=N(`idle`),[a,o]=N({}),s=A(()=>{let t=[];for(let n of e.sections)t.push(...be(n.fields));return t},[e]),c=s.length>0&&n!==void 0,l=D(e=>{o(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:r,hasProbeFields:c,probeResults:a,handleTestAll:D(async()=>{if(!n)return;let e=s.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;i(`testing`);let r={};for(let t of e)r[t]={status:`probing`};o(r);let a=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await n(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),c={};for(let e of a)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;c[t]={status:n.status===`ok`?`ok`:`error`,result:n}}o(c),i(`idle`)},[n,s,t]),clearProbeResult:l}}O();function Se(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Se(n.fields));return t}function Ce(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Y(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Y(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function X(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function we({open:e,integrationId:n,addonId:r,onClose:i}){let{t:a}=_e(),o=M(),[s,c]=N({}),[l,u]=N(!1),[d,f]=N(null),[m,ee]=N(X),h=T({addonId:r},{enabled:e}),v=h.data?.deviceType??null,y=_({addonId:r,type:v??I.Camera},{enabled:e&&h.isSuccess&&v!==null}),b=y.data??null;ie(()=>{e&&(c(b?Y(b.sections.flatMap(e=>e.fields)):{}),ee(X()),u(!1),f(null))},[e,n,b]);let te=A(()=>({...s,_probeRequestId:m}),[s,m]),x=p({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),S=t(),C=D(async(e,t)=>{u(!0);let n=await S.mutateAsync({addonId:r,type:v??I.Camera,key:e,value:t,formValues:te});return n.status===`ok`&&n.suggestedValues&&c(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Ce(e[i])&&!Ce(a)&&(r[i]=a,t=!0);return t?r:e}),n},[S,r,te,v]),{testAllStatus:w,hasProbeFields:ne,probeResults:E,handleTestAll:re,clearProbeResult:O}=xe(b??{sections:[]},s,C);async function j(e){f(null);try{await x.mutateAsync({addonId:r,type:v??I.Camera,config:s,integrationId:n}),e?c(b?Y(b.sections.flatMap(e=>e.fields)):{}):i()}catch(e){f(e instanceof Error?e.message:String(e))}}if(!e)return null;let F=Se((b?.sections??[]).flatMap(e=>e.fields)).filter(e=>Ce(s[e])),L=F.length===0,R=h.isLoading||v!==null&&y.isLoading,z=h.isError||h.isSuccess&&v===null||y.isError||y.isSuccess&&b===null;return k(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[P(`div`,{className:`absolute inset-0 bg-black/60`,onClick:i}),k(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[90vh] rounded-xl border border-border bg-background shadow-2xl`,children:[k(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:a(`integrations.addDevice`)}),P(`button`,{onClick:i,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:P(me,{className:`h-4 w-4`})})]}),P(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:R?P(`div`,{className:`flex items-center justify-center py-8`,children:P(q,{className:`h-5 w-5 animate-spin text-primary`})}):z?k(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[P(K,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),k(`div`,{className:`space-y-1`,children:[P(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),k(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,P(`span`,{className:`font-mono`,children:r}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):P(J,{schema:b,values:s,onChange:c,onTestField:C,probeResults:E,onClearProbe:O})}),!z&&!R&&k(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[k(`button`,{type:`button`,onClick:()=>u(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[k(`span`,{className:`flex items-center gap-2`,children:[P(he,{className:`h-3.5 w-3.5`}),`Test logs`,P(`span`,{className:`font-mono text-[9px] opacity-60`,children:m.slice(0,14)})]}),P(G,{className:`h-3.5 w-3.5 transition-transform ${l?`rotate-180`:``}`})]}),l&&P(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:P(g,{addonId:r,requestId:m,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!z&&!R&&(d||F.length>0)&&P(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:k(`div`,{className:`flex items-start gap-2`,children:[P(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),P(`p`,{className:`text-[11px] text-destructive`,children:d||`Required: ${F.join(`, `)}`})]})}),k(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[k(`div`,{className:`flex items-center gap-2`,children:[P(`button`,{onClick:i,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.cancel`)}),!z&&ne&&k(`button`,{type:`button`,onClick:re,disabled:w===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[w===`testing`?P(q,{className:`h-3.5 w-3.5 animate-spin`}):P(se,{className:`h-3.5 w-3.5`}),`Test All`]})]}),k(`div`,{className:`flex items-center gap-2`,children:[P(`button`,{onClick:()=>j(!0),disabled:z||!L||x.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:a(`integrations.saveAndNew`)}),P(`button`,{onClick:()=>j(!1),disabled:z||!L||x.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:x.isPending?a(`integrations.saving`):a(`integrations.save`)})]})]})]})]})}function Z(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}O();var Q=`devices`,Te={id:Q,label:`Devices`,isDefault:!0},Ee=2e4,De=100;function Oe({addonId:e,integrationId:t,onClose:n}){let{t:r}=_e(),[i,o]=N(new Set),[l,u]=N(new Set),[d,f]=N(new Map),[p,m]=N(null),{data:ee}=te(),g=(ee??[]).find(t=>t.addonId===e)?.supportsLocationImport??!1,[_,y]=N(!0),b=S({addonId:e,integrationId:t}).data?.filters,C=b&&b.length>0?b:[Te],[w,ne]=N(C.find(e=>e.isDefault)?.id??(C.some(e=>e.id===Q)?Q:C[0].id)),T=w!==Q,E=x(),O=v({addonId:e,integrationId:t,page:1,pageSize:Ee,filter:w}),A=O.refetch,j=E.mutate,M=D(()=>{j({addonId:e,integrationId:t},{onSettled:()=>{A()}})},[j,e,t,A]),F=re(null);ie(()=>{let n=`${e}::${t}`;F.current===n||O.isLoading||(F.current=n,(O.data?.candidates.length??0)===0&&M())},[e,t,O.isLoading,O.data,M]);let I=E.isPending,L=E.isError?E.error instanceof Error?E.error.message:String(E.error):null,R=O.data?.candidates??[],z=O.isError?O.error instanceof Error?O.error.message:String(O.error):null,B=h(),ae=D(e=>{e.alreadyAdopted||o(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),oe=D(e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),se=D((e,t)=>{f(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),H=D(e=>{let t={};for(let n of e){let e=d.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[d]),ce=D(async()=>{m(null);let r=[...i];if(r.length!==0)try{let i=H(r);await B.mutateAsync({addonId:e,integrationId:t,filter:w,childNativeIds:r,...i?{perCandidate:i}:{},...g?{importLocations:_}:{}}),o(new Set),f(new Map),await A(),n()}catch(e){m(e instanceof Error?e.message:String(e))}},[i,H,B,e,t,w,A,g,_]),W=D(e=>{ne(e),o(new Set),u(new Set),f(new Map),m(null)},[]),G=i.size;return k(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[P(`div`,{className:`absolute inset-0 bg-black/60`,onClick:n}),k(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[k(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[k(`div`,{className:`min-w-0`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:r(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),P(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:r(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),k(`div`,{className:`flex items-center gap-3 shrink-0`,children:[g&&k(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[P(`input`,{type:`checkbox`,checked:_,onChange:e=>y(e.target.checked),className:`accent-primary`}),r(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),P(`button`,{onClick:n,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:P(me,{className:`h-4 w-4`})})]})]}),k(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(L??z)&&R.length===0&&P(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:k(`div`,{className:`flex items-start gap-2`,children:[P(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),k(`div`,{className:`min-w-0`,children:[P(`p`,{className:`text-xs font-medium text-destructive`,children:r(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),P(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:L??z})]})]})}),C.length>1&&P(ke,{filters:C,activeFilter:w,onSelect:W}),P(`div`,{className:`flex-1 min-h-0`,children:P(s,{mode:`generic`,items:R,pageSize:De,getKey:e=>e.childNativeId,getSearchText:Z,getFilterType:e=>e.type,filterOptions:c(),filterLabel:r(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:O.isLoading||I&&R.length===0,searchPlaceholder:r(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(L??z)&&R.length===0?``:r(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:k(`button`,{type:`button`,onClick:M,disabled:I,title:r(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[P(V,{className:`h-3.5 w-3.5 ${I?`animate-spin`:``}`}),r(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:r(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>P($,{candidate:e,expandable:!T,expanded:l.has(e.childNativeId),onToggleExpand:()=>oe(e.childNativeId),adoptedLabel:r(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:r(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=a(e.type),n=t.icon;return k(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[P(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>P(`div`,{className:`flex items-center justify-end`,children:P(`button`,{onClick:()=>ae(e),disabled:e.alreadyAdopted,"aria-label":i.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${i.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:i.has(e.childNativeId)&&P(U,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!T&&l.has(e.childNativeId),renderExpanded:T?void 0:e=>P(Ae,{candidate:e,hiddenChildIds:d.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>se(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:i.has(e.childNativeId)?`bg-primary/5`:``})})]}),p&&P(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:k(`div`,{className:`flex items-start gap-2`,children:[P(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),P(`p`,{className:`text-[11px] text-destructive`,children:p})]})}),k(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[P(`div`,{}),k(`div`,{className:`flex items-center gap-2`,children:[P(`button`,{onClick:n,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:r(`integrations.cancel`,{defaultValue:`Cancel`})}),k(`button`,{onClick:ce,disabled:G===0||B.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[B.isPending&&P(q,{className:`h-3.5 w-3.5 animate-spin`}),r(`integrations.addSelected`,{defaultValue:`Add selected`}),G>0?` (${G})`:``]})]})]})]})]})}function ke({filters:e,activeFilter:t,onSelect:n}){return P(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return P(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function $({candidate:e,expandable:t,expanded:n,onToggleExpand:r,adoptedLabel:i}){let a=(e.children??[]).length;return k(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&a>0?k(`button`,{type:`button`,onClick:r,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[P(n?G:W,{className:`h-3.5 w-3.5`}),a]}):P(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),P(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&P(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:i})]})}function Ae({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let r=e.children??[];return r.length===0?null:P(`div`,{className:`space-y-1 py-1`,children:r.map(e=>{let r=t.has(e.childNativeId),i=e.capabilities??[];return k(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${r?`opacity-50`:``}`,children:[P(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),i.length>0&&P(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:i.join(`, `)}),P(`button`,{onClick:()=>n(e.childNativeId),"aria-label":r?`Show child`:`Hide child`,title:r?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:P(r?H:le,{className:`h-3 w-3`})})]},e.childNativeId)})})}O();function je({integrationId:e,addonId:t,name:n,kind:r,brokerKind:i,trpc:a,onClose:o}){let{t:s}=_e(),c=M(),u=r===`device-adoption`,{data:f}=l({id:e},{enabled:u}),p=A(()=>{let e=f?.brokerId;return typeof e==`string`?e:null},[f]),m=d();return P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:o,children:k(`div`,{className:`max-h-[85vh] w-full max-w-md overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[k(`div`,{className:`mb-3 flex items-center justify-between`,children:[k(`h2`,{className:`text-sm font-semibold text-foreground`,children:[s(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),P(`button`,{onClick:o,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":s(`common.close`,{defaultValue:`Close`}),children:P(me,{className:`h-4 w-4`})})]}),u?i?k(`div`,{className:`space-y-3`,children:[P(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),p&&k(`p`,{className:`text-[11px] text-foreground`,children:[s(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,P(`span`,{className:`font-mono text-foreground-subtle`,children:p})]}),m.isPending?k(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[P(q,{className:`h-3 w-3 animate-spin`}),s(`integrations.saving`,{defaultValue:`Saving…`})]}):P(z,{kind:i,onResolved:t=>{m.mutate({id:e,settings:{brokerId:t}},{onSuccess:()=>{c.invalidateQueries(),o()}})},onBack:o}),m.isError&&P(`p`,{className:`text-[11px] text-danger`,children:s(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):P(`p`,{className:`text-[11px] text-danger`,children:s(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):P(ne,{trpc:a,addonId:t,nodeId:`hub`,title:n})]})})}O();function Me(){let{t}=_e(),{integrationId:a}=fe(),c=M(),l=ue(),[d,p]=ce(),h=F(),[_,v]=N(!1),[x,S]=N(!1),[ne,T]=N(!1),[re,O]=N(!1),[I,z]=N(!1),{data:V,isLoading:se}=o({id:a??``},{enabled:!!a}),{data:H}=u({addonId:V?.addonId??``,nodeId:`hub`},{enabled:!!V?.addonId}),{data:U,isSuccess:W}=te(),G=A(()=>{let e=V?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[U,V?.addonId,W]),{data:le}=C({}),de=A(()=>(le?.providers??[]).some(e=>e.addonId===V?.addonId),[le,V?.addonId]),J=G!==null,be=J?G===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),xe=A(()=>{let e=V?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.brokerKind??null},[U,V?.addonId,W]),Se=A(()=>{let e=V?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.mode??null},[U,V?.addonId,W]);ie(()=>{d.get(`add`)===`1`&&J&&(v(!0),p(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[d,J,p]);let Ce=H!=null&&Array.isArray(H.sections)&&H.sections.some(e=>e.fields.length>0),{data:Y}=w({},{refetchInterval:5e3}),X=[[`integrations`,`get`],{input:{id:a??``},type:`query`}],Z=e({onMutate:async e=>{await c.cancelQueries({queryKey:X});let t=c.getQueryData(X);return t!=null&&c.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&c.setQueryData(X,r.previous)},onSettled:()=>{c.invalidateQueries({queryKey:[[`integrations`]]}),c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=r({onSuccess:()=>{c.invalidateQueries({queryKey:[[`integrations`]]}),c.invalidateQueries({queryKey:[[`deviceManager`]]}),O(!1),l(`/integrations`)}}),Te=b({onSuccess:()=>{c.invalidateQueries({queryKey:[[`integrations`]]}),c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ee=n({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),De=y({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=ee({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=A(()=>Y??[],[Y]),Ae=A(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),Me=D(e=>Ae.get(e)??null,[Ae]),Ne=D(e=>P(L,{type:e,size:`sm`}),[]),Pe=D(e=>l(`/devices/${String(e)}`),[l]),Fe=A(()=>{let e=V?.addonId;return e?$.filter(t=>t.addonId===e):[]},[$,V?.addonId]),Ie=A(()=>i(Fe).length,[Fe]);return se?k(`div`,{className:`p-4`,children:[P(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),P(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):V?k(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[P(f,{items:[{label:`Integrations`,onClick:()=>l(`/integrations`)},{label:V.name}]}),k(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[k(`div`,{className:`flex items-center gap-3 min-w-0`,children:[P(`img`,{src:`/api/addon-assets/${V.addonId}/assets/icon.svg`,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),k(`div`,{className:`min-w-0`,children:[P(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:V.name}),k(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[V.addonId,` · `,Ie,` `,t(`integrations.devices`)]})]})]}),k(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[de&&k(`button`,{onClick:()=>S(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the network for devices (incl. a different subnet)`,children:[P(B,{className:`h-3.5 w-3.5`}),`Scan network`]}),k(`button`,{onClick:()=>v(!0),disabled:!J,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:be,children:[P(R,{className:`h-3.5 w-3.5`}),be]}),k(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${V.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[P(E,{checked:V.enabled,onCheckedChange:e=>Z.mutate({id:a,enabled:e}),disabled:Z.isPending,"aria-label":V.enabled?`Disable integration`:`Enable integration`}),P(`span`,{className:`text-[11px] font-medium ${V.enabled?`text-success`:`text-foreground-subtle`}`,children:V.enabled?`Enabled`:`Disabled`}),Z.isPending&&P(q,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Se!==`standalone`&&(Ce||G===`device-adoption`)&&k(`button`,{onClick:()=>T(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[P(pe,{className:`h-3 w-3`}),t(`integrations.config`)]}),k(`button`,{onClick:()=>z(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.logs`,{defaultValue:`View logs`}),children:[P(he,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),P(m,{label:`Restart`,icon:oe,title:`Restart "${V.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ie} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Te.isPending,action:()=>Te.mutateAsync({addonId:V.addonId})}),k(`button`,{onClick:()=>O(!0),className:`flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors`,title:t(`integrations.delete`,{defaultValue:`Delete integration`}),children:[P(ge,{className:`h-3 w-3`}),t(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),P(s,{context:`integration-detail`,devices:$,trpc:h.trpcClient,defaultView:`cards`,forceAddon:V.addonId,urlScope:`root`,lsKey:`integration-detail:${V.addonId}`,resolveIntegrationIcon:Ne,resolveParent:Me,onNavigate:Pe,batchActions:{remove:Ee.mutate,disable:De.mutate,enable:ke.mutate},onDeleteDevice:e=>Ee.mutate({deviceId:e.id})}),_&&a&&G===`device-adoption`&&P(Oe,{addonId:V.addonId,integrationId:a,onClose:()=>v(!1)}),_&&a&&G===`device-provider`&&P(we,{open:_,integrationId:a,addonId:V.addonId,onClose:()=>v(!1)}),x&&V&&P(ae,{open:x,scope:{addonId:V.addonId,label:V.name},onClose:()=>S(!1)}),ne&&a&&G!==null&&P(je,{integrationId:a,addonId:V.addonId,name:V.name,kind:G,brokerKind:xe,trpc:h.trpcClient,onClose:()=>T(!1)}),I&&P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>z(!1),children:k(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[k(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[k(`div`,{className:`flex items-center gap-2 min-w-0`,children:[P(he,{className:`h-4 w-4 text-primary shrink-0`}),P(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:V.name}),k(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[V.addonId,a?` · ${a}`:``]})]}),P(`button`,{onClick:()=>z(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:P(me,{className:`h-4 w-4`})})]}),P(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:P(g,{addonId:V.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),re&&P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Q.isPending&&O(!1),children:k(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[k(`div`,{className:`flex items-start gap-3`,children:[P(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:P(K,{className:`h-4 w-4 text-danger`})}),k(`div`,{className:`min-w-0`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),P(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:V.name,count:Ie})})]})]}),Q.error&&P(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Q.error instanceof Error?Q.error.message:String(Q.error)}),k(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[P(`button`,{onClick:()=>O(!1),disabled:Q.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:t(`integrations.cancel`,{defaultValue:`Cancel`})}),P(`button`,{onClick:()=>Q.mutate({id:a}),disabled:Q.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed`,children:Q.isPending?k(j,{children:[P(q,{className:`h-3 w-3 animate-spin`}),t(`integrations.deleting`,{defaultValue:`Deleting…`})]}):k(j,{children:[P(ge,{className:`h-3 w-3`}),t(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):k(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[P(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:P(ye,{className:`h-6 w-6 text-foreground-subtle`})}),k(`div`,{className:`space-y-1 max-w-sm`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),P(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:a??``})})]}),k(`button`,{onClick:()=>l(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[P(ve,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{Me as IntegrationDetailPage};
@@ -1 +0,0 @@
1
- import{$t as e,Aa as t,H as n,Qn as r,V as i,Wn as a,Xn as o,Z as s,cn as c,qn as l,vn as u}from"./src-BVMxsNe8.js";import{I as d,Q as f,S as p,W as m,b as ee,o as h,q as g,x as _,z as v}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as y}from"./player-overlays-BH6aBUe-.js";import{t as b}from"./ProviderIcon-BVyDFfZQ.js";import{t as x}from"./plus-CDeS7IvC.js";import{n as S,r as C,t as w}from"./ScanNetworkModal-CAWMDwou.js";import{t as T}from"./refresh-cw-DCVnt6DS.js";import{F as E,G as D,I as O,M as k,P as A,U as j,f as M,g as N,i as P,t as F,x as I}from"./index-DjbbJhB4.js";import{t as te}from"./AdminPage-BwmGKnRf.js";import{t as L}from"./StatusBadge-Dcr2bw58.js";import{t as R}from"./useEventInvalidation-B-rUQp_C.js";import{t as z}from"./FormBuilder-CegbdtFO.js";import{t as B}from"./useBodyScrollLock-B_rtaBV1.js";f();function V({onSelect:e,onClose:t,pendingAddonId:n=null}){let{t:r}=F(),i=j(),{data:a,isLoading:o}=l();if(o)return _(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>_(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let s=n!==null;return p(`div`,{className:`space-y-2`,children:[(a??[]).map(a=>{let o=a.instanceMode===`unique`&&a.existingInstances.length>0,c=n===a.addonId,l=s;return p(`button`,{disabled:l,onClick:()=>{if(!l)if(o){let e=a.existingInstances[0].id;t(),i(`/integrations/${e}`)}else e(a.addonId,a.instanceMode,a.discoveryMode,a.name,a.kind,a.brokerKind,a.mode)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[a.iconUrl?_(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${a.color}15`},children:_(`img`,{src:a.iconUrl,alt:``,className:`h-5 w-5`})}):_(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${a.color}15`},children:_(`span`,{className:`text-sm`,style:{color:a.color},children:`◉`})}),p(`div`,{className:`flex-1 min-w-0`,children:[_(`p`,{className:`text-xs font-semibold text-foreground`,children:a.name}),a.description&&_(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:a.description})]}),c?_(I,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):o?p(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[_(M,{className:`h-3 w-3`}),r(`integrations.manage`)]}):_(k,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},a.addonId)}),(a??[]).length===0&&_(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:r(`integrations.noProviders`)})]})}function H({addonId:e,configSchema:t,onSave:n,onBack:i}){let{t:a}=F(),[o,s]=g(``),[c,l]=g({}),[u,d]=g(null),f=r({onSuccess:e=>d(e),onError:e=>d({success:!1,error:String(e)})});return p(`div`,{className:`space-y-4`,children:[p(`div`,{children:[_(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:a(`integrations.integrationName`)}),_(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:a(`integrations.integrationNamePlaceholder`),className:`w-full rounded-lg border border-border bg-surface px-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:border-primary/50`})]}),t&&_(z,{schema:t,values:c,onChange:l}),u&&_(`div`,{className:`rounded-lg border px-3 py-2 text-xs ${u.success?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:u.success?a(`integrations.connectionSuccess`):`${a(`integrations.errorPrefix`)} ${u.error}`}),p(`div`,{className:`flex items-center justify-between pt-2`,children:[_(`button`,{onClick:i,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.back`)}),p(`div`,{className:`flex items-center gap-2`,children:[_(`button`,{onClick:()=>f.mutate({addonId:e,settings:c}),disabled:f.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:f.isPending?a(`integrations.testing`):a(`integrations.testConnection`)}),_(`button`,{onClick:()=>n({name:o,config:c}),disabled:!o.trim(),className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:a(`integrations.forward`)})]})]})]})}f();function U({providerId:e,onImport:t,onSkip:n}){let{t:r}=F(),[i,a]=g(new Set),o=c(),s=o.data,l=o.isPending||!o.data&&!o.isError;v(()=>{e&&(o.isPending||o.data||o.mutate({addonId:e}))},[e,o]);function u(e){a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(l)return p(`div`,{className:`flex flex-col items-center py-12`,children:[_(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),_(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:r(`integrations.searchingDevices`)})]});let d=s??[];return p(`div`,{className:`space-y-4`,children:[_(`p`,{className:`text-xs text-foreground-subtle`,children:d.length>0?r(`integrations.foundDevices`,{count:d.length}):r(`integrations.noDevicesFound`)}),d.length>0&&_(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:d.map(e=>{let t=e.stableId,n=e.suggestedName??t,r=i.has(t);return p(`button`,{onClick:()=>u(t),className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${r?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[_(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${r?`border-primary bg-primary`:`border-border`}`,children:r&&_(E,{className:`h-3 w-3 text-primary-foreground`})}),_(O,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),_(`span`,{className:`text-xs font-medium text-foreground truncate`,children:n})]},t)})}),p(`div`,{className:`flex items-center justify-between pt-2`,children:[_(`button`,{onClick:n,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:r(`integrations.skip`)}),d.length>0&&p(`button`,{onClick:()=>t(Array.from(i)),disabled:i.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[r(`integrations.importSelected`),` (`,i.size,`)`]})]})]})}f();function W(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}function ne({open:t,onClose:n}){let{t:r}=F(),i=j(),o=h(),[l,u]=g(`picker`),[d,f]=g(null),[y,b]=g(null),[x,C]=g(`manual`),[w,T]=g(null),[E,D]=g(``),[O,k]=g(null),[A,M]=g(null),{data:N}=s({addonId:d??``,nodeId:`hub`},{enabled:d!=null}),te=m(()=>N?W(N):null,[N]),L=a({onSuccess:()=>o.invalidateQueries({queryKey:[[`integrations`]]})}),R=c(),z=R.data;v(()=>{l!==`discovery`||!y||!d||R.isPending||R.data||R.mutate({addonId:d})},[l,y,d,R]);let ne=e({onSuccess:()=>o.invalidateQueries({queryKey:[[`deviceManager`]]})});function G(e,t,n,r,i,a,o){if(!L.isPending){if(f(e),C(n),D(r),M(null),o===`broker`){if(!a){M(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}T(a),u(`broker`);return}if(o===`account`){u(`config`);return}re(e,r)}}async function re(e,t){try{let r=await L.mutateAsync({addonId:e,name:t,settings:{}});n(),Y(),i(`/integrations/${r.id}?add=1`)}catch{}}async function ie(e){if(d)try{let t=await L.mutateAsync({addonId:d,name:e.name,settings:e.config});b(t.id),x===`auto`||x===`both`?u(`discovery`):J(t.id)}catch{}}async function K(e){if(d)try{let t=await L.mutateAsync({addonId:d,name:E,settings:{brokerId:e}});k(t.id),b(t.id),J(t.id)}catch{}}async function q(e){if(d){for(let t of e){let e=z?.find(e=>e.stableId===t);e&&await ne.mutateAsync({addonId:d,candidate:e,...O===null?{}:{integrationId:O}})}J()}}function J(e){let t=e??y??d;n(),Y(),t&&i(`/integrations/${t}`)}function Y(){u(`picker`),f(null),b(null),C(`manual`),T(null),D(``),k(null),M(null)}function X(){n(),Y()}if(B(t),!t)return null;let ae={picker:r(`integrations.newIntegration`),config:r(`integrations.configureIntegration`),discovery:r(`integrations.importDevices`),broker:r(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Z=L.isPending,oe=Z?d:null,Q=L.error;return p(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[_(`div`,{className:`absolute inset-0 bg-black/60`,onClick:Z?void 0:X}),p(`div`,{className:`relative z-10 w-full max-w-lg max-h-[85vh] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[p(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[_(`h2`,{className:`text-sm font-semibold text-foreground`,children:ae[l]}),_(`button`,{onClick:X,disabled:Z,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:_(P,{className:`h-4 w-4`})})]}),p(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[Q&&!Z&&_(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:Q instanceof Error?Q.message:String(Q)}),l===`picker`&&p(ee,{children:[A&&_(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:A}),_(V,{onSelect:G,onClose:X,pendingAddonId:oe})]}),l===`config`&&d&&_(H,{addonId:d,configSchema:te??null,onSave:ie,onBack:()=>u(`picker`)}),l===`broker`&&w&&_(S,{kind:w,onResolved:e=>{K(e)},onBack:()=>u(`picker`)}),l===`discovery`&&y&&_(U,{providerId:y,onImport:q,onSkip:J})]}),Z&&p(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm`,children:[_(I,{className:`h-6 w-6 animate-spin text-primary`}),_(`p`,{className:`text-xs font-medium text-foreground`,children:r(`integrations.creating`,{defaultValue:`Creating integration…`})}),_(`p`,{className:`text-[10px] text-foreground-subtle`,children:r(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})})]})]})]})}function G({integration:e,expanded:t,onToggleExpand:n}){return p(`div`,{className:`flex items-center gap-2.5`,children:[_(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),n(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:_(t?A:k,{className:`h-3.5 w-3.5`})}),_(b,{type:e.addonId,size:`sm`}),p(`div`,{className:`flex min-w-0 flex-col`,children:[_(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),_(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function re(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>_(G,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>_(L,{status:e.status})}]}f();function ie(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var K=`expand`;function q(){let{t:e}=F(),r=j(),a=y(),[s]=D(),[c,l]=g(!1),f=d(()=>l(!0),[]),h=d(()=>l(!1),[]),[v,S]=g(!1),E=d(()=>S(!0),[]),O=d(()=>S(!1),[]);R([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),R([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:k,isLoading:A,refetch:M}=o(void 0),{data:P,isLoading:I,refetch:L}=u({}),z=m(()=>P??[],[P]),B=m(()=>k??[],[k]),V=m(()=>{let e=new Map;for(let t of z)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[z]),H=m(()=>{let e=new Map;for(let t of n(z)){let n=t.addonId??``;n&&e.set(n,(e.get(n)??0)+1)}return e},[z]),U=m(()=>B.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:ie(e),deviceCount:H.get(e.addonId)??0})),[B,H]),W=s.get(K),G=d(e=>{let t=new URLSearchParams(window.location.search);t.get(K)===e?t.delete(K):t.set(K,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),q=d(e=>r(`/integrations/${e.id}`),[r]),J=d(e=>V.get(e)??null,[V]),Y=d(e=>_(b,{type:e,size:`sm`}),[]),X=d(e=>r(`/devices/${String(e)}`),[r]),ae=d(e=>_(i,{context:`integration-detail`,devices:z,trpc:a.trpcClient,forceAddon:e.addonId,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:Y,resolveParent:J,onNavigate:X}),[z,a.trpcClient,Y,J,X]),Z=d(e=>W===e.addonId,[W]),oe=m(()=>re({isExpanded:Z,onToggleExpand:G}),[Z,G]),Q=d(e=>`${e.name} ${e.addonId}`,[]),se=d(e=>e.addonId,[]),ce=d(()=>{M(),L()},[M,L]),$=A||I,le=B.length>0;return p(te,{icon:N,title:e(`nav.integrations`,`Integrations`),actions:p(ee,{children:[_(`button`,{onClick:ce,disabled:$,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:_(T,{className:t(`h-3.5 w-3.5`,$&&`animate-spin`)})}),p(`button`,{onClick:E,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[_(C,{className:`h-3.5 w-3.5`}),`Scan network`]}),p(`button`,{onClick:f,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[_(x,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[$&&_(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>_(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!$&&!le&&p(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[_(`p`,{className:`text-sm`,children:`No integrations configured.`}),_(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!$&&le&&_(i,{mode:`generic`,items:U,getKey:se,getSearchText:Q,columns:oe,onRowClick:q,isExpanded:Z,renderExpanded:ae,searchPlaceholder:e(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:e(`integrations.empty`,{defaultValue:`No integrations found.`})}),_(ne,{open:c,onClose:h}),_(w,{open:v,onClose:O})]})}export{q as IntegrationsPage};