@camstack/addon-admin-ui 1.1.56 → 1.1.58

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 (94) hide show
  1. package/dist/assets/{AddLocationWizard-BS_sw-yb.js → AddLocationWizard-CVNjYxtc.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-B83rtm_P.js → AddonCollectionPage-ocTXpvOZ.js} +1 -1
  3. package/dist/assets/Addons-7Vjs9zfK.js +1 -0
  4. package/dist/assets/{AdminTabs-CGgxIyjn.js → AdminTabs-ti8-1m5K.js} +1 -1
  5. package/dist/assets/{AiProfiles-BiwHduY5.js → AiProfiles-CrEp6OFD.js} +1 -1
  6. package/dist/assets/{BrokerForm-Ce54Djz4.js → BrokerForm-DtpQ8uTP.js} +1 -1
  7. package/dist/assets/{Capabilities-B5IxdwuN.js → Capabilities-t4Kv7n1W.js} +1 -1
  8. package/dist/assets/{CapabilityBadges-3XeZhtSI.js → CapabilityBadges-mdL66YzR.js} +1 -1
  9. package/dist/assets/{Cluster-D8rUWJST.js → Cluster-Cm9cMLcE.js} +1 -1
  10. package/dist/assets/{ClusterRecordingTab-DX9aLngj.js → ClusterRecordingTab-CaOKHEeI.js} +1 -1
  11. package/dist/assets/{Dashboard-BblDjLKn.js → Dashboard-CpYJcmr_.js} +1 -1
  12. package/dist/assets/{Data-CdLaMkIJ.js → Data-4IVm8wg4.js} +1 -1
  13. package/dist/assets/{DetectionIntelligence-D6i0W6kk.js → DetectionIntelligence-BdB98iCp.js} +1 -1
  14. package/dist/assets/DeviceDetail-CQyDvbFg.js +2 -0
  15. package/dist/assets/{Devices-x_UPdIGK.js → Devices-C_6aVGD7.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-Buxyv9Ar.js → EmbedPlayerPage-CcGFTaVD.js} +1 -1
  17. package/dist/assets/Events-DaR_UKkQ.js +1 -0
  18. package/dist/assets/{FormBuilder-iTpxBqBc.js → FormBuilder-Dc0ym63B.js} +1 -1
  19. package/dist/assets/Identity-DJyNRncE.js +1 -0
  20. package/dist/assets/IntegrationDetail-BM--jjoS.js +1 -0
  21. package/dist/assets/{Integrations-BDJ1xxLY.js → Integrations-Cf9xW5df.js} +1 -1
  22. package/dist/assets/{Integrations-CV1KBLOI.js → Integrations-DzxZVoSV.js} +1 -1
  23. package/dist/assets/{Logs-ErbjBqie.js → Logs-CcOsniV2.js} +1 -1
  24. package/dist/assets/{MotionZonesSettings-BMPiTO3l.js → MotionZonesSettings-CokOBQSP.js} +1 -1
  25. package/dist/assets/{MyAccess-DTt40JO0.js → MyAccess-CX_ow6J1.js} +1 -1
  26. package/dist/assets/Network-DUc2RoeT.js +1 -0
  27. package/dist/assets/{NodeAddonsSettingsPanel-CFXh9ESA.js → NodeAddonsSettingsPanel-9-LKLy9X.js} +1 -1
  28. package/dist/assets/{NotificationTargets-Dgs05HjS.js → NotificationTargets-BhtcVTrY.js} +1 -1
  29. package/dist/assets/Pipeline-DovdUqqp.js +1 -0
  30. package/dist/assets/{Plates-B_BVouJR.js → Plates-CGw20xsK.js} +1 -1
  31. package/dist/assets/{PrivacyMaskSettings-DSSEqXHi.js → PrivacyMaskSettings-6vOAMZvp.js} +1 -1
  32. package/dist/assets/{ProviderIcon-BeZnXEB7.js → ProviderIcon-B3eTSPH9.js} +1 -1
  33. package/dist/assets/Recordings-B_jTro7W.js +1 -0
  34. package/dist/assets/{ScanNetworkModal-C_pd8W_5.js → ScanNetworkModal-BXLlQxmE.js} +1 -1
  35. package/dist/assets/{Settings-Cg4clEYW.js → Settings-ciNE8s7I.js} +1 -1
  36. package/dist/assets/{Showroom-DQuD1mwE.js → Showroom-DZhEfAVz.js} +1 -1
  37. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DqSIGxiA.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-WPoOdk8K.js} +1 -1
  38. package/dist/assets/{build-cluster-graph-D36_rlRB.js → build-cluster-graph-DF6vXFuz.js} +2 -2
  39. package/dist/assets/circle-check-big-CpW47sKH.js +1 -0
  40. package/dist/assets/clock-B2DLn9V8.js +1 -0
  41. package/dist/assets/{copy-DAnlpNmN.js → copy-CTAB7ETk.js} +1 -1
  42. package/dist/assets/{debounced-invalidate-DkqNPsSh.js → debounced-invalidate-BO1jeGCV.js} +1 -1
  43. package/dist/assets/{dist-Ck-SkmF_.js → dist-DfX3QEHj.js} +1 -1
  44. package/dist/assets/dist-hBxf_PpM.js +7 -0
  45. package/dist/assets/{download-CTO2YqfN.js → download-BUxKBqKH.js} +1 -1
  46. package/dist/assets/{face-bbox-Ctmu8UoI.js → face-bbox-CMdVS6x4.js} +1 -1
  47. package/dist/assets/{hostInit-DRnXHdHY.js → hostInit-YBm54NBK.js} +1 -1
  48. package/dist/assets/index-bh7u7Hyq.js +4 -0
  49. package/dist/assets/{key-round-DY-W0ctm.js → key-round-uhUyoLEA.js} +1 -1
  50. package/dist/assets/{mf-entry-bootstrap-0-64545043.js → mf-entry-bootstrap-0-d890d3a5.js} +2 -2
  51. package/dist/assets/{pencil-fohpLhWe.js → pencil-DvE-pDJv.js} +1 -1
  52. package/dist/assets/{player-overlays-CDSEY_-X.js → player-overlays-Xmuz6PYc.js} +1 -1
  53. package/dist/assets/plus-ZqwElRGO.js +1 -0
  54. package/dist/assets/{radio-CCbXLtig.js → radio-Bb4Ca-oO.js} +1 -1
  55. package/dist/assets/{refresh-cw-7j7eJ_7S.js → refresh-cw-wdTE-h5_.js} +1 -1
  56. package/dist/assets/remoteEntry-DaFl2uRt.js +1 -0
  57. package/dist/assets/{rotate-ccw-DVTmMtl2.js → rotate-ccw-BQvhpDZw.js} +1 -1
  58. package/dist/assets/rotate-cw-D3gOk0zM.js +1 -0
  59. package/dist/assets/search-DfF0SYZN.js +1 -0
  60. package/dist/assets/{send-CyaRM2HU.js → send-QP1-cyTt.js} +1 -1
  61. package/dist/assets/{server-BxecI2el.js → server-DduF17Ok.js} +1 -1
  62. package/dist/assets/square-Bj4oAYL4.js +1 -0
  63. package/dist/assets/{square-check-big-BsYa2Tzh.js → square-check-big-dYbuq7N5.js} +1 -1
  64. package/dist/assets/src-BXsSzH8t.js +67 -0
  65. package/dist/assets/src-Cghq8X9g.js +7 -0
  66. package/dist/assets/{upload-CYB5H427.js → upload-CBWYeFKA.js} +1 -1
  67. package/dist/assets/useDevice-CPjIwHzA.js +1 -0
  68. package/dist/assets/{useEventInvalidation-DtNYz-2H.js → useEventInvalidation-DyNr0T5f.js} +1 -1
  69. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DtiKhSUE.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BXXE9AlJ.js} +2 -2
  70. package/dist/assets/{wifi-D9-_VL0_.js → wifi-BGDzRUYW.js} +1 -1
  71. package/dist/assets/{zap-WiUYl_aC.js → zap-IAmUubjw.js} +1 -1
  72. package/dist/index.html +5 -5
  73. package/dist/server/addon.js +512 -3
  74. package/package.json +1 -1
  75. package/dist/assets/Addons-CVIk8bKA.js +0 -1
  76. package/dist/assets/DeviceDetail-BYfQe_30.js +0 -2
  77. package/dist/assets/Events-CDDnJ01Z.js +0 -1
  78. package/dist/assets/Identity-DH41lSfX.js +0 -1
  79. package/dist/assets/IntegrationDetail-CR5AD5vO.js +0 -1
  80. package/dist/assets/Network-CyPbysr8.js +0 -1
  81. package/dist/assets/Pipeline-Dsx-nB1p.js +0 -1
  82. package/dist/assets/Recordings-H8TXnxuf.js +0 -1
  83. package/dist/assets/circle-check-big-DOCODmhZ.js +0 -1
  84. package/dist/assets/clock-D2H-Andr.js +0 -1
  85. package/dist/assets/dist-DZmXEoJH.js +0 -7
  86. package/dist/assets/index-BVO5AjpN.js +0 -4
  87. package/dist/assets/plus-CWmuK222.js +0 -1
  88. package/dist/assets/remoteEntry-BB2jugOV.js +0 -1
  89. package/dist/assets/rotate-cw-Dl9N7lTh.js +0 -1
  90. package/dist/assets/search-DvkKd5B0.js +0 -1
  91. package/dist/assets/square-CzYy8xOt.js +0 -1
  92. package/dist/assets/src-DNVzx9ag.js +0 -7
  93. package/dist/assets/src-P2A2VEVG.js +0 -67
  94. package/dist/assets/useDevice-BskeVR-e.js +0 -1
@@ -1 +0,0 @@
1
- import{At as e,Ct as t,Dt as n,Et as r,Nr as i,Oa as a,St as o,Ta as s,Tt as c,_t as l,bt as u,dt as ee,ft as d,g as f,gt as p,ht as m,ja as h,jt as g,kt as _,m as v,mt as te,pt as ne,v as re,vt as ie,xt as ae,zr as y}from"./src-P2A2VEVG.js";import{I as b,K as x,Q as S,R as oe,S as C,W as w,b as T,o as E,q as D,x as O,z as k}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{H as se}from"./src-DNVzx9ag.js";import{p as ce}from"./player-overlays-CDSEY_-X.js";import{t as A}from"./clock-D2H-Andr.js";import{t as j}from"./download-CTO2YqfN.js";import{t as le}from"./plus-CWmuK222.js";import{t as M}from"./refresh-cw-7j7eJ_7S.js";import{t as ue}from"./search-DvkKd5B0.js";import{t as N}from"./upload-CYB5H427.js";import{I as P,J as de,K as fe,L as F,M as pe,S as I,W as L,g as R,i as z,m as me,p as B,s as V}from"./index-BVO5AjpN.js";import{t as H}from"./AdminPage-BwmGKnRf.js";import{t as he}from"./NodeAddonsSettingsPanel-CFXh9ESA.js";var ge=L(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),U=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`}]]),W=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`}]]);S();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 _e(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 ve(){let{data:e}=u({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=h(se.AddonsJobProgress,e=>e.job.jobId);return w(()=>{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 _e([...n.values()],Date.now())},[e,t])}var Y={queued:{icon:A,cls:`bg-muted text-foreground-subtle`,label:`queued`},fetching:{icon:I,cls:`bg-primary/10 text-primary`,label:`fetching`,spin:!0},staged:{icon:I,cls:`bg-primary/10 text-primary`,label:`staged`,spin:!0},validating:{icon:I,cls:`bg-primary/10 text-primary`,label:`validating`,spin:!0},applying:{icon:I,cls:`bg-primary/10 text-primary`,label:`applying`,spin:!0},restarting:{icon:I,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:`restarting`,spin:!0},applied:{icon:I,cls:`bg-primary/10 text-primary`,label:`finalizing`,spin:!0},done:{icon:F,cls:`bg-success/10 text-success`,label:`updated`},failed:{icon:U,cls:`bg-danger/10 text-danger`,label:`failed`},skipped:{icon:G,cls:`bg-muted text-foreground-subtle`,label:`skipped`}};function ye({progress:e}){let t=Y[e.phase],n=t.icon,r=e.error??`${e.packageName}: ${e.fromVersion??`?`} → ${e.toVersion}`;return C(`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:[O(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label,C(`span`,{className:`font-mono`,children:[`→ `,e.toVersion]})]})}function be({packageName:e,currentVersion:t,installSource:n,onInstall:r,onClose:i,onSelect:a,selectedVersion:o}){let s=n===`upload`||n===`local`,{data:c,isLoading:l}=p({name:e});return C(`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:[C(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[O(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Versions`}),O(`button`,{type:`button`,onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:O(z,{className:`h-3 w-3`})})]}),s&&C(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[O(N,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),C(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[C(`span`,{className:`font-semibold`,children:[n===`upload`?`Uploaded copy`:`Local copy`,` in place.`]}),` `,`Re-install `,O(`span`,{className:`font-mono`,children:t}),` from npm to track upstream releases again.`]})]}),l&&C(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[O(I,{className:`h-3.5 w-3.5 animate-spin`}),`Loading versions...`]}),c&&O(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:c.map(e=>{let n=e.version===t,i=a!==void 0&&e.version===o,c=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version),l=C(T,{children:[O(`span`,{className:`font-mono flex-1 text-left ${n?`text-primary font-semibold`:c?`text-amber-400`:`text-foreground`}`,children:e.version}),n&&O(`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=>O(`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&&O(`span`,{className:`text-[9px] text-red-400 line-through`,children:`deprecated`}),O(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return a?C(`button`,{type:`button`,"aria-label":`Select ${e.version}`,onClick:()=>a(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?O(F,{className:`h-3 w-3 text-primary shrink-0`}):O(`span`,{className:`w-3 shrink-0`})]},e.version):C(`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&&!s?O(F,{className:`h-3 w-3 text-primary shrink-0`}):O(`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:O(j,{className:`h-3 w-3`})})]},e.version)})}),c&&c.length===0&&O(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:`No versions found`})]})}var xe={queued:{icon:A,bg:`bg-muted text-foreground-subtle`,label:`queued`},updating:{icon:I,bg:`bg-primary/10 text-primary`,label:`updating`,spin:!0},"done-pending-restart":{icon:M,bg:`bg-amber-500/10 text-amber-700`,label:`pending restart`},done:{icon:F,bg:`bg-success/10 text-success`,label:`done`},failed:{icon:U,bg:`bg-danger/10 text-danger`,label:`failed`}};function Se({item:e}){let t=xe[e.status],n=t.icon;return C(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${t.bg}`,title:e.error,children:[O(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label]})}S();var X=`device-export`;function Ce(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===X)}function we({isBundle:e,installSource:t,addonId:n,iconPath:r,color:i}){let[a,o]=D(!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 C(`div`,{className:`relative flex-shrink-0`,children:[O(`div`,{className:`h-9 w-9 rounded-lg flex items-center justify-center ${s?``:c}`,style:s,children:u?O(`img`,{src:l,alt:n,className:`h-5 w-5`,onError:()=>o(!0)}):O(e?W:R,{className:`h-4 w-4`})}),t===`local`&&O(`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`&&O(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:O(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:O(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),t===`upload`&&O(`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:O(N,{className:`h-2.5 w-2.5 text-white`})})]})}function Te({version:e,availableUpdate:t,selectedVersion:n,isUpdating:r,installSource:i,disabled:a,onUpdate:o,onOpenPicker:s,children:c}){if(r)return C(`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:[O(I,{className:`h-3 w-3 animate-spin`}),`Updating…`]});if(t){let r=n??t;return C(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[o&&C(`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:[O(j,{className:`h-3 w-3`}),`Update`]}),C(`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:[O(`span`,{className:`font-normal opacity-70`,children:e}),O(`span`,{className:`font-normal opacity-70`,children:`→`}),r,O(P,{className:`h-3 w-3`})]}),c]})}return C(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[C(`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,O(P,{className:`h-3 w-3 opacity-50`})]}),c]})}function Ee({addonId:e}){let t=E(),{data:r=`inherit`}=ne({addonId:e}),i=n({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return O(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>O(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),i.mutate({addonId:e,channel:t})},disabled:i.isPending,className:`px-2.5 py-1 transition-colors capitalize ${r===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 De({addon:n,agents:r=[],clusterStatus:i,hideVersion:a,availableUpdate:o,onUpdate:u,isUpdating:ee,jobProgress:d,bundle:p,bulkItem:m,disabledByBulk:h,isSystem:g}){let[_,te]=D(!1),[ne,ie]=D(!1),[ae,y]=D(!1),[b,x]=D(null);k(()=>{x(null)},[o]);let S=b??o,[oe,w]=D(!1),[se,A]=D(!1),[j,ue]=D(`logs`),N=E(),de=ce(),F=fe(),pe=s(),{manifest:I}=n,L=n.installedOn??[],R=!p&&!I.protected&&I.removable!==!1,H=!!p,G=p?.displayName??I.name,K=p?.packageName??I.packageName,q=p?.version??I.packageVersion??I.version,J=p?.installSource??n.installSource,_e=p?p.bundle?.description??p.addons[0]?.manifest.description:I.description,ve=e({onSuccess:()=>{N.invalidateQueries({queryKey:[[`addons`]]}),N.invalidateQueries({queryKey:[[`addonPages`]]}),N.invalidateQueries({queryKey:[[`capabilities`]]})}}),Y=t({onSuccess:()=>{N.invalidateQueries({queryKey:[[`addons`]]})}}),xe=l({onSuccess:()=>{N.invalidateQueries({queryKey:[[`addons`]]}),N.invalidateQueries({queryKey:[[`addonPages`]]}),N.invalidateQueries({queryKey:[[`capabilities`]]}),N.invalidateQueries({queryKey:[[`integrations`]]})}}),X=c({onSuccess:()=>{N.invalidateQueries({queryKey:[[`addons`]]}),N.invalidateQueries({queryKey:[[`alerts`]]})}}),Z=n.health,Q=Z?.phase===`failed`&&!Z.inGracePeriod,Oe=Q&&Z?.nextRetryAt&&!Z.retrying;return C(`div`,{className:`rounded-lg border bg-surface overflow-hidden ${Q?`border-red-500/50`:`border-border`}`,children:[Q&&Z&&C(`div`,{className:`bg-danger/10 border-b border-danger/30 px-4 py-2.5 flex items-start gap-2.5`,children:[O(U,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),C(`div`,{className:`flex-1 min-w-0`,children:[C(`div`,{className:`text-xs font-semibold text-danger`,children:[`Failed to load (attempt #`,Z.retryCount,`)`]}),O(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:Z.lastError?.message??`Unknown error`}),Oe&&Z.nextRetryAt&&C(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:[`Auto-retry at `,new Date(Z.nextRetryAt).toLocaleTimeString()]})]}),C(`button`,{type:`button`,disabled:X.isPending||Z.retrying,onClick:e=>{e.stopPropagation(),X.mutate({packageName:K})},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:[O(M,{className:`h-3 w-3 ${X.isPending||Z.retrying?`animate-spin`:``}`}),`Retry now`]})]}),C(`div`,{className:`flex items-start gap-3 px-4 py-3`,children:[O(we,{isBundle:H||!!I.components&&I.components.length>1,installSource:J,addonId:H?p.addons[0]?.manifest.id:I.id,iconPath:H?p.bundle?.icon??p.addons[0]?.manifest.icon:I.icon,color:H?p.addons[0]?.manifest.color:I.color}),C(`div`,{className:`flex-1 min-w-0`,children:[C(`div`,{className:`flex items-start justify-between gap-2`,children:[O(`span`,{className:`text-sm font-semibold text-foreground truncate min-w-0`,children:G}),!a&&O(Te,{version:q,availableUpdate:o,...S===void 0?{}:{selectedVersion:S},isUpdating:ee,installSource:J,disabled:h,...u&&S!==void 0?{onUpdate:()=>u(S)}:{},onOpenPicker:()=>y(e=>!e),children:ae&&O(be,{packageName:K,currentVersion:q,...J?{installSource:J}:{},...o!==void 0&&S!==void 0?{selectedVersion:S,onSelect:e=>{x(e),y(!1)}}:{},onInstall:e=>{y(!1),xe.mutate({packageName:K,version:e})},onClose:()=>y(!1)})})]}),C(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[K!==G&&O(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:K}),H&&C(`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:[O(W,{className:`h-3 w-3`}),p.addons.length]}),g&&C(`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:[O(M,{className:`h-3 w-3`}),`System`]}),m!=null&&O(Se,{item:m}),d!=null&&O(ye,{progress:d})]}),_e&&O(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:_e}),!H&&n.process&&C(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[O(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${n.process.mode===`forked`?`bg-blue-500/15 text-blue-400`:`bg-gray-500/15 text-gray-400`}`,children:n.process.mode===`forked`?`forked`:`in-process`}),n.process.pid!=null&&C(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,n.process.pid]}),O(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${n.process.state===`running`?`bg-emerald-500/15 text-emerald-400`:n.process.state===`crashed`||n.process.state===`failed`?`bg-red-500/15 text-red-400`:`bg-gray-500/15 text-gray-400`}`,children:n.process.state})]})]})]}),!H&&C(`div`,{className:`flex items-center gap-1 px-4 py-1.5 border-t border-border/50 bg-surface-hover/20`,children:[C(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),Y.mutate({addonId:I.id})},disabled:Y.isPending||h,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:[O(M,{className:`h-3 w-3 ${Y.isPending?`animate-spin`:``}`}),`Restart`]}),C(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),w(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${oe?`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:[O(me,{className:`h-3 w-3`}),`Logs`]}),!H&&C(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),A(!0)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${se?`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:[O(B,{className:`h-3 w-3`}),`Settings`]}),O(`div`,{className:`flex-1`}),R&&C(`button`,{type:`button`,onClick:async e=>{e.stopPropagation(),await pe({title:`Uninstall ${I.name}?`,message:`This will remove the addon package and all its data. This action cannot be undone.`,confirmLabel:`Uninstall`,variant:`danger`})&&ve.mutate({packageName:I.packageName})},disabled:ve.isPending||h,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:[O(V,{className:`h-3 w-3`}),ve.isPending?`Removing...`:`Uninstall`]})]}),i&&i.nodes.length>1&&!H&&C(`div`,{className:`border-t border-border px-4 py-2 bg-muted/10`,children:[O(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:`Cluster Deployment`}),O(`div`,{className:`space-y-1`,children:i.nodes.map(e=>C(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[O(`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`}`}),O(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),O(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&O(`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`&&O(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:`offline`}),e.synced&&e.status!==`offline`&&O(`span`,{className:`text-[9px] text-success`,children:`synced`})]},e.nodeId))})]}),oe&&!H&&C(`div`,{className:`border-t border-border`,children:[C(`div`,{className:`flex items-center px-4 py-1 bg-surface-hover/20 border-b border-border/50`,children:[C(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[O(`button`,{type:`button`,onClick:()=>ue(`logs`),className:`px-2 py-0.5 transition-colors ${j===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Logs`}),O(`button`,{type:`button`,onClick:()=>ue(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${j===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Events`})]}),O(`div`,{className:`flex-1`}),O(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),w(!1)},className:`text-foreground-subtle hover:text-foreground`,children:O(z,{className:`h-3.5 w-3.5`})})]}),j===`logs`&&O(f,{addonId:I.id,maxHeight:`max-h-64`,showFilters:!1}),j===`events`&&O(v,{addonId:I.id,category:`addon.*`,maxHeight:`max-h-64`})]}),H&&C(T,{children:[O(`button`,{type:`button`,onClick:()=>te(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:O(_?ge:P,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),_&&O(`div`,{className:`border-t border-border px-3 py-2 space-y-2`,children:p.addons.map(e=>O(De,{addon:e,agents:r,hideVersion:!0},e.manifest.id))})]}),se&&!H&&O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,onClick:()=>A(!1),children:C(`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:[C(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0`,children:[C(`div`,{className:`flex items-center gap-2`,children:[O(B,{className:`h-4 w-4 text-primary`}),C(`h2`,{className:`text-sm font-semibold text-foreground`,children:[G,` Settings`]})]}),O(`button`,{onClick:()=>A(!1),className:`text-foreground-subtle hover:text-foreground transition-colors p-1 rounded`,children:O(z,{className:`h-4 w-4`})})]}),C(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-4`,children:[O(he,{nodeId:`hub`,addonIds:[I.id],level:`global`}),Ce(I)&&C(`div`,{children:[O(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Device export`}),O(re,{addonId:I.id,trpc:de.trpcClient,onOpenDevice:e=>F(`/devices/${e}`)})]}),J===`npm`&&C(`div`,{children:[O(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Auto-Update`}),O(Ee,{addonId:I.id})]}),I.components&&I.components.length>0&&C(`div`,{children:[C(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Components (`,I.components.length,`)`]}),O(`div`,{className:`flex flex-wrap gap-1`,children:I.components.map(e=>O(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]}),r.length>=2&&C(`div`,{children:[O(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Installed on`}),C(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[L.length===0&&O(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Hub (local)`}),L.map(e=>O(`span`,{className:`rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle`,children:e},e)),C(`div`,{className:`relative`,children:[C(`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:[O(le,{className:`h-3 w-3`}),`Add agent`]}),ne&&C(`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:[r.filter(e=>!e.isHub&&!L.includes(e.name)).map(e=>O(`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)),r.filter(e=>!e.isHub&&!L.includes(e.name)).length===0&&O(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle`,children:`No available agents`})]})]})]})]})]}),O(`div`,{className:`flex items-center justify-end px-5 py-3 border-t border-border flex-shrink-0`,children:O(`button`,{type:`button`,onClick:()=>A(!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`})})]})})]})}S();var Z=`.tgz,.tar.gz,.zip`;function Q({onUploadSuccess:e}){let[t,n]=D(!1),r=x(null),i=b(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 C(T,{children:[O(`input`,{ref:r,type:`file`,accept:Z,onChange:b(e=>{let t=e.target.files?.[0];t&&i(t),e.target.value=``},[i]),className:`hidden`}),C(`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?O(I,{className:`w-3.5 h-3.5 animate-spin`}):O(N,{className:`w-3.5 h-3.5`}),t?`Uploading...`:`Upload`]})]})}S();var Oe=new Set([`@camstack/system`,`@camstack/types`,`@camstack/sdk`,`@camstack/shm-ring`,`@camstack/ui-library`]);function ke(e){return e!==void 0&&Oe.has(e)}function Ae(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function je(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 Me(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 Ne({addons:e,clusterStatus:t,selectedNode:n,onRefresh:i,isRefreshing:a}){let o=E(),[c,u]=D(``),d=oe(c),[f,p]=D(!1),h=x(null);k(()=>{if(!f)return;let e=e=>{h.current&&!h.current.contains(e.target)&&p(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[f]);let{data:v}=ae({nodeId:n.id}),ne=w(()=>{let e=new Map;for(let t of v??[])e.set(t.name,t.latestVersion);return e},[v]),re=w(()=>(v??[]).filter(e=>!e.isSystem).length,[v]),[ie,y]=D(()=>new Set),[S,T]=D(()=>new Map),se=b(e=>{y(t=>new Set(t).add(e))},[]),ce=b(e=>{y(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),A=b((e,t)=>{T(n=>new Map(n).set(e,t))},[]),le=b(e=>{T(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),N=g({onMutate:e=>{se(e.name),le(e.name)},onSuccess:(e,t)=>{ce(t.name);let n=e;if(n&&n.success===!1){A(t.name,n.error??`Update failed (no error message returned by server)`);return}o.invalidateQueries({queryKey:[[`addons`]]}),o.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{ce(t.name),A(t.name,e instanceof Error?e.message:String(e))}}),P=ve(),fe=x(new Set);k(()=>{let e=new Set;for(let[t,n]of P)J(n)&&e.add(t);let t=[...fe.current].some(t=>!e.has(t));fe.current=e,t&&(o.invalidateQueries({queryKey:[[`addons`]]}),o.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[P,o]);let{data:L}=te(void 0),R=ee({onSuccess:()=>{o.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:z,isFetching:me}=r({query:d||void 0},{enabled:f}),B=_(),{data:V}=m(void 0),H=V?.requestedAt,[he,ge]=D(null),[U,W]=D(!1);k(()=>{if(V?.kind===`framework-bulk-update`&&V.requestedAt!==he){ge(V.requestedAt),W(!0);let e=window.setTimeout(()=>W(!1),6e3);return()=>window.clearTimeout(e)}},[H,he,V]),s();let G=b(async()=>{let e=(v??[]).filter(e=>!e.isSystem);e.length!==0&&await B.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[n.id]})},[v,n.id,B]),K=l({onSuccess:()=>{o.invalidateQueries({queryKey:[[`addons`]]}),o.invalidateQueries({queryKey:[[`addonPages`]]}),o.invalidateQueries({queryKey:[[`capabilities`]]}),o.invalidateQueries({queryKey:[[`integrations`]]})}}),[q,_e]=D(`type`),[Y,ye]=D(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),be=e=>{ye(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[xe,Se]=de(),X=xe.get(`capability`),Ce=w(()=>{let t=e.filter(e=>!ke(e.manifest.packageName));return n.isHub||(t=t.filter(e=>Ae(e.placement,n.isHub))),X&&(t=t.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===X))),t},[e,n.isHub,X]),we=()=>{let e=new URLSearchParams(xe);e.delete(`capability`),Se(e,{replace:!0})},Te=Y===`flat`?Ce:Me(Ce),Ee=w(()=>{let e=[...Te];switch(q){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},[Te,q]);return C(`div`,{className:`space-y-4`,children:[[...S.entries()].map(([e,t])=>O(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px]`,children:C(`div`,{className:`flex items-start justify-between gap-3`,children:[C(`div`,{className:`space-y-0.5`,children:[C(`div`,{className:`font-medium text-danger`,children:[`Failed to update `,e]}),O(`div`,{className:`text-foreground-subtle font-mono`,children:t})]}),O(`button`,{type:`button`,onClick:()=>le(e),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:`dismiss`})]})},e)),C(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[C(`div`,{className:`flex items-center gap-1.5`,children:[O(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Sort:`}),C(`select`,{value:q,onChange:e=>_e(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:[O(`option`,{value:`type`,children:`Bundles first`}),O(`option`,{value:`name`,children:`Name`}),O(`option`,{value:`source`,children:`Install source`})]})]}),C(`div`,{className:`flex items-center gap-1.5`,children:[O(`span`,{className:`text-[10px] text-foreground-subtle`,children:`View:`}),O(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>O(`button`,{type:`button`,onClick:()=>be(e),className:`px-2.5 py-1.5 transition-colors capitalize ${Y===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))})]}),n.isHub&&C(`div`,{className:`flex items-center gap-1.5`,children:[O(M,{className:`h-3 w-3 text-foreground-subtle`}),O(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Auto-Update:`}),O(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>O(`button`,{type:`button`,onClick:()=>R.mutate({channel:e}),disabled:R.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))})]}),re>0&&C(`button`,{type:`button`,onClick:()=>void G(),disabled:B.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:[B.isPending?O(I,{className:`w-3 h-3 animate-spin`}):O(j,{className:`w-3 h-3`}),B.isPending?`Updating…`:`Update All (${re})`]}),C(`button`,{type:`button`,onClick:i,disabled:a||B.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:[O(M,{className:`w-3 h-3 ${a?`animate-spin`:``}`}),`Refresh`]})]}),C(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[C(`div`,{className:`relative flex-1 min-w-0 sm:min-w-[200px]`,ref:h,children:[O(ue,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),O(`input`,{type:`text`,value:c,onChange:e=>{u(e.target.value),p(!0)},onFocus:()=>p(!0),placeholder:`Search addons on npm...`,disabled:B.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`}),me&&O(I,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin`}),f&&z&&z.length>0&&C(`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:[z.length>0&&C(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[`npm results (`,z.length,`)`]}),z&&z.length>0&&O(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:z.map(e=>C(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[O(`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()}),C(`div`,{className:`flex-1 min-w-0`,children:[C(`div`,{className:`flex items-baseline gap-2 min-w-0`,children:[O(`span`,{className:`text-[11px] font-semibold break-words`,children:e.name.replace(/^@camstack\/(addon-)?/,``)}),C(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`v`,e.version]})]}),O(`div`,{className:`font-mono text-[9px] text-foreground-subtle/80 truncate`,children:e.name}),e.description&&O(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?C(`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:[O(F,{className:`h-3 w-3`}),e.installedVersion??`Installed`]}):C(`button`,{type:`button`,onClick:()=>K.mutate({packageName:e.name}),disabled:K.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:[K.isPending?O(I,{className:`h-3 w-3 animate-spin`}):O(j,{className:`h-3 w-3`}),`Install`]})]},e.name))})]})]}),O(Q,{onUploadSuccess:()=>{o.invalidateQueries({queryKey:[[`addons`]]}),i()}})]}),X&&C(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-primary/10 border border-primary/30 text-sm`,children:[O(`span`,{className:`text-foreground-subtle`,children:`Filtering by capability:`}),O(`span`,{className:`font-mono text-primary font-semibold`,children:X}),O(`button`,{type:`button`,onClick:we,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:`Clear`})]}),U&&C(`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:[O(pe,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),C(`div`,{children:[O(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Bulk update completed`}),O(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`System packages updated — hub restarted successfully.`})]})]}),Ce.length===0&&O(`div`,{className:`text-xs text-foreground-subtle`,children:e.length===0?`No addons installed`:X?`No installed addons declare the "${X}" capability. Browse the npm catalog above to find a compatible addon.`:`No addons compatible with ${n.name} (placement filter active)`}),O(`div`,{className:`space-y-2`,children:Ee.map(e=>{let r=$(e)?e.bundle.packageName:e.manifest.packageName,i=ne.get(r),a=$(e)?e.representative:e,o=i?e=>N.mutate({name:r,version:e,nodeId:n.id}):void 0,s=P.get(r)??null,c=s!==null&&J(s);return O(De,{addon:a,clusterStatus:t?.[a.manifest.id],bundle:$(e)?e.bundle:void 0,availableUpdate:i,isUpdating:ie.has(r)||c,jobProgress:s,onUpdate:o,disabledByBulk:B.isPending},$(e)?r:e.manifest.id)})})]})}function Pe(){let e=E(),{data:t,isLoading:n,isError:r}=ie(),{data:s}=i(void 0),{data:c}=y(void 0,{refetchInterval:1e4}),l=w(()=>{let e=new Map;e.set(`hub`,{id:`hub`,name:`Hub`,isHub:!0});for(let t of c??[]){let n=String(t.id??``);n&&e.set(n,{id:n,name:String(t.name??n),isHub:!!t.isHub})}return[...e.values()]},[c]),[u,ee]=D(`hub`),f=l.find(e=>e.id===u)??l[0],p=d(),m=o(),h=p.isPending||m.isPending,g=async()=>{await p.mutateAsync({nodeId:u}),await m.mutateAsync(),e.invalidateQueries({queryKey:[[`addons`]]})},_=x(p);_.current=p,k(()=>{_.current.mutate({nodeId:`hub`})},[]);let v=(t??[]).map(je).filter(e=>e!==null);return C(H,{children:[C(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[O(a,{selectedNodeId:u,onSelect:ee}),C(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[!n&&!r&&C(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:[v.length,` installed`]}),C(`button`,{type:`button`,onClick:()=>void g(),disabled:h,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:[O(M,{className:`w-3 h-3 ${h?`animate-spin`:``}`}),`Check for updates`]})]})]}),!f.isHub&&C(`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`,` `,O(`span`,{className:`font-medium text-foreground`,children:f.name}),` — agents only run`,` `,O(`code`,{className:`font-mono`,children:`agent-only`}),` and`,` `,O(`code`,{className:`font-mono`,children:`any-node`}),` addons. Install / uninstall is hub-driven; agents auto-sync from the hub.`]}),n&&O(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading…`}),r&&O(`div`,{className:`text-xs text-danger`,children:`Failed to load addons`}),!n&&!r&&O(Ne,{addons:v,clusterStatus:s,selectedNode:f,onRefresh:()=>void g(),isRefreshing:h})]})}export{Pe as AddonsPage};
@@ -1,2 +0,0 @@
1
- import{$ as e,An as t,B as n,Ba as r,Bn as i,Ca as a,Ct as o,D as s,Di as c,Dn as l,E as u,F as d,Fa as f,Fn as p,H as m,Hi as h,Hn as g,In as _,J as v,K as y,La as b,Ln as x,Mr as S,N as C,O as w,On as T,P as E,Pa as D,Pn as ee,Q as O,Ra as te,Rn as ne,Rt as re,Sa as k,T as A,Ta as ie,Tn as ae,Ua as oe,Un as se,V as ce,Vn as j,Wn as M,X as le,Y as ue,Yr as de,Z as fe,a as N,an as pe,at as me,bn as he,cr as ge,di as P,f as _e,g as ve,gr as ye,hn as be,hr as F,i as I,it as xe,jn as Se,kn as Ce,l as we,li as Te,lo as Ee,m as De,mr as Oe,n as ke,na as Ae,o as je,oi as Me,on as L,p as Ne,pn as Pe,q as Fe,r as Ie,ra as Le,rt as Re,tt as ze,u as Be,uo as Ve,wn as R,xi as He,xn as Ue,y as We,za as Ge,zn as Ke,zr as qe}from"./src-P2A2VEVG.js";import{I as z,K as B,Q as V,S as H,W as U,a as Je,b as W,o as G,q as K,t as Ye,x as q,z as J}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{A as Xe,B as Ze,D as Qe,E as $e,L as et,O as tt,S as nt,T as rt,b as it,g as at,k as ot,w as Y,y as st}from"./src-DNVzx9ag.js";import{c as ct,k as lt,p as X,r as ut,t as dt,u as ft}from"./player-overlays-CDSEY_-X.js";import{t as pt}from"./CapabilityBadges-3XeZhtSI.js";import{n as mt,t as ht}from"./rotate-ccw-DVTmMtl2.js";import{t as gt}from"./ProviderIcon-BeZnXEB7.js";import{n as _t,t as vt}from"./FormBuilder-iTpxBqBc.js";import{i as yt,n as bt,t as xt}from"./useDevice-BskeVR-e.js";import{t as St}from"./pencil-fohpLhWe.js";import{t as Ct}from"./plus-CWmuK222.js";import{t as wt}from"./refresh-cw-7j7eJ_7S.js";import{t as Tt}from"./rotate-cw-Dl9N7lTh.js";import{t as Et}from"./server-BxecI2el.js";import{t as Dt}from"./wifi-D9-_VL0_.js";import{A as Ot,J as kt,K as At,L as jt,S as Mt,U as Nt,V as Pt,W as Ft,a as It,c as Lt,i as Rt,j as zt,m as Bt,q as Vt,r as Ht,s as Ut,t as Wt,v as Gt,y as Kt,z as qt}from"./index-BVO5AjpN.js";import{t as Jt}from"./StatusBadge-Dcr2bw58.js";import{t as Yt}from"./useEventInvalidation-DtNYz-2H.js";import{n as Xt,r as Zt,t as Qt}from"./SchemaTabBar-DhsmEGyn.js";var $t=Ft(`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`}]]),en=Ft(`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`}]]),tn=Ft(`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`}]]),nn=Ft(`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`}]]),rn=Ft(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),an=Ft(`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 on({parentDeviceId:e}){let{t}=Wt(),n=At(),r=X(),{data:i,isLoading:a,isError:o}=bt(e),{data:s}=R({deviceId:e},{enabled:Number.isFinite(e)});if(a)return q(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:q(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(o)return q(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:q(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let c=(i??[]).filter(e=>e.display?.hidden!==!0);if(c.length===0)return null;let l=v(s?.stableId??``,c,s?.childLayout),u=l.ungrouped,d=e=>n(`/devices/${String(e)}`),f=s?.name??``,p=(e,t)=>q(y,{trpc:r.trpcClient,device:{...t,name:O(t,f)},variant:`minimal`,onNavigate:d},e),m=u.some(e=>!!e.role),h=u.some(e=>!e.role),g=m&&!h?t(`device.accessories`,{defaultValue:`Accessories`}):!m&&h?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),_=u.length>0?H(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[q(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:g}),q(`div`,{className:`space-y-1`,children:u.map(e=>p(e.id,e))})]}):null,b=l.disabledSection===void 0?null:q(Fe,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:l.disabledSection.children.length,defaultOpen:!1,children:q(`div`,{className:`opacity-60 space-y-1`,children:l.disabledSection.children.map(e=>p(e.id,e))})},l.disabledSection.title);return l.sections.length===0?b===null?_:H(`div`,{className:`space-y-2`,children:[_,b]}):H(`div`,{className:`space-y-2`,children:[l.sections.map(e=>q(Fe,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>p(e.id,e))},e.title)),_,b]})}function sn({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:[q(gt,{type:n,size:`lg`}),H(`div`,{children:[q(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),q(`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:[q(Jt,{status:r?`online`:`offline`}),i.length>0&&q(pt,{capabilities:i})]}),q(`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 cn({deviceId:e}){let t=G(),n=pe({deviceId:e},{refetchInterval:1e4,retry:!1}),r=L({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=U(()=>ln(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:[q(un,{label:`Discovered`,value:i.total,icon:q(Gt,{className:`h-3.5 w-3.5`})}),q(un,{label:`Adopted`,value:i.adopted,accent:`success`}),q(un,{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?q(Mt,{className:`h-3.5 w-3.5 animate-spin`}):q(wt,{className:`h-3.5 w-3.5`}),q(`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:[q(dn,{icon:q(Dt,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),q(dn,{icon:q(Kt,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),q(dn,{icon:q(It,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?q(dn,{icon:q($t,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function ln(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 un({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,q(`span`,{className:`truncate`,children:e})]}),q(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function dn({icon:e,label:t}){return H(`span`,{className:`inline-flex items-center gap-1`,children:[e,q(`span`,{children:t})]})}function fn({deviceId:e,features:t}){return q(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:q(a,{trpc:X().trpcClient,deviceId:e,features:t})})}function pn({deviceId:e,features:t}){return q(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:q(k,{trpc:X().trpcClient,deviceId:e,features:t})})}function Z({deviceId:e,deviceType:t,features:n}){let r=X(),i=xe(t)?.HeroCard??k,a=ft(ct(r.trpcClient,e)?.state.deviceStatus),o=a!==void 0&&a.online===!1,s=o?a.lastChangedAt:null;return H(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[o?q(`div`,{className:`flex justify-center`,children:q(m,{lastChangedAt:s})}):null,q(i,{trpc:r.trpcClient,deviceId:e,features:n})]})}function mn({deviceId:e}){let t=X(),{data:n,isLoading:r}=xt(e),{data:i,isLoading:a}=bt(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?q(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):q(`div`,{className:`flex h-full w-full flex-col`,children:q(ce,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}var hn={[Y.Switch]:Z,[Y.Siren]:Z,[Y.Light]:Z,[Y.Sensor]:Z,[Y.Button]:Z,[Y.Hub]:cn,[Y.Cover]:fn,[Y.Valve]:Z,[Y.Humidifier]:Z,[Y.WaterHeater]:Z,[Y.Container]:mn,[Y.Lock]:Z,[Y.Fan]:Z,[Y.Thermostat]:Z,[Y.Climate]:Z,[Y.MediaPlayer]:Z,[Y.Control]:Z,[Y.AlarmPanel]:pn,[Y.EventEmitter]:pn,[Y.Notifier]:pn,[Y.Script]:pn,[Y.Automation]:pn,[Y.Presence]:Z,[Y.Update]:Z,[Y.Vacuum]:Z,[Y.LawnMower]:Z,[Y.Weather]:Z,[Y.Image]:Z,[Y.PetFeeder]:Z};function gn(e){return q(hn[e.deviceType]??sn,{...e})}function _n(e){return N(X().trpcClient,e)}V();function vn(e){let[t,n]=K(`idle`),[r,i]=K(null),a=B(null),o=B(null),s=B(null),c=B(!0),l=F(),u=Oe(),d=ye(),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 J(()=>(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 yn=0;function Q(){return++yn}function bn(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function xn(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 Sn(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 Cn(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 wn({scope:e,greeting:t,className:n}){let r=X(),[i,a]=K(()=>{let n=[];return t&&n.push({id:Q(),kind:`info`,text:t}),n.push({id:Q(),kind:`info`,text:`scope: ${bn(e)} — type help or context for available commands`}),n}),[o,s]=K(``),[c,l]=K([]),[u,d]=K(-1),f=B(null),p=B(null);J(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=z(()=>{f.current?.focus()},[]),h=Ye({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: ${bn(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...xn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...Cn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...Sn(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: ${bn(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=>q(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&q(`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:[q(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),q(`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 Tn({deviceId:e,intercomAvailable:t=!1}){let n=X(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=_n(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),g=le(n.trpcClient,i?e:null),_=vn(i&&t?e:null),v=_.state===`requesting-mic`||_.state===`starting`||_.state===`connecting`||_.state===`stopping`,y=_.isTalking||v,b=()=>{_.state===`idle`||_.state===`error`?_.start():_.state!==`stopping`&&_.stop()},x=ut(),S=w(),C=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,T=x.length>0?q(W,{children:x.map(e=>q(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return q(We,{serverUrl:r,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h,...S.request?{playbackUrl:S.request.url,playbackAuthToken:C,...S.request.label?{playbackLabel:S.request.label}:{},onExitPlayback:()=>S.clear()}:{},streams:o,pipelineMetrics:s,phase:a.phase,detections:a,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:g.src,...g.src?{posterUrl:g.src}:{},snapshotLoading:g.loading,onRefreshSnapshot:g.refresh,intercomAvailable:t,intercomShown:y,onIntercomToggle:b,extraOverlay:T,chromeless:!0,className:`h-full`})}function En({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full`,children:q(ve,{...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 Dn({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 q(wn,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function On({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(De,{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 kn({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(_e,{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 An({deviceId:e}){let n=G(),r=Number.isFinite(e),{data:i}=R({deviceId:e},{enabled:r}),a=typeof i?.type==`string`?i.type:`camera`;Yt([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:o,isLoading:s,isError:c,error:l}=Ue({deviceId:e},{enabled:r}),{data:u}=t({deviceType:a},{enabled:!!a}),d=g({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(s)return q(`div`,{className:`p-4`,children:q(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(c)return H(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,l instanceof Error?l.message:String(l)]});let f=new Map,p={};for(let e of u??[])p[e.capName]=e.wrappers;for(let e of o?.entries??[])f.set(e.capName,{...e,wrappers:p[e.capName]??[]});for(let e of u??[])f.has(e.capName)||f.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let m=[...f.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(m.length===0)return H(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[q(mt,{className:`h-8 w-8 opacity-40`}),q(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),q(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let h=m.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:[q(`span`,{className:`font-medium text-foreground`,children:h}),` of `,m.length,` capabilit`,m.length===1?`y`:`ies`,` bound — rows marked `,q(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),q(Ge,{columns:[{key:`capability`,header:`Capability`,render:e=>q(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>q(jn,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>q(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||q(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?q(Mn,{nodeId:e.providerNodeId}):q(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>q(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||q(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return q(Nn,{wrappers:t.wrappers,activeWrapperId:n,disabled:d.isPending,onPick:r=>{let i=n===r;d.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:m,rowKey:e=>e.capName,minWidthPx:720})]})}function jn({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:[q(Et,{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:[q(en,{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:[q(nn,{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:[q(yt,{className:`h-3 w-3`}),`unbound`]})}function Mn({nodeId:e}){return q(`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 Nn({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?q(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):q(`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:[q(i?jt:ht,{className:`h-3 w-3`}),e]},e)})})}V();function Pn({schema:e,values:t,pendingKeys:n,onChange:r,onAction:i,onSave:a,onDiscard:o,disabled:s,activeSubTab:c,onSubTabChange:l,flattenTabs:u=!1,deviceId:d}){let f=e.tabs??[],p=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]),m=new Set(f.map(e=>e.id)),h=[...f,...[...p.keys()].filter(e=>!m.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],g=h[0]?.id??`general`,[_,v]=K(g),y=l!==void 0,b=new Set(h.map(e=>e.id)),x=y?c&&b.has(c)?c:g:b.has(_)?_:g,S=e=>{y?l(e):v(e)},C=p.get(x)??[],w={sections:C.length<=1?C.length===1?[{...C[0],title:``}]:C:C.every(e=>!e.title)?[{...C[0],title:``,fields:C.flatMap(e=>e.fields)}]:C},T=q(Xt,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:s});if(u||h.length<=1)return H(`div`,{className:`flex flex-col gap-3`,children:[q(vt,{schema:e,values:t,onChange:r,onAction:i,disabled:s,deviceId:d}),T]});let E=new Map,D=new Map;for(let[e,t]of p){E.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&&D.set(e,a)}return H(`div`,{className:`flex flex-col gap-3`,children:[q(Qt,{tabs:h.map(e=>({id:e.id,label:e.label})),activeId:x,onChange:S,countByTab:E,pendingByTab:D}),q(vt,{schema:w,values:t,onChange:r,onAction:i,disabled:s,deviceId:d}),T]})}var Fn=`device-export`,In=`export`,Ln=`Export`;function Rn(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(Rn):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(Rn)):e.writerCapName===Fn}function zn(e){return e.fields.some(Rn)}V();function Bn(e,t){return t&&t===`admin`?e:!0}function Vn(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?zn(e)&&zn(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function Hn(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 Un(e){return e.key}function Wn(e){if(!Hn(e))return e.value}function Gn(e){return Hn(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 qn(e){if(!e)return{};let t={};for(let n of e.sections)Kn(n.fields,e=>{let n=Un(e);n!==null&&(t[n]=Wn(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||Un(e)!==t)return;let r=Gn(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function Yn(e){return{...e,fields:e.fields.map(Xn)}}function Xn(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function Zn(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=Gn(e);return n?Bn(t,n.minRole)?e:Xn(e):e})}))}}function Qn({deviceId:e,sectionFilter:t,activeSubTab:n,onSubTabChange:r,flattenSubTabs:i}){let a=G(),{user:o}=Ht(),s=o?.isAdmin===!0,c=B(!1),{data:l,isLoading:u}=ae({deviceId:e},{refetchInterval:()=>c.current?!1:2500,enabled:Number.isFinite(e)}),{data:d}=R({deviceId:e},{enabled:Number.isFinite(e)}),f=l?.settings??null,m=l?.live??null,h=U(()=>{if(!f&&!m)return null;let e=f?.sections??[],n=(m?.sections??[]).map(Yn),r=[...e,...n],i=t?r.filter(t):r.filter(e=>e.location!==`top-tab`&&!zn(e));if(i.length===0)return null;let a=new Set;for(let e of i)a.add(e.tab??`general`);let o=[...f?.tabs??[],...(m?.tabs??[]).filter(e=>!(f?.tabs??[]).some(t=>t.id===e.id))].filter(e=>a.has(e.id));return o.length>0?{tabs:o,sections:i}:{sections:i}},[f,m,t]),g=U(()=>Vn(h),[h]),_=U(()=>Zn(g,s),[g,s]),v=U(()=>qn(_),[_]),y=Le(),b=Ae(),x=se(),S=p(),C=M({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),w={isPending:C.isPending,mutate:t=>{C.mutate({deviceId:e,changes:[...t]})}},T=Zt({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:D,handleChange:ee,handleSave:O,handleDiscard:te}=T;if(c.current=T.editingPaused,u)return H(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[q(Mt,{className:`h-4 w-4 animate-spin mr-2`}),q(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!_||_.sections.length===0)return q(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:`No aggregate contributions for this device.`});async function ne(t,n,r){if(t===`regenerate-rtsp-token`){let t=[`rtspUrl:`,`regenerateToken:`].find(e=>n.startsWith(e));if(!t)throw Error(`regenerate-rtsp-token: unrecognised key "${n}" (expected "rtspUrl:<streamId>" or "regenerateToken:<streamId>")`);let r=n.slice(t.length);if(!r)throw Error(`regenerate-rtsp-token: key "${n}" has no streamId after prefix`);let i=et(e,r);await y.mutateAsync({brokerId:i}),a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(t===`test-probe`){if(!d)return{status:`error`,error:`Device metadata not loaded yet`};try{return await x.mutateAsync({addonId:d.addonId,type:d.type,key:n,value:r})}catch(e){return{status:`error`,error:e instanceof Error?e.message:String(e)}}}if(t===`refresh-probe`){if(!n.startsWith(`probedInfo:`))throw Error(`refresh-probe: unrecognised key "${n}" (expected "probedInfo:<streamId>")`);let t=n.slice(11);if(!t)throw Error(`refresh-probe: key "${n}" has no streamId after prefix`);let r=et(e,t),i=await b.mutateAsync({brokerId:r});return a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),i}if(t===`device-custom-action`){let t=await S.mutateAsync({deviceId:e,action:n,input:r});return a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),t}throw Error(`[device-aggregate] unknown action "${t}"`)}return q(Pn,{schema:_,values:E,pendingKeys:D,onChange:ee,onAction:ne,onSave:O,onDiscard:te,disabled:w.isPending,activeSubTab:n,onSubTabChange:r,flattenTabs:i,deviceId:e})}function $n({deviceId:e,activeSubTab:t,onSubTabChange:n}){return q(`div`,{className:`flex flex-col gap-3`,children:q(Qn,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}V();function er(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 tr(e){return e?e.enabled!==void 0||e.modelId!==void 0||e.settings!==void 0:!1}function nr(e,t){return t?{enabled:t.enabled??e.enabled,modelId:t.modelId??e.modelId,settings:t.settings??e.settings}:e}function rr({agents:e,currentAgent:t,onPick:n,hint:r}){let[i,a]=K(!1),o=e.filter(e=>e!==t);return o.length===0?null:H(`div`,{className:`relative`,children:[q(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>a(e=>!e),children:`Mirror from ▾`}),r&&q(`div`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:r}),i&&q(`div`,{className:`absolute top-full left-0 mt-1 min-w-[140px] bg-surface border border-border rounded shadow-lg z-10`,children:o.map(e=>q(`button`,{type:`button`,className:`w-full text-left px-3 py-1.5 text-xs hover:bg-muted`,onClick:()=>{a(!1),n(e)},children:e},e))})]})}function ir({deviceId:e,refreshToken:t}){let n=G(),r=X().trpcClient,[i,a]=K(null),[o,s]=K(null),[c,l]=K(null),u=Me({deviceId:e},{refetchOnMount:`always`}),d=P(void 0,{refetchOnMount:`always`});Yt([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let p=qe(void 0,{refetchOnMount:`always`}),m=U(()=>{let e=new Set;for(let t of p.data??[])t.isOnline&&e.add(t.id);return e},[p.data]),h=U(()=>(d.data??[]).filter(e=>m.has(e.nodeId)).map(e=>e.nodeId),[d.data,m]),g=h[0]??``,_=de({nodeId:g},{enabled:g!==``,refetchOnMount:`always`}),v=Je({enabled:h.length>0,queryKey:[[`pipelineExecutor`,`getSchema`],`device-step-formats`,h.join(`,`),t],queryFn:async()=>{let e={};for(let t of h)try{e[t]=(await r.pipelineExecutor.getSchema.query({nodeId:t})).selectedEngine.format}catch{e[t]=`coreml`}return e}}),y=He({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]})}}),x=U(()=>_.data?b(_.data):[],[_.data]),S=U(()=>{let e=d.data??[];return(m.size===0?[]:e.filter(e=>m.has(e.nodeId))).map(e=>({agentNodeId:e.nodeId,engineLabel:v.data?.[e.nodeId]??`(engine unknown)`}))},[d.data,v.data,m]),C=(e,t)=>(d.data?.find(t=>t.nodeId===e))?.settings.addonDefaults[t]??null,w=(e,t,n)=>e?.stepOverridesByAgent?.[t]?.[n]??null,T=(e,t)=>{let n=v.data?.[t];if(!er(_.data??null,e)?.models.some(e=>n!==void 0&&!!e.formats[n]))return{kind:`na`};let r=C(t,e);if(!r)return{kind:`na`};let i=w(u.data??null,t,e),a=tr(i),o=nr(r,i);return o.enabled?{kind:`enabled`,modelId:o.modelId??`Auto`,overridden:a}:{kind:`disabled`,overridden:a}},E=i&&_.data?er(_.data,i.addonId):null,ee=i?C(i.agentNodeId,i.addonId):null,O=i?v.data?.[i.agentNodeId]??`coreml`:`coreml`,ne=i?tr(w(u.data??null,i.agentNodeId,i.addonId)):!1,re=()=>{a(null),s(null),l(null)},k=(e,t)=>{a({addonId:e,agentNodeId:t}),s(w(u.data??null,t,e)),l(null)},A=e=>{if(!i||!_.data||!d.data)return;let t=d.data.find(t=>t.nodeId===e),n=d.data.find(e=>e.nodeId===i.agentNodeId);if(!t||!n)return;let[r]=Ve({source:{nodeId:t.nodeId,engine:{format:O},defaults:t.settings.addonDefaults},target:{nodeId:n.nodeId,engine:{format:O},defaults:n.settings.addonDefaults},catalog:_.data,addonIds:[i.addonId]});if(!r){l(`no mirror result`);return}if(r.outcome===`skip`){l(`skipped: ${r.reason??`no candidate`}`);return}s(r.patch),l(`${r.outcome} from ${e}`)},ie=()=>{i&&y.mutate({deviceId:e,agentNodeId:i.agentNodeId,addonId:i.addonId,patch:o},{onSuccess:re})},ae=()=>{i&&y.mutate({deviceId:e,agentNodeId:i.agentNodeId,addonId:i.addonId,patch:null},{onSuccess:re})};if(d.isLoading||g!==``&&_.isLoading)return q(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(S.length===0)return q(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`No online agents.`});if(!_.data)return q(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let oe=i!==null&&E!==null&&ee!==null,se=(d.data??[]).map(e=>e.nodeId);return H(`div`,{className:`relative h-full w-full space-y-3`,children:[H(`div`,{className:`flex items-center gap-3 text-[10px] text-foreground-subtle`,children:[H(`span`,{className:`inline-flex items-center gap-1`,children:[q(`span`,{className:`h-1.5 w-1.5 rounded-full bg-emerald-500`}),` inherited`]}),H(`span`,{className:`inline-flex items-center gap-1`,children:[q(`span`,{className:`h-1.5 w-1.5 rounded-full bg-amber-500`}),` override`]}),q(`span`,{children:`Click a cell to override this camera's step for that agent.`})]}),q(`div`,{className:oe?`md:pr-[360px]`:``,children:x.length>0?q(D,{tree:x,agents:S,getCellState:T,onCellClick:k,selectedCell:i}):q(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),q(te,{open:oe,onClose:re,title:E?.name??``,subtitle:i?`${i.agentNodeId} · ${O}`:``,footer:H(W,{children:[q(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle disabled:opacity-50`,disabled:!ne||y.isPending,onClick:ae,children:`Clear override`}),q(`div`,{className:`flex-1`}),q(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:re,children:`Cancel`}),q(`button`,{type:`button`,disabled:!i||y.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:ie,children:y.isPending?`Saving…`:`Save`})]}),children:E&&ee&&i&&H(`div`,{className:`space-y-4`,children:[q(rr,{agents:se,currentAgent:i.agentNodeId,onPick:A,hint:c}),q(f,{mode:`device`,addon:E,agentDefault:ee,agentNodeId:i.agentNodeId,currentPatch:o,engineFormat:O,onChangePatch:s})]})})]})}function $({label:e,value:t}){return H(`div`,{className:`${lt} flex items-start gap-2 sm:gap-3`,children:[q(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),q(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}V();function ar({deviceId:e,initialName:t}){let n=G(),[r,i]=K(!1),[a,o]=K(t),[s,c]=K(!1),l=B(null);J(()=>{r||o(t)},[t,r]),J(()=>{r&&l.current?.focus()},[r]);let u=Ke({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),d=async()=>{let n=a.trim();if(n.length===0||n===t){i(!1),o(t);return}c(!0);try{await u.mutateAsync({deviceId:e,name:n}),i(!1)}catch{}finally{c(!1)}},f=()=>{o(t),i(!1)};return r?q($,{label:`Name`,value:H(`div`,{className:`flex items-center gap-1`,children:[q(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?d():e.key===`Escape`&&f()},disabled:s,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`}),q(`button`,{type:`button`,onClick:()=>void d(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:q(jt,{className:`h-3 w-3`})}),q(`button`,{type:`button`,onClick:f,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:q(Rt,{className:`h-3 w-3`})})]})}):q($,{label:`Name`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[q(`span`,{className:`truncate`,children:t}),q(`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:q(St,{className:`h-3.5 w-3.5`})})]})})}V();function or({deviceId:e,initialLocation:t}){let n=G(),[r,i]=K(!1),[a,o]=K(t??``),[s,c]=K(!1),l=B(null),{data:u}=Se(void 0,{enabled:r}),d=u??[];J(()=>{r||o(t??``)},[t,r]),J(()=>{r&&l.current?.focus()},[r]);let f=ne({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),p=U(()=>{let e=a.trim().toLowerCase();return e.length===0?d:d.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[d,a]),m=a.trim().length>0&&!d.some(e=>e.toLowerCase()===a.trim().toLowerCase()),h=async n=>{let r=(n??a).trim(),o=r.length===0?null:r;if(o===(t??null)){i(!1);return}c(!0);try{await f.mutateAsync({deviceId:e,location:o}),i(!1)}catch{}finally{c(!1)}},g=()=>{o(t??``),i(!1)};return r?q($,{label:`Location`,value:H(`div`,{className:`relative`,children:[H(`div`,{className:`flex items-center gap-1`,children:[q(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?h():e.key===`Escape`&&g()},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`}),q(`button`,{type:`button`,onClick:()=>void h(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:q(jt,{className:`h-3 w-3`})}),q(`button`,{type:`button`,onClick:g,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:q(Rt,{className:`h-3 w-3`})})]}),(p.length>0||m)&&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:[p.map(e=>H(`button`,{type:`button`,onClick:()=>{o(e),h(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[q(_t,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),q(`span`,{className:`truncate`,children:e})]},e)),m&&H(`button`,{type:`button`,onClick:()=>void h(),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:[q(`span`,{className:`text-foreground-subtle`,children:`Create`}),H(`span`,{className:`font-medium truncate`,children:[`"`,a.trim(),`"`]})]})]})]})}):q($,{label:`Location`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[t?q(`span`,{className:`truncate`,children:t}):q(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),q(`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:q(St,{className:`h-3.5 w-3.5`})})]})})}V();function sr({deviceId:e}){let t=G(),{data:r}=xt(e),{data:a}=bt(e),[o,s]=K(null),c=i({onSuccess:()=>{s(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{s(`Could not change primary child: ${e.message}`)}});if(r==null||String(r.type??``)!==Y.Container)return null;let l=(a??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(l.length<=1)return null;let u=Re(l,typeof r.linkDeviceId==`number`?r.linkDeviceId:null,typeof r.primaryChildEntityId==`string`?r.primaryChildEntityId:null);return H(W,{children:[q($,{label:`Primary child`,value:q(n,{childrenList:l,selectedId:u===null?l[0].id:u.id,onSetPrimary:t=>c.mutate({deviceId:e,primaryChildEntityId:t}),disabled:c.isPending})}),o!==null&&q(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:o})]})}V();var cr=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function lr(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function ur(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function dr(){let e=E(),t=d(),{data:n}=R({deviceId:e??0},{enabled:e!==null}),{data:r}=Ue({deviceId:e??0},{enabled:e!==null}),i=n??t??null,[a,o]=K(`identity`);if(e===null||!i)return null;let s=String(i.stableId??``),c=String(i.name??``),l=String(i.type??``),u=String(i.addonId??``),f=i.features??[],p=new Set([`device-status`,`feature-probe`,`device-ops`]),m=(r?.entries??[]).filter(e=>e.kind===`native`&&!p.has(e.capName)).map(e=>e.capName),h=f.length>0?f:m,g=i.location??null,_=i.metadata??null,v=_!==null&&Object.keys(_).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:[q(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),v&&H(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[q(fr,{active:a===`identity`,onClick:()=>o(`identity`),label:`Identity`}),q(fr,{active:a===`hardware`,onClick:()=>o(`hardware`),label:`Hardware`})]})]}),(!v||a===`identity`)&&H(`div`,{className:`divide-y divide-border`,children:[q($,{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,`)`]})]})}),q(ar,{deviceId:e,initialName:c}),q(or,{deviceId:e,initialLocation:g}),q(sr,{deviceId:e}),q($,{label:`Type`,value:l}),q($,{label:`Provider`,value:q(gt,{type:u,size:`sm`,showLabel:!0})}),q($,{label:`Capabilities`,value:h.length>0?q(pt,{capabilities:h,showLabels:!0}):q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),v&&a===`hardware`&&q(pr,{metadata:_})]})}function fr({active:e,onClick:t,label:n}){return q(`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 pr({metadata:e}){let t=cr.filter(t=>t in e),n=Object.keys(e).filter(e=>!cr.includes(e)).toSorted(),r=[...t,...n];return H(`div`,{children:[q(`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.`}),q(`div`,{className:`divide-y divide-border`,children:r.map(t=>q($,{label:lr(t),value:q(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:ur(e[t])})},t))})]})}V();function mr({deviceId:e}){let[t,n]=K(null),r=Pe({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:[q(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),q(`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:[q(wt,{className:`h-3 w-3 ${r.isPending?`animate-spin`:``}`}),r.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&q(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}V();var hr={icon:``,label:``,unit:``,precision:``,hidden:!1};function gr(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function _r(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function vr(e){let t=e.precision.trim()===``?void 0:Number.parseInt(e.precision,10),n={...e.icon===``?{}:{icon:e.icon},...e.label.trim()===``?{}:{label:e.label.trim()},...e.unit===``?{}:{unit:e.unit},...t!==void 0&&Number.isFinite(t)?{precision:t}:{},...e.hidden?{hidden:!0}:{}};return Object.keys(n).length===0?null:n}function yr({deviceId:t}){let n=X(),r=G(),{data:i}=R({deviceId:t},{enabled:t>0}),a=typeof i?.role==`string`?i.role:null,o=a===null?void 0:me[a],s=o?.kind===`numeric`,c=ke(n.trpcClient,t,a??``),u=o?.kind===`numeric`?o.canonicalUnit:void 0,d=_r(c)??u,f=d===void 0?void 0:st(d),p=U(()=>f===void 0?[]:it(f),[f]),[m,h]=K(null),g=m??gr(i?.display),_=x({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:v}=l({},{staleTime:6e4}),y=j({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(i===void 0||a===null)return null;let b=e=>{h({...g,...e})},S=()=>{_.mutate({deviceId:t,display:vr(g)})},C=()=>{h(hr),_.mutate({deviceId:t,display:null})},w=()=>{let e={...g.icon===``?{}:{icon:g.icon},...g.unit===``?{}:{unit:g.unit},...g.precision.trim()!==``&&Number.isFinite(Number.parseInt(g.precision,10))?{precision:Number.parseInt(g.precision,10)}:{}},t={...v?.defaults??{},[a]:e};y.mutate({defaults:t})},T=ze(a).label,E=Object.keys(e);return H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[q(`div`,{className:`border-b border-border px-4 py-2`,children:q(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Display`})}),H(`div`,{className:`p-4 space-y-3`,children:[H(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Icon`}),H(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:g.icon,onChange:e=>b({icon:e.target.value}),children:[H(`option`,{value:``,children:[`Default (`,T,`)`]}),E.map(e=>q(`option`,{value:e,children:e},e))]})]}),H(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Label`}),q(`input`,{type:`text`,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:T,value:g.label,onChange:e=>b({label:e.target.value})})]}),s&&H(`div`,{className:`grid grid-cols-2 gap-3`,children:[H(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Unit`}),H(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:g.unit,onChange:e=>b({unit:e.target.value}),disabled:p.length===0,children:[H(`option`,{value:``,children:[`Source`,d?` (${d})`:``]}),p.map(e=>q(`option`,{value:e,children:e},e))]})]}),H(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Precision`}),q(`input`,{type:`number`,min:0,max:10,step:1,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:`inherit`,value:g.precision,onChange:e=>b({precision:e.target.value})})]})]}),H(`label`,{className:`flex items-center gap-2`,children:[q(`input`,{type:`checkbox`,checked:g.hidden,onChange:e=>b({hidden:e.target.checked})}),q(`span`,{className:`text-sm text-foreground`,children:`Hide from device lists`})]}),H(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[q(`button`,{type:`button`,className:`rounded bg-primary px-3 py-1 text-sm font-medium text-primary-foreground disabled:opacity-50`,onClick:S,disabled:_.isPending,children:`Save`}),q(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:C,disabled:_.isPending,children:`Reset`}),H(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:w,disabled:y.isPending,title:`Apply this unit / precision / icon as the default for every ${T} sensor`,children:[`Set as default for all `,T,` sensors`]})]})]})]})}function br(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function xr({device:e}){let t=At(),n=typeof e.id==`number`?e.id:null,r=String(e.type??``),i=r===Y.Camera,a=r===Y.Hub,o=typeof e.role==`string`&&e.role.length>0,s=e.features??[],c=s.includes(nt.Resyncable),{data:l}=S({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),u=l?.streams??{},d=Object.entries(u),f=s.includes(nt.DoorbellButton),p=Ie(f?{deviceId:n??void 0,historyLimit:10}:void 0),m=p.latest?Date.now()-p.latest.timestamp<3e4:!1;return H(`div`,{className:`space-y-5`,children:[a&&n!==null&&q(Ne,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&q(mr,{deviceId:n}),i&&n!==null&&q(A,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),f&&q(Be,{history:p.history,latestIsFresh:m}),i&&n!==null&&q(A,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),i&&d.length>0&&H(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[q(`div`,{className:`border-b border-border px-4 py-2`,children:q(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),q(`div`,{className:`divide-y divide-border`,children:d.map(([e,t])=>H(`div`,{className:`px-4 py-2.5`,children:[H(`div`,{className:`flex items-center gap-2 mb-2`,children:[q(Dt,{className:`h-3 w-3 text-foreground-subtle`}),q(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),H(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[q(Sr,{label:`Nominal`,value:br(t.nominalBitrateKbps??0)}),q(Sr,{label:`Observed`,value:br(t.observedBitrateKbps??0)}),q(Sr,{label:`Peak`,value:br(t.peakBitrateKbps??0)}),q(Sr,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),q(dr,{}),o&&n!==null&&q(yr,{deviceId:n})]})}function Sr({label:e,value:t,warning:n}){return H(`div`,{children:[q(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),q(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}V();function Cr(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function wr(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=Cr(r.value,t));return n}function Tr(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 Er(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 Dr(e){return e==null?`identity`:e.kind}function Or({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=K(()=>Dr(e)),[o,s]=K(()=>Tr(e,n)),[c,l]=K(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=K(()=>Er(e));J(()=>{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]),J(()=>{if(i===`identity`){t(void 0);return}if(i===`enum-map`){let e=wr(o,r),n=c===``?void 0:Cr(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(Tr(void 0,n)),e===`linear`&&d(Er(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:[q(`p`,{className:`text-[11px] font-medium text-foreground-subtle mb-1.5`,children:`Transform`}),q(`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:[q(`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:[q(`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:[q(`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`}),q(`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:[q(`option`,{value:``,children:`—`}),q(`option`,{value:`true`,children:`true`}),q(`option`,{value:`false`,children:`false`})]}):q(`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`&&q(`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`&&q(`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:[q(`label`,{className:`text-[10px] text-foreground-subtle/70 whitespace-nowrap`,children:`Fallback:`}),q(`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:[q(`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:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Scale`}),q(`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:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Offset`}),q(`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:[q(`input`,{type:`checkbox`,checked:u.useClamp,onChange:e=>d(t=>({...t,useClamp:e.target.checked})),className:`accent-primary`}),q(`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:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Min`}),q(`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:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Max`}),q(`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`})]})]})]})]})}var kr=`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`;function Ar({mode:e,idPrefix:t,labelPrefix:n,pickerDevices:r,value:i,onChange:a,search:o,onSearchChange:s}){let{data:c}=T({deviceId:i.sourceId??0},{enabled:i.sourceId!=null}),l=c?.caps??[],u=l.find(e=>e.cap===i.cap)?.fields??[],d=e=>{a(e,(l.find(t=>t.cap===e.cap)?.fields??[]).find(t=>t.path===e.fieldPath))},f=e=>{d({sourceId:e===``?null:Number(e),cap:``,fieldPath:``})},p=e=>{d({sourceId:i.sourceId,cap:e,fieldPath:``})},m=e=>{d({sourceId:i.sourceId,cap:i.cap,fieldPath:e})};return H(W,{children:[e===`global`&&s&&H(`div`,{children:[q(`label`,{htmlFor:`${t}-search`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Search devices`}),q(`input`,{id:`${t}-search`,type:`text`,value:o??``,placeholder:`Filter by name, stable id or #id`,onChange:e=>s(e.target.value),className:kr})]}),H(`div`,{children:[H(`label`,{htmlFor:`${t}-device`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[n,` device`]}),H(`select`,{id:`${t}-device`,value:i.sourceId??``,onChange:e=>f(e.target.value),className:kr,children:[q(`option`,{value:``,children:`— select a device —`}),r.map(e=>H(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),H(`div`,{children:[H(`label`,{htmlFor:`${t}-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[n,` cap`]}),H(`select`,{id:`${t}-cap`,value:i.cap,disabled:i.sourceId==null,onChange:e=>p(e.target.value),className:kr,children:[q(`option`,{value:``,children:`— select a cap —`}),l.map(e=>q(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),H(`div`,{children:[H(`label`,{htmlFor:`${t}-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[n,` field`]}),H(`select`,{id:`${t}-field`,value:i.fieldPath,disabled:i.cap===``,onChange:e=>m(e.target.value),className:kr,children:[q(`option`,{value:``,children:`— select a field —`}),u.map(e=>H(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]})}function jr(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 Mr(e){return e===null?`null`:typeof e==`number`?`number`:typeof e==`boolean`?`boolean`:`string`}function Nr(e){return e===null?``:String(e)}V();var Pr=`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`,Fr=`min, max, abs, round, floor, ceil, sqrt, pow, clamp, avg, sum, coalesce, age, convert`,Ir=0;function Lr(){return Ir+=1,`b${Ir}`}function Rr(e){return{key:Lr(),name:e,mode:`sibling`,sourceId:null,cap:``,fieldPath:``,search:``,literalType:`number`,literalText:``,sampleText:``}}function zr(e,t,n){if(e===null)return[Rr(`a`)];let r=[];for(let[i,a]of Object.entries(e.bindings)){if(a.kind===`literal`){r.push({...Rr(i),mode:`literal`,literalType:Mr(a.value),literalText:Nr(a.value)});continue}if(a.kind===`global`){r.push({...Rr(i),mode:`global`,sourceId:t.find(e=>e.stableId===a.sourceStableId)?.id??null,cap:a.cap,fieldPath:a.fieldPath});continue}r.push({...Rr(i),mode:`sibling`,sourceId:t.find(e=>e.stableId===`${n}-${a.sourceKey}`)?.id??null,cap:a.cap,fieldPath:a.fieldPath})}return r.length>0?r:[Rr(`a`)]}function Br(e,t,n){if(e.mode===`literal`){let t=jr(e.literalType,e.literalText);return t===null?null:{kind:`literal`,value:t.value}}let r=t.find(t=>t.id===e.sourceId);if(!r||e.cap===``||e.fieldPath===``)return null;if(e.mode===`global`)return{kind:`global`,sourceStableId:r.stableId,cap:e.cap,fieldPath:e.fieldPath};let i=`${n}-`,a=r.stableId.startsWith(i)?r.stableId.slice(i.length):``;return a===``?null:{kind:`field`,sourceKey:a,cap:e.cap,fieldPath:e.fieldPath}}function Vr(e){if(e.mode===`literal`)return jr(e.literalType,e.literalText)?.value??null;let t=e.sampleText.trim();if(t===``)return null;let n=Number(t);return Number.isFinite(n)?n:e.sampleText}function Hr({devices:e,siblings:t,targetDeviceId:n,containerStableId:r,initial:i,onChange:a}){let[o,s]=K(i?.expr??``),[c,l]=K(()=>zr(i,e,r)),u=U(()=>{let t={},n=c.length>0,i=new Set;for(let a of c){let o=a.name.trim();if(o===``||i.has(o)){n=!1;continue}i.add(o);let s=Br(a,e,r);if(s===null){n=!1;continue}t[o]=s}return{source:{kind:`expression`,expr:o,bindings:t},complete:n}},[c,o,e,r]),d=U(()=>$e({expr:u.source.expr,bindings:u.source.bindings}),[u.source]),f=U(()=>{if(o.trim()===``)return null;let e=Qe(o);return e.ok?null:e.error},[o]),p=U(()=>{if(u.source.expr.trim()===``)return null;let e={};for(let t of c){let n=t.name.trim();n!==``&&(e[n]=Vr(t))}return rt(u.source.expr,e,Date.now())},[u.source.expr,c]),m=u.complete&&d===null&&o.trim()!==``;J(()=>{a(m?u.source:null)},[m?JSON.stringify(u.source):`null`]);let h=e=>{let t=e.name.trim();return t===``?`required`:ot.test(t)?Xe.has(t)?`reserved`:tt.has(t)?`shadows builtin`:c.filter(e=>e.name.trim()===t).length>1?`duplicate`:null:`invalid name`},g=(e,t)=>{l(n=>n.map(n=>n.key===e?{...n,...t}:n))},_=()=>{c.length>=32||l(e=>[...e,Rr(Ur(e))])},v=e=>{l(t=>t.length<=1?t:t.filter(t=>t.key!==e))};return H(`div`,{className:`flex flex-col gap-3`,children:[H(`div`,{className:`flex flex-col gap-2`,children:[q(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Bindings`}),c.map((r,i)=>q(Wr,{row:r,ordinal:i+1,devices:e,siblings:t,targetDeviceId:n,nameError:h(r),onPatch:e=>g(r.key,e),onRemove:()=>v(r.key),canRemove:c.length>1},r.key)),q(`button`,{type:`button`,onClick:_,disabled:c.length>=32,className:`self-start px-2 py-1 rounded-md text-[11px] font-medium border border-border text-foreground-subtle hover:bg-surface-hover disabled:opacity-50`,children:`+ Add binding`})]}),H(`div`,{children:[q(`label`,{htmlFor:`link-expr-input`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Expression`}),q(`textarea`,{id:`link-expr-input`,value:o,rows:2,spellCheck:!1,placeholder:`e.g. clamp(avg(a, b) + 5, 0, 100)`,onChange:e=>s(e.target.value),className:`${Pr} font-mono resize-y`}),H(`p`,{className:`mt-1 text-[10px] text-foreground-subtle/60`,children:[`Functions: `,Fr]}),f&&q(`p`,{className:`mt-1 text-[10px] text-danger`,children:f}),f===null&&d&&q(`p`,{className:`mt-1 text-[10px] text-danger`,children:d})]}),H(`div`,{className:`rounded-md border border-border bg-surface/50 px-2 py-1.5`,children:[q(`span`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle/60`,children:`Preview`}),` `,p===null?q(`span`,{className:`text-[11px] text-foreground-subtle/60`,children:`enter an expression`}):p.ok?q(`span`,{className:`font-mono text-[11px] text-foreground`,children:JSON.stringify(p.value)}):q(`span`,{className:`font-mono text-[11px] text-danger`,children:p.error})]})]})}function Ur(e){let t=new Set(e.map(e=>e.name.trim()));for(let e=0;e<26;e++){let n=String.fromCharCode(97+e);if(!t.has(n))return n}return`b${e.length+1}`}function Wr({row:e,ordinal:t,devices:n,siblings:r,targetDeviceId:i,nameError:a,onPatch:o,onRemove:s,canRemove:c}){let l=e.search.trim().toLowerCase(),u=n.filter(e=>e.id===i?!1:l===``?!0:e.name.toLowerCase().includes(l)||e.stableId.toLowerCase().includes(l)||String(e.id).includes(l)),d=e.mode===`global`?u:r;return H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border/60 p-2`,children:[H(`div`,{className:`flex items-center gap-2`,children:[q(`input`,{type:`text`,"aria-label":`binding ${t} name`,value:e.name,placeholder:`name`,onChange:e=>o({name:e.target.value}),className:`${Pr} max-w-[8rem] font-mono`}),H(`select`,{"aria-label":`binding ${t} mode`,value:e.mode,onChange:e=>{let t=e.target.value;(t===`sibling`||t===`global`||t===`literal`)&&o({mode:t,sourceId:null,cap:``,fieldPath:``,search:``})},className:`${Pr} max-w-[9rem]`,children:[q(`option`,{value:`sibling`,children:`Sibling`}),q(`option`,{value:`global`,children:`Any device`}),q(`option`,{value:`literal`,children:`Literal`})]}),c&&q(`button`,{type:`button`,"aria-label":`remove binding ${t}`,onClick:s,className:`px-2 py-1 rounded-md text-[11px] text-danger hover:bg-surface-hover`,children:`✕`})]}),a&&H(`span`,{className:`text-[10px] text-danger`,children:[`name: `,a]}),e.mode===`literal`?H(`div`,{className:`flex items-center gap-2`,children:[H(`select`,{"aria-label":`binding ${t} literal type`,value:e.literalType,onChange:e=>{let t=e.target.value;(t===`string`||t===`number`||t===`boolean`||t===`null`)&&o({literalType:t,literalText:t===`boolean`?`true`:``})},className:`${Pr} max-w-[7rem]`,children:[q(`option`,{value:`string`,children:`string`}),q(`option`,{value:`number`,children:`number`}),q(`option`,{value:`boolean`,children:`boolean`}),q(`option`,{value:`null`,children:`null`})]}),e.literalType!==`null`&&q(`input`,{type:`text`,"aria-label":`binding ${t} literal value`,value:e.literalText,placeholder:e.literalType===`number`?`e.g. 42`:`value`,onChange:e=>o({literalText:e.target.value}),className:Pr})]}):H(W,{children:[q(Ar,{mode:e.mode,idPrefix:`binding-${t}`,labelPrefix:`Binding`,pickerDevices:d,value:{sourceId:e.sourceId,cap:e.cap,fieldPath:e.fieldPath},onChange:e=>o({sourceId:e.sourceId,cap:e.cap,fieldPath:e.fieldPath}),search:e.search,onSearchChange:e=>o({search:e})}),q(`input`,{type:`text`,"aria-label":`binding ${t} sample`,value:e.sampleText,placeholder:`sample value (preview only)`,onChange:e=>o({sampleText:e.target.value}),className:`${Pr} text-[10px]`})]})]})}V();function Gr(e,t,n){return(n===void 0?[e,t]:[e,n,t]).map(e=>e.replace(/[^a-z0-9]/gi,`-`)).join(`-`)}function Kr(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function qr(e,t){return t.find(t=>t.stableId===e)?.id??null}function Jr(e){return e==null?`sibling`:e.source.kind===`literal`?`literal`:e.source.kind===`global`?`global`:e.source.kind===`expression`?`expression`:`sibling`}function Yr(e){return e==null||e.source.kind!==`literal`?`string`:Mr(e.source.value)}function Xr(e){return e==null||e.source.kind!==`literal`?``:Nr(e.source.value)}function Zr({deviceId:e,parentDeviceId:t,deviceStableId:n,initial:r,onSave:i,onCancel:a}){let{data:o}=Ce({}),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}=T({deviceId:e,includeSynthesizable:!0}),d=u?.caps??[],f=r!=null&&(r.source.kind===void 0||r.source.kind===`field`)?r.source:null,p=r!=null&&r.source.kind===`global`?r.source:null,m=r!=null&&r.source.kind===`expression`?r.source:null,h=f==null?p==null?null:qr(p.sourceStableId,s):Kr(f.sourceKey,c,s),[g,_]=K(Jr(r)),[v,y]=K(r?.target.cap??``),[b,x]=K(r?.target.fieldPath??``),[S,C]=K(r?.target.itemKey??``),[w,E]=K(h),[D,ee]=K((f??p)?.cap??``),[O,te]=K((f??p)?.fieldPath??``),[ne,re]=K(void 0),[k,A]=K(``),[ie,ae]=K(Yr(r)),[oe,se]=K(Xr(r)),[ce,j]=K(m),[M,le]=K(r?.transform);J(()=>{if((f??p)==null||w!==null||s.length===0)return;let e=f==null?p==null?null:qr(p.sourceStableId,s):Kr(f.sourceKey,c,s);e!==null&&E(e)},[f,p,w,s,c]);let ue=d.find(e=>e.cap===v)?.fields??[],de=ue.find(e=>e.path===b),fe=de?.item===!0,N=k.trim().toLowerCase(),pe=s.filter(t=>t.id===e?!1:N===``?!0:t.name.toLowerCase().includes(N)||t.stableId.toLowerCase().includes(N)||String(t.id).includes(N)),me=g===`global`?pe:l,he=e=>{y(e),x(``),C(``)},ge=e=>{e!==`sibling`&&e!==`global`&&e!==`literal`&&e!==`expression`||(_(e),E(null),ee(``),te(``),re(void 0),A(``))},P=jr(ie,oe),_e=g===`literal`?P!==null:g===`expression`?ce!==null:w!=null&&D!==``&&O!==``,ve=v!==``&&b!==``&&(!fe||S.trim()!==``)&&_e,ye=()=>{if(g===`literal`)return P===null?null:{kind:`literal`,value:P.value};if(g===`expression`)return ce;let e=s.find(e=>e.id===w);if(!e||D===``||O===``)return null;if(g===`global`)return{kind:`global`,sourceStableId:e.stableId,cap:D,fieldPath:O};let t=`${c}-`;return{sourceKey:e.stableId.startsWith(t)?e.stableId.slice(t.length):``,cap:D,fieldPath:O}},be=()=>{if(!ve)return;let e=ye();if(e===null)return;let t=fe?S.trim():void 0;i({id:r?.id??Gr(v,b,t),source:e,target:{cap:v,fieldPath:b,...t===void 0?{}:{itemKey:t}},...M==null?{}:{transform:M}})},F=`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:[q(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Target (this device)`}),H(`div`,{children:[q(`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=>he(e.target.value),className:F,children:[q(`option`,{value:``,children:`— select a cap —`}),d.map(e=>q(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),H(`div`,{children:[q(`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:F,children:[q(`option`,{value:``,children:`— select a field —`}),ue.map(e=>q(`option`,{value:e.path,children:e.item===!0?`${e.path} (per item, ${e.kind})`:`${e.path} (${e.kind})`},e.path))]})]}),fe&&H(`div`,{children:[q(`label`,{htmlFor:`link-target-item-key`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Item key`}),q(`input`,{id:`link-target-item-key`,type:`text`,value:S,placeholder:`e.g. main-brush`,onChange:e=>C(e.target.value),className:F}),q(`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:[q(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Source`}),H(`div`,{children:[q(`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=>ge(e.target.value),className:F,children:[q(`option`,{value:`sibling`,children:`Sibling device (same container)`}),q(`option`,{value:`global`,children:`Any device`}),q(`option`,{value:`literal`,children:`Literal constant`}),q(`option`,{value:`expression`,children:`Expression (computed)`})]})]}),g===`literal`&&H(W,{children:[H(`div`,{children:[q(`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:ie,onChange:e=>{let t=e.target.value;(t===`string`||t===`number`||t===`boolean`||t===`null`)&&(ae(t),t===`boolean`&&se(`true`),t===`null`&&se(``))},className:F,children:[q(`option`,{value:`string`,children:`string`}),q(`option`,{value:`number`,children:`number`}),q(`option`,{value:`boolean`,children:`boolean`}),q(`option`,{value:`null`,children:`null`})]})]}),ie!==`null`&&(ie===`boolean`?H(`div`,{children:[q(`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:oe,onChange:e=>se(e.target.value),className:F,children:[q(`option`,{value:`true`,children:`true`}),q(`option`,{value:`false`,children:`false`})]})]}):H(`div`,{children:[q(`label`,{htmlFor:`link-literal-value`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal value`}),q(`input`,{id:`link-literal-value`,type:`text`,value:oe,placeholder:ie===`number`?`e.g. 42`:`e.g. main-brush`,onChange:e=>se(e.target.value),className:F})]}))]}),g===`expression`&&q(Hr,{devices:s,siblings:l,targetDeviceId:e,containerStableId:c,initial:m,onChange:j}),(g===`sibling`||g===`global`)&&q(Ar,{mode:g,idPrefix:`link-source`,labelPrefix:`Source`,pickerDevices:me,value:{sourceId:w,cap:D,fieldPath:O},onChange:(e,t)=>{E(e.sourceId),ee(e.cap),te(e.fieldPath),re(t)},search:k,onSearchChange:A})]}),q(Or,{value:M,onChange:le,sourceField:g===`literal`||g===`expression`?void 0:ne,targetKind:de?.kind}),H(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[q(`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`}),q(`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 Qr({deviceId:e}){let t=X(),n=G(),r=Number.isFinite(e),{data:i,isLoading:a}=R({deviceId:e},{enabled:r,refetchInterval:1e4}),{data:o}=T({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=_({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]=K(null),m=t=>{c.mutate({deviceId:e,deviceLinks:l.filter(e=>e.id!==t)})};return a?q(`div`,{className:`p-4`,children:q(`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:[q(`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:[q(Ct,{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:[q(tn,{className:`h-8 w-8 opacity-30`}),q(`p`,{className:`text-xs`,children:`No links yet.`}),q(`p`,{className:`text-[10px] opacity-60`,children:`Cross-device field wirings will appear here once authored.`})]}):q(`div`,{className:`flex flex-col divide-y divide-border rounded-lg border border-border overflow-hidden`,children:l.map(n=>q(ei,{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:[q(`div`,{className:`flex items-center justify-between`,children:q(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:f===`new`?`Add link`:`Edit link`})}),q(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:q(Zr,{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 $r(e,t,n,r){let i=at(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:at(a,r)}function ei({deviceId:e,link:t,itemArray:n,trpcClient:r,onDelete:i,onEdit:a,isPending:o}){let s=ke(r,e,t.target.cap),c=t.target.itemKey,l=s===void 0?void 0:c!==void 0&&n!==void 0?$r(s,n,c,t.target.fieldPath):c===void 0?at(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:[q(nn,{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:[q(`span`,{className:`font-mono text-[11px] font-medium text-foreground`,children:t.target.cap}),q(`span`,{className:`text-[10px] text-foreground-subtle/60`,children:`.`}),q(`span`,{className:`font-mono text-[11px] text-foreground-subtle`,children:t.target.fieldPath}),c!==void 0&&q(`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:[q(`span`,{children:`←`}),t.source.kind===`literal`?H(`span`,{className:`font-mono`,children:[`literal: `,String(t.source.value)]}):t.source.kind===`expression`?H(W,{children:[H(`span`,{className:`font-mono`,title:t.source.expr,children:[`ƒ`,` `,t.source.expr.length>40?`${t.source.expr.slice(0,40)}…`:t.source.expr]}),H(`span`,{className:`rounded bg-surface-hover px-1 py-px font-mono text-[9px] text-foreground-subtle`,title:`Number of source bindings`,children:[Object.keys(t.source.bindings).length,` bindings`]})]}):H(W,{children:[q(`span`,{className:`font-mono`,children:t.source.kind===`global`?t.source.sourceStableId:t.source.sourceKey}),q(`span`,{className:`opacity-60`,children:`/`}),q(`span`,{className:`font-mono`,children:t.source.cap}),q(`span`,{className:`opacity-60`,children:`.`}),q(`span`,{className:`font-mono`,children:t.source.fieldPath})]})]})]}),t.transform&&q(ti,{kind:t.transform.kind}),q(`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}),q(`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`}),q(`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 ti({kind:e}){return q(`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 ni=[{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 ri(e){let t=e===Y.Camera;return ni.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var ii=[{id:`logs`,icon:Bt,label:`Logs`},{id:`repl`,icon:Lt,label:`REPL`},{id:`events`,icon:Pt,label:`Events`},{id:`state`,icon:Ot,label:`State`}];function ai(){let e=Vt(),t=Number(e.deviceId),n=Number.isFinite(t),i=At(),a=G(),l=ie(),d=X(),[f,p]=kt(),m=f.get(`tab`)??`overview`,g=f.get(`sub`),[_,v]=K(`logs`),y=`device-detail.left-col-width-px`,[b,x]=K(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(y),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),S=B(b);S.current=b;function w(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??b??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{x(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=S.current;if(e!==null)try{window.localStorage.setItem(y,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:E,isLoading:D,isError:O}=R({deviceId:t},{enabled:n,refetchInterval:5e3,retry:1}),{data:te}=ae({deviceId:t},{enabled:n}),ne=U(()=>{let e=te?.settings?.sections??[],t=te?.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(zn)&&r.add(In),[...r].map(e=>e===`export`?{id:e,label:Ln,isAddonContrib:!0}:{id:e,label:Ze[e]?.label??e,isAddonContrib:!0})},[te]),k=E,A=String(k?.name??e.deviceId??`Device`),se=k?.online===!0,ce=se?`online`:`offline`,j=String(k?.addonId??`rtsp`),M=k?.features??[],le=k?.type,de=le===Y.Camera,{data:N}=bt(n?t:0),pe=le===Y.Container,me=U(()=>(N??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[N]),P=U(()=>pe?Re(me,typeof k?.linkDeviceId==`number`?k.linkDeviceId:null,typeof k?.primaryChildEntityId==`string`?k.primaryChildEntityId:null)?.id??null:null,[pe,me,k?.linkDeviceId,k?.primaryChildEntityId]),{data:_e}=ae({deviceId:P??0},{enabled:P!==null}),ve=U(()=>{if(P===null)return[];let e=_e?.settings?.sections??[],t=_e?.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:Ze[e]?.label??e,isAddonContrib:!0,childDeviceId:P}))},[P,_e]),ye=typeof k?.parentDeviceId==`number`?k.parentDeviceId:null,{data:F}=R({deviceId:ye??0},{enabled:ye!==null}),I=oe(),xe=k?.disabled!==!0,{data:Se}=T({deviceId:t},{enabled:n}),Ce=(Se?.caps.length??0)>0,Ee=U(()=>{let e=new Set,t=[];for(let n of[...ri(le),...ne,...ve])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!Ce)&&t.push(n));return t},[le,ne,ve,Ce]),De=U(()=>Ee.some(e=>e.id===m)?m:`overview`,[Ee,m]),Oe=z(e=>{p(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[p]),ke=z(e=>{p(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[p]),Ae=(N??[]).length>0,Me=U(()=>ii.filter(({featureGate:e})=>!e||M.includes(e)),[M]),{data:L}=ge({addonId:j},{enabled:!!j&&j!==`rtsp`}),Ne=ee({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]}),i(L?.id?`/integrations/${L.id}`:`/integrations`)}}),Pe=he({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=be({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=h(),Le=o({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ze=M.includes(nt.Rebootable),Be=M.includes(nt.BatteryOperated),Ve=fe(d.trpcClient,Be&&n?t:null),[He,Ue]=K(!1),We=ct(d.trpcClient,n?t:null),Ge=async()=>{if(!(He||!We)){Ue(!0);try{await We.snapshot?.invalidateCache({});let e=await We.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=A.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{Ue(!1)}}},Ke=Pe.isPending||Fe.isPending,{data:qe}=Te({deviceId:t},{enabled:n,refetchInterval:1e4}),V=qe?.agentNodeId??null,Je=typeof V==`string`&&V.length>0&&!V.startsWith(`addon:`)?V:void 0,{data:W}=c({deviceId:t,...Je?{nodeId:Je}:{}},{enabled:n,refetchInterval:3e3,retry:!1}),{data:Ye}=re({deviceId:t},{enabled:n,refetchInterval:3e3,retry:!1}),J=Ye?.level?.dbfs??null;function Xe(){if(!n)return null;switch(De){case`overview`:return q(xr,{device:k??{}});case`config`:return q($n,{deviceId:t,activeSubTab:g,onSubTabChange:ke});case`pipeline`:return q(ir,{deviceId:t,refreshToken:0});case`bindings`:return q(An,{deviceId:t});case`wiring`:return q(Qr,{deviceId:t});default:{let e=De,n=ne.some(t=>t.id===e),r=ve.find(t=>t.id===e);if(!n&&r===void 0)return null;let i=r?.childDeviceId??t;if(e===`export`)return q(Qn,{deviceId:t,sectionFilter:zn,activeSubTab:g,onSubTabChange:ke});let a=q(Qn,{deviceId:i,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:g,onSubTabChange:ke});return r!==void 0&&i!==t?q(C,{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:[q(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),q(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),q(`div`,{className:`flex-1 p-6`,children:q(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):O||!E?H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[q(`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]})]}),q(`button`,{onClick:()=>i(`/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:[q(`div`,{className:`mb-2`,children:q(r,{items:[{label:`Integrations`,onClick:()=>i(`/integrations`)},{label:L?.name??j,onClick:()=>L?.id&&i(`/integrations/${L.id}`)},{label:A}]})}),H(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[q(gt,{type:j,size:`lg`}),H(`div`,{className:`min-w-0 flex-1`,children:[H(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[q(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:A}),q(Jt,{status:ce}),Be&&q(ue,{status:Ve,variant:`full`})]}),ye!==null&&F&&H(`button`,{type:`button`,onClick:()=>i(`/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 ${F.name}`,children:[q(`span`,{children:`↑`}),q(`span`,{className:`truncate`,children:String(F.name??`Device #${ye}`)})]}),q(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:M.length>0&&q(pt,{capabilities:M})})]}),W&&q(`div`,{className:`hidden lg:flex`,children:q(oi,{metrics:W,dbfs:J})}),H(`div`,{className:`flex items-center gap-1 shrink-0`,children:[H(`button`,{onClick:async()=>{xe?await l({title:`Disable "${A}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Fe.mutate({deviceId:t}):Pe.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:[q(rn,{className:`h-3.5 w-3.5`}),q(`span`,{className:`hidden sm:inline`,children:Ke?`Updating…`:xe?`Enabled`:`Disabled`})]}),q(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),q(we,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:qt,disabled:He,onClick:()=>{Ge()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:Tt,hidden:!ze,disabled:Ie.isPending,danger:!0,onClick:async()=>{await l({title:`Reboot "${A}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Ie.mutate({deviceId:t})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${L?.name??j}.`,icon:wt,disabled:Le.isPending,danger:!0,onClick:async()=>{await l({title:`Restart "${L?.name??j}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${A}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Le.mutate({addonId:j})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:Ut,separatorBefore:!0,disabled:Ne.isPending,danger:!0,onClick:async()=>{await l({title:`Delete "${A}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Ne.mutate({deviceId:t})}}]})]})]})]}),q(C,{deviceId:t,device:k??void 0,children:q(s,{children:q(u,{children:q(dt,{children:q(je,{children:H(`main`,{className:I?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[H(`div`,{className:I?`flex flex-col bg-surface`:`${b===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!I&&b!==null?{width:`${String(b)}px`}:void 0,children:[q(`div`,{className:de?`flex-shrink-0 border-b border-border-subtle bg-black`:I?`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:de?q(Tn,{deviceId:t,intercomAvailable:M.includes(nt.TwoWayAudio)}):q(gn,{deviceId:t,deviceName:A,deviceType:le??`unknown`,provider:j,isOnline:se,features:M})}),H(`div`,{className:I?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[q(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:q(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:Me.map(({id:e,label:t,icon:n})=>H(`button`,{onClick:()=>v(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${_===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[q(n,{className:`h-3 w-3`}),t]},e))})}),H(`div`,{className:I?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[_===`logs`&&q(En,{deviceId:t,containerDeviceId:le===`container`?t:void 0}),_===`repl`&&q(Dn,{deviceId:t}),_===`events`&&q(On,{deviceId:t}),_===`state`&&q(kn,{deviceId:t})]})]})]}),!I&&q(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:w,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:q(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),H(`div`,{className:I?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[q(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:q(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:Ee.map(e=>{let t=De===e.id;return H(`button`,{onClick:()=>Oe(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&&q(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),H(`div`,{className:I?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[De===`overview`&&Ae&&q(on,{parentDeviceId:t}),Xe()]})]})]})})})})})})]}):H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[q(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),H(`p`,{className:`text-xs`,children:[`The URL segment`,` `,q(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:e.deviceId}),` `,`is not a number.`]}),q(`button`,{onClick:()=>i(`/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 oi({metrics:e,dbfs:t}){let n=Ee(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:[q(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),q(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),q(`div`,{className:`h-3 w-px bg-border`}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[q(Nt,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),q(`span`,{children:`fps`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[q(zt,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),q(`span`,{children:`ms`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[q(an,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),q(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&H(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{ai as DeviceDetailPage};
@@ -1 +0,0 @@
1
- import{G as e,Gr as t,Hr as n,Ja as r,Ma as i,Ur as a,Vr as o,Wr as s,Ya as c,io as l,kn as u,kr as d,xa as f,yt as p}from"./src-P2A2VEVG.js";import{I as m,K as h,Q as g,S as _,W as v,b as y,i as b,o as x,q as S,x as C,z as w}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{H as T,s as E,w as D}from"./src-DNVzx9ag.js";import{p as O}from"./player-overlays-CDSEY_-X.js";import{t as k}from"./clock-D2H-Andr.js";import{t as A}from"./copy-DAnlpNmN.js";import{a as j,c as M,d as ee,f as N,i as P,m as F,n as te,o as ne,p as I,r as re,s as ie,t as L}from"./debounced-invalidate-DkqNPsSh.js";import{t as R}from"./search-DvkKd5B0.js";import{t as z}from"./square-check-big-BsYa2Tzh.js";import{t as B}from"./square-CzYy8xOt.js";import{E as V,I as H,L as ae,P as oe,S as U,U as W,W as G,i as se,s as ce}from"./index-BVO5AjpN.js";import{t as le}from"./AdminPage-BwmGKnRf.js";import{r as ue,t as K}from"./authed-media-XfBD4Ma-.js";var q=G(`arrow-down-wide-narrow`,[[`path`,{d:`m3 16 4 4 4-4`,key:`1co6wj`}],[`path`,{d:`M7 20V4`,key:`1yoxec`}],[`path`,{d:`M11 4h10`,key:`1w87gc`}],[`path`,{d:`M11 8h7`,key:`djye34`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}]]),de=G(`square-parking`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 17V7h4a3 3 0 0 1 0 6H9`,key:`1dfk2c`}]]);g();var fe=720*60*60*1e3;function pe(e){let t=[];for(let n of e)t.push(...n);return t}function me(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function he(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function J(e,t){return`${String(e)}:${t}`}function ge(e,t){let n=new Map,r=new Set;for(let i of e){let e=J(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function _e(e,t){return{since:e.fromMs??t-fe,until:e.toMs??t}}var Y=typeof o==`function`,ve=`Track deletion arrives with the next server update`;function ye(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var be=Y?o:ye,xe=200,Se=3e4;function Ce(e){let t=O(),n=b({queries:e.deviceIds.map(n=>({queryKey:[`events-feed`,n,e.since,e.until,e.minImportance??null,e.classFilter??null],staleTime:Se,refetchInterval:Se,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEvents.query({deviceId:n,since:e.since,until:e.until,limit:xe,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>({...e,deviceId:n}))}))});return{rows:me(pe(n.map(e=>e.data??[])),`importance`),isLoading:n.some(e=>e.isLoading)}}var we=[`events-feed`],Te=2e3;function Ee(){let e=x(),t=h(e);t.current=e;let n=h(void 0);n.current||=L({delayMs:Te,invalidate:()=>{t.current.invalidateQueries({queryKey:we})}}),w(()=>()=>n.current?.cancel(),[]),i(T.PipelineAnalyticsDetectionEvent,()=>{n.current?.trigger()}),i(T.PipelineAnalyticsTrackEnded,()=>{n.current?.trigger()})}var X=100,De=120,Oe={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Z=e=>e<0?0:e>1?1:e,Q=e=>Math.round(e*100)/100;function ke(e,t){if(e.length<=t)return[...e];let n=(e.length-1)/(t-1),r=[];for(let i=0;i<t;i++)r.push(e[Math.round(i*n)]);return r[r.length-1]=e[e.length-1],r}function Ae(e,t,n){if(e.length===0||t===null)return Oe;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return Oe;let a=ke(e,n?.maxPoints??De).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X),mediaKey:e.mediaKey})),u=null,d=-1;for(let t of e){let e=Z(t.bbox.w/r)*Z(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Q(Z(u.bbox.x/r)*X),y:Q(Z(u.bbox.y/i)*X),w:Q(Z(u.bbox.w/r)*X),h:Q(Z(u.bbox.h/i)*X)}:null}}var je={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`};function Me(e){return e in je}function Ne(e){return Me(e)?je[e]:e}function Pe(e,t){return`${e}${K}/${encodeURIComponent(t)}`}g();var Fe=1400,Ie=`Admin-gated URL — opens only inside an authenticated session`;function Le({label:e,value:t,title:n}){let[r,i]=S(!1);return w(()=>{if(!r)return;let e=setTimeout(()=>i(!1),Fe);return()=>clearTimeout(e)},[r]),_(`button`,{type:`button`,onClick:m(()=>{(async()=>{try{await navigator.clipboard.writeText(t),i(!0)}catch{window.prompt(`Copy the media URL:`,t)}})()},[t]),title:n,"aria-label":`Copy ${e} URL`,className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${r?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[C(r?ae:A,{className:`h-2.5 w-2.5 shrink-0`}),C(`span`,{className:`truncate`,children:r?`Copied`:e})]})}function Re({localUrl:e,publicUrl:t}){return _(`div`,{className:`flex flex-wrap gap-1`,children:[C(Le,{label:`Local`,value:e,title:`Copy LAN URL — ${Ie}`}),t&&C(Le,{label:`Public`,value:t,title:`Copy public URL — ${Ie}`})]})}g();var ze=3e4;function Be(e){let[t,n]=S(null),r=m(e=>{n(t=>t??e)},[]);return w(()=>{e||n(null)},[e]),{publicOrigin:t,probes:e?C(Ve,{onOrigin:r}):null}}function Ve({onOrigin:e}){let{data:t}=p({capName:`network-access`});return C(y,{children:(t??[]).map(t=>C(He,{addonId:t.addonId,onOrigin:e},t.addonId))})}function He({addonId:e,onOrigin:t}){let{data:n}=d({addonId:e},{refetchInterval:ze,retry:!1});return w(()=>{let e=n?E.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}g();var Ue=15e3,We=window.location.origin,Ge=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),Ke=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]);function qe(e){let[t,n]=S(null);return w(()=>{if(n(null),!e)return;let t=!1,r=new Image;return r.onload=()=>{t||n({width:r.naturalWidth,height:r.naturalHeight})},r.src=e,()=>{t=!0,r.onload=null}},[e]),t}function Je({overlay:e,onPickSnapshot:t}){return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:_(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&C(`rect`,{x:e.peakBox.x,y:e.peakBox.y,width:e.peakBox.w,height:e.peakBox.h,fill:`none`,stroke:`#f59e0b`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),e.polyline&&C(`polyline`,{points:e.polyline,fill:`none`,stroke:`#38bdf8`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),e.points.map((e,t)=>C(`circle`,{cx:e.x,cy:e.y,r:1,fill:`#38bdf8`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),e.snapshots.map((e,n)=>C(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`#0ea5e9`,fillOpacity:.95,stroke:`#082f49`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:t?`pointer-events-auto cursor-pointer`:void 0,onClick:t?n=>{n.stopPropagation(),t(e.mediaKey)}:void 0,children:C(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${e.mediaKey}-${String(n)}`)),e.start&&C(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`#22c55e`,stroke:`#052e16`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&C(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`#ef4444`,stroke:`#450a0a`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function $({label:e,value:t,mono:n}){return _(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[C(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),C(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function Ye({row:e,cameraName:t,deleteAvailable:i,onClose:o,onDeleted:u}){let d=O(),p=be(),h=e!==null,g=e?.deviceId??0,b=e?.trackId??``,x=e?.bestEventId??``,T=e?.timestamp??0,E=e?.windowMs??0,{data:D}=a({deviceId:g,trackId:b},{enabled:h}),{data:k}=s({trackId:b},{enabled:h}),{data:A}=n({eventId:x},{enabled:h&&x!==``}),{data:j}=f({deviceId:g,since:T-Ue,until:T+E+Ue},{enabled:h}),[M,N]=S(null),[te,ne]=S(!1),{publicOrigin:re,probes:ie}=Be(h);w(()=>{N(null)},[g,b]);let L=v(()=>{let e=k??[],t=A??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[k,A]),R=ue(L?`${K}/${encodeURIComponent(L.key)}`:void 0),z=v(()=>{let e=new Set,t=[];for(let n of[...A??[],...k??[]])!n.base64||e.has(n.key)||(e.add(n.key),t.push(n));return t},[A,k]),B=v(()=>z.find(e=>Ge.has(e.kind))??null,[z]),H=qe(B?`data:image/jpeg;base64,${B.base64}`:null),ae=v(()=>Ae(D?.positions??[],H,{snapshots:(D?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaKey:e.mediaKey}))}),[D?.positions,D?.snapshots,H]),oe=m(e=>{let t=z.find(t=>t.key===e);t&&N(t)},[z]);if(e===null)return null;let W=M?`data:image/jpeg;base64,${M.base64}`:R.src,G=M?.kind??L?.kind,le=G!==void 0&&Ke.has(G)&&H!==null&&(D?.positions.length??0)>=2,q=j&&j.length>0?j[0]:null,de=()=>{q&&(ne(!0),(async()=>{try{let t=await d.trpcClient.videoclips.getClipPlayback.query({deviceId:e.deviceId,clipId:q.id});window.open(t.playbackUrl,`_blank`,`noopener`)}catch{window.alert(`Could not resolve clip playback. Check the server logs.`)}finally{ne(!1)}})())},fe=()=>{!i||p.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await p.mutateAsync({deviceId:e.deviceId,trackIds:[e.trackId]}),u()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},pe=Math.round(e.importance*100),me=D?.importanceReason?`${String(pe)}% · ${D.importanceReason}`:`${String(pe)}%`,he=D?.zonesVisited&&D.zonesVisited.length>0?D.zonesVisited.join(`, `):`—`,J=D?.audioLabels&&D.audioLabels.length>0?D.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,ge=D?D.totalDistance.toFixed(2):`—`,_e=I(D?D.firstSeen:T),Y=D?I(D.lastSeen):`—`;return C(r,{open:!0,onOpenChange:e=>!e&&o(),children:_(c,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Event detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[_(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[_(`div`,{className:`min-w-0`,children:[_(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[e.className,e.label?_(`span`,{className:`text-foreground-subtle`,children:[` · `,e.label]}):null]}),C(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),C(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:C(se,{className:`h-4 w-4`})})]}),_(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[W?C(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:C(P,{src:W,alt:`Key frame from ${t}`,fit:`natural`,className:`w-full`,overlay:le?C(Je,{overlay:ae,onPickSnapshot:oe}):void 0})}):C(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:R.failed?_(y,{children:[C(F,{className:`h-8 w-8 opacity-60`}),C(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):C(U,{className:`h-6 w-6 animate-spin opacity-70`})}),z.length>0&&C(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:z.map(e=>{let t=`data:image/jpeg;base64,${e.base64}`,n=Ne(e.kind),r=Pe(We,e.key),i=re?Pe(re,e.key):null;return _(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[C(`button`,{type:`button`,onClick:()=>N(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${n} · ${I(e.timestamp)}`,children:C(`img`,{src:t,alt:n,className:`h-full w-full object-cover`})}),_(`figcaption`,{className:`min-w-0 px-0.5`,children:[C(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:n,children:n}),C(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:I(e.timestamp),children:ee(e.timestamp)})]}),C(Re,{localUrl:r,publicUrl:i})]},e.key)})}),ie,q&&_(l,{variant:`secondary`,onClick:de,disabled:te,children:[te?C(U,{className:`h-3.5 w-3.5 animate-spin`}):C(V,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),_(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[C($,{label:`Camera`,value:t}),C($,{label:`Class`,value:e.className}),C($,{label:`Label`,value:e.label??`—`}),C($,{label:`Importance`,value:me}),C($,{label:`Zones visited`,value:he}),C($,{label:`Audio heard`,value:J}),C($,{label:`Total distance`,value:ge}),C($,{label:`First seen`,value:_e}),C($,{label:`Last seen`,value:Y}),C($,{label:`Track`,value:e.trackId,mono:!0})]})]}),C(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:C(`span`,{title:i?void 0:ve,children:_(l,{variant:`secondary`,onClick:fe,disabled:!i||p.isPending,children:[p.isPending?C(U,{className:`h-3.5 w-3.5 animate-spin`}):C(ce,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}function Xe(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function Ze({row:e,cameraName:t,nowMs:n,onOpenDetail:r,selected:i=!1,onToggleSelect:a,score:o}){let s=ue(e.bestEventId?`${K}/${e.bestEventId}`:void 0),c=Math.round(e.importance*100),l=o===void 0?void 0:Math.round(o*100),u=Xe(e.windowMs),d=()=>r(e);return _(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[_(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[s.src?C(`img`,{src:s.src,alt:`Event from ${t}`,onClick:d,className:`h-full w-full cursor-zoom-in object-cover`}):C(`button`,{type:`button`,onClick:d,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:s.failed?`Key-event media unavailable`:`No key-event media`,children:C(F,{className:`h-6 w-6 opacity-60`})}),a&&C(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(J(e.deviceId,e.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Deselect`:`Select`,children:i?C(z,{className:`h-4 w-4 text-primary`}):C(B,{className:`h-4 w-4`})}),l!==void 0&&_(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:`CLIP semantic-match score`,children:[String(l),`%`]}),c>0&&C(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(c)})]}),_(`button`,{type:`button`,onClick:d,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[_(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,e.label?_(`span`,{className:`text-foreground-subtle`,children:[` · `,e.label]}):null]}),C(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),_(`div`,{className:`flex items-center justify-between gap-2`,children:[C(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:N(e.timestamp,n)}),u&&C(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:u})]})]})]})}g();var Qe=[`events-feed`],$e=60,et=[`person`,`vehicle`,`animal`],tt=[{value:`importance`,label:`Importance`,icon:q},{value:`time`,label:`Recent`,icon:k}];function nt(){let e=x(),[t,n]=S(ie),[r,i]=S(new Set),[a,o]=S(new Set),[s,c]=S(0),[d,f]=S(`time`),[p,m]=S(new Set),[h,g]=S(null),[b,T]=S(()=>Date.now());w(()=>{let e=setInterval(()=>T(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:E,until:O}=v(()=>_e({fromMs:t.fromMs,toMs:t.toMs},b),[t.fromMs,t.toMs,b]);Ee();let{data:k}=u({}),A=v(()=>(k??[]).filter(e=>e.type===D.Camera),[k]),ee=v(()=>A.map(e=>e.id),[A]),N=be(),P=N.isPending,{rows:F,isLoading:I}=Ce({deviceIds:ee,since:E,until:O,minImportance:s>0?s:void 0,classFilter:a.size===1?[...a][0]:void 0}),L=v(()=>{let e=new Map;for(let t of A??[])e.set(t.id,t.name);return e},[A]),R=e=>L.get(e)??`Camera #${String(e)}`,z=v(()=>M(F).map(e=>({id:e,name:R(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[F,L]),B=v(()=>me(he(F,{cameras:r,classes:a,minImportance:s}),d),[F,r,a,s,d]),V=te(B,$e,v(()=>JSON.stringify([[...r].sort((e,t)=>e-t),[...a].sort(),s,d,E,O]),[r,a,s,d,E,O])),H=()=>{e.invalidateQueries({queryKey:Qe})},ae=()=>m(new Set);function oe(e){m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function W(e){o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function G(){if(p.size===0||!Y)return;let e=ge(F,p),t=[...e.values()].reduce((e,t)=>e+t.length,0);if(t===0||!window.confirm(`Delete ${String(t)} track${t===1?``:`s`} and all their media? This cannot be undone.`))return;let n=[...e];Promise.allSettled(n.map(([e,t])=>N.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{H();let t=[],r=new Set;if(e.forEach((e,i)=>{let a=n[i];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)r.add(J(o,e));else t.push(o)}),m(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),t.length>0){let e=t.map(e=>R(e)).join(`, `);window.alert(`Failed to delete tracks on: ${e}. They remain selected — retry, or check the server logs.`)}})}let le=B.length!==F.length;return _(`div`,{className:`relative space-y-3`,children:[_(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[C(j,{onChange:n}),C(ne,{cameras:z,selected:r,onChange:i}),C(`div`,{className:`flex items-center gap-1`,children:et.map(e=>C(`button`,{type:`button`,onClick:()=>W(e),className:`rounded-md px-2.5 py-1 text-xs capitalize transition-colors ${a.has(e)?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e},e))}),_(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[C(`span`,{children:`Min score`}),C(`input`,{type:`range`,min:0,max:1,step:.05,value:s,onChange:e=>c(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),C(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(s*100)})]}),C(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:tt.map(e=>{let t=e.icon;return _(`button`,{type:`button`,onClick:()=>f(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${d===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[C(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!I&&C(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:le?`${String(B.length)} of ${String(F.length)} events`:`${String(B.length)} event${B.length===1?``:`s`}`})]}),p.size>0&&_(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[_(`span`,{className:`text-xs font-medium text-foreground`,children:[p.size,` selected`]}),_(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[C(`span`,{title:Y?void 0:`Track deletion arrives with the next server update`,children:_(l,{variant:`secondary`,onClick:G,disabled:!Y||P,children:[P?C(U,{className:`h-3.5 w-3.5 animate-spin`}):C(ce,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),C(l,{variant:`ghost`,onClick:ae,disabled:P,children:C(se,{className:`h-3.5 w-3.5`})})]})]}),I&&_(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[C(U,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!I&&B.length===0&&C(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),!I&&B.length>0&&_(y,{children:[C(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:V.pageItems.map(e=>C(Ze,{row:e,cameraName:R(e.deviceId),nowMs:b,selected:p.has(J(e.deviceId,e.trackId)),onToggleSelect:oe,onOpenDetail:g},J(e.deviceId,e.trackId)))}),C(re,{currentPage:V.page,totalItems:V.totalItems,pageSize:V.pageSize,onPageChange:V.setPage,itemNoun:`events`})]}),h&&C(Ye,{row:h,cameraName:R(h.deviceId),deleteAvailable:Y,onClose:()=>g(null),onDeleted:()=>{H(),g(null)}})]})}g();var rt=50,it=350,at=[`person`,`vehicle`,`animal`],ot=[{value:.2,label:`Loose`},{value:.25,label:`Balanced`},{value:.3,label:`Strict`}];function st(e){return{id:e.id,trackId:e.trackId??e.id,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,importance:e.importance??0,bestEventId:e.mediaKey??e.trackId??e.id,windowMs:void 0}}function ct({onActiveChange:n}){let[r,i]=S(``),[a,o]=S(.2),[s,c]=S(null),[l,d]=S(null),[f,p]=S(null),m=e(r,it).trim(),h=m.length>0;w(()=>{n(h)},[h,n]);let[g,y]=S(()=>Date.now());w(()=>{let e=setInterval(()=>y(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:b}=u({}),x=v(()=>(b??[]).filter(e=>e.type===D.Camera),[b]),T=v(()=>{let e=new Map;for(let t of b??[])e.set(t.id,t.name);return e},[b]),E=e=>T.get(e)??`Camera #${String(e)}`,{data:O,isFetching:k,isError:A,error:j}=t({text:m,minScore:a,limit:rt,classFilter:s??void 0,deviceId:l??void 0},{enabled:h}),M=v(()=>[...O??[]].sort((e,t)=>t.score-e.score).map(e=>({...st(e),score:e.score})),[O]);function ee(e){c(t=>t===e?null:e)}return _(`div`,{className:`space-y-3`,children:[_(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[_(`div`,{className:`flex flex-wrap items-center gap-2`,children:[_(`div`,{className:`relative min-w-[16rem] flex-1`,children:[C(R,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),C(`input`,{type:`text`,value:r,onChange:e=>i(e.target.value),placeholder:`Semantic search — describe what you're looking for…`,className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-8 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Semantic event search`}),r&&C(`button`,{type:`button`,onClick:()=>i(``),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Clear search`,children:C(se,{className:`h-3.5 w-3.5`})})]}),k&&h&&C(U,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),_(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[C(`div`,{className:`flex items-center gap-1`,children:at.map(e=>C(`button`,{type:`button`,onClick:()=>ee(e),className:`rounded-md px-2.5 py-1 text-xs capitalize transition-colors ${s===e?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e},e))}),_(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[C(`span`,{children:`Camera`}),_(`select`,{value:l===null?``:String(l),onChange:e=>d(e.target.value===``?null:Number(e.target.value)),className:`h-7 rounded-md border border-border bg-background px-1.5 text-xs text-foreground focus:border-primary focus:outline-none`,"aria-label":`Filter by camera`,children:[C(`option`,{value:``,children:`All`}),x.map(e=>C(`option`,{value:String(e.id),children:e.name},e.id))]})]}),_(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[C(`span`,{children:`Match`}),C(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:ot.map(e=>C(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${a===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:`Minimum CLIP score ${e.value.toFixed(2)}`,children:e.label},e.value))})]}),h&&!k&&!A&&_(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[M.length,` match`,M.length===1?``:`es`]})]})]}),h&&_(`div`,{className:`space-y-3`,children:[A&&_(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,j instanceof Error?j.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!A&&k&&M.length===0&&_(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[C(U,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!A&&!k&&M.length===0&&_(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:[`No semantic matches for “`,m,`”. Try a looser match threshold or a different phrasing.`]}),!A&&M.length>0&&C(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:M.map(e=>C(Ze,{row:e,cameraName:E(e.deviceId),nowMs:g,score:e.score,onOpenDetail:p},e.id))})]}),f&&C(Ye,{row:f,cameraName:E(f.deviceId),deleteAvailable:Y,onClose:()=>p(null),onDeleted:()=>p(null)})]})}var lt=15e3;function ut(e){let t=O(),n=b({queries:e.map(e=>({queryKey:[`stationary-objects`,e],staleTime:lt,refetchInterval:lt,queryFn:async()=>((await t.trpcClient.zoneAnalytics.getCurrentSnapshot.query({deviceId:e}))?.stationaryObjects??[]).map(t=>({...t,deviceId:e}))}))});return{rows:n.flatMap(e=>e.data??[]).toSorted((e,t)=>t.becameStationaryAt-e.becameStationaryAt),isLoading:n.some(e=>e.isLoading)}}g();function dt(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return`just now`;if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function ft({row:e,cameraName:t,nowMs:n}){let r=e.keyFrameMediaKey?.startsWith(`track:`)?e.keyFrameMediaKey.split(`:`)[1]:e.keyFrameMediaKey,i=ue(r?`${K}/${r}`:void 0);return _(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[_(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[i.src?C(`img`,{src:i.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):C(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:C(de,{className:`h-6 w-6`})}),C(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),_(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[C(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),_(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,dt(n,e.becameStationaryAt)]})]})]})}function pt(){let[e,t]=S(!1),n=Date.now(),{data:r}=u({}),i=v(()=>(r??[]).filter(e=>e.type===D.Camera),[r]),a=v(()=>i.map(e=>e.id),[i]),o=v(()=>{let e=new Map;for(let t of i)e.set(t.id,t.name);return e},[i]),{rows:s}=ut(a);return s.length===0?null:_(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[_(`button`,{type:`button`,onClick:()=>t(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[C(e?H:oe,{className:`h-4 w-4 text-foreground-subtle`}),C(de,{className:`h-4 w-4 text-foreground-subtle`}),C(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),C(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:s.length}),C(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`})]}),e&&C(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:s.map(e=>C(ft,{row:e,cameraName:o.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}g();function mt(){Ee();let[e,t]=S(!1);return C(le,{icon:W,title:`Events`,subtitle:`Every captured key event across all cameras — trajectory, media, and clips.`,children:_(`section`,{className:`space-y-3`,children:[C(ct,{onActiveChange:t}),!e&&C(pt,{}),!e&&C(nt,{})]})})}export{mt as EventsPage};
@@ -1 +0,0 @@
1
- import{Ta as e,_a as t,ba as n,c as r,ca as i,da as a,fa as o,ga as s,ha as c,io as l,la as u,ma as d,oa as f,pa as p,s as m,sa as h,ua as g,va as _,vt as v,ya as y,yt as b,za as x}from"./src-P2A2VEVG.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-DOCODmhZ.js";import{t as A}from"./copy-DAnlpNmN.js";import{t as j}from"./key-round-DY-W0ctm.js";import{t as M}from"./AddonCollectionPage-B83rtm_P.js";import{t as ee}from"./plus-CWmuK222.js";import{L as N,S as P,T as F,W as I,f as L,i as R,r as z,s as B,u as V,w as H}from"./index-BVO5AjpN.js";import{t as U}from"./AdminPage-BwmGKnRf.js";import{t as W}from"./AdminTabs-CGgxIyjn.js";import{t as G}from"./addon-display-names-DvSEQty-.js";var K=I(`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=I(`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=I(`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`}]]),q=I(`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`}]]),re=I(`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 ie({userId:t,username:n,onClose:r}){let i=E(),a=e(),o=g({userId:t}),s=o.data,c=()=>i.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),d=u({onSuccess:()=>{c(),r()}}),f=o.isLoading?`loading`:s?.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(V,{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:r,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:O(R,{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(P,{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(H,{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`&&s&&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`,` `,s.confirmedAt?new Date(s.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(l,{onClick:r,variant:`secondary`,children:`Close`}),C(`button`,{onClick:async()=>{await a({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:t})},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(P,{className:`h-3 w-3 animate-spin`}):O(R,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function ae(){let t=E(),{user:r}=z(),[a,o]=D(!1),[s,l]=D(``),[u,f]=D(``),[p,m]=D(!1),[g,_]=D(null),{data:v,isLoading:b,isError:S}=d(),w=e(),T=()=>t.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),k=h({onSuccess:()=>{T(),o(!1),l(``),f(``),m(!1),_(null)},onError:e=>{_(e instanceof Error?e.message:`Failed to create user`)}}),A=i({onSuccess:T}),j=n({onSuccess:T}),M=c({onSuccess:T}),N=y({onSuccess:()=>{T(),I(null)}}),[F,I]=D(null),[H,W]=D(null),G=v??[];async function K(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 te(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 re(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:()=>o(!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`]})}),a&&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:()=>o(!1),className:`text-foreground-subtle hover:text-foreground`,children:O(R,{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:s,onChange:e=>l(e.target.value),placeholder:`john`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),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:u,onChange:e=>f(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:p,onChange:e=>m(e.target.checked),className:`rounded border-border focus:ring-primary`}),O(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),g&&O(`p`,{className:`text-[10px] text-danger`,children:g}),C(`div`,{className:`flex justify-end gap-2`,children:[O(`button`,{onClick:()=>o(!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:s,password:u,isAdmin:p}),disabled:k.isPending||!s||!u,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children: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(x,{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:()=>I(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(L,{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:re(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:t=>{let n=e(t);return C(`div`,{className:`flex items-center justify-end gap-1`,children:[t.id!==r?.id&&t.totpEnabled&&C(`button`,{onClick:()=>W(t),disabled:n,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(V,{className:`h-3 w-3`}),`Remove 2FA`]}),C(`button`,{onClick:()=>te(t),disabled:n,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:()=>K(t),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:`Delete user`,children:[n?O(P,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:G,rowKey:e=>e.id,minWidthPx:560})})(),H&&O(ie,{userId:H.id,username:H.username,onClose:()=>W(null)}),F&&O(oe,{user:F,onClose:()=>I(null),onSubmit:e=>N.mutate({userId:F.id,scopes:e}),submitting:N.isPending})]})}function oe(e){let{user:t}=z(),n=t?.isAdmin===!0;return O(se,{...e,callerScopes:n?null:t?.scopes??[]})}function se({user:e,onClose:t,onSubmit:n,submitting:i,callerScopes:a}){let[o,s]=D(w(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),c=r(o);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(R,{className:`h-4 w-4`})})]}),C(`div`,{className:`px-4 py-4`,children:[O(m,{value:o,onChange:s,clampToParent:a,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.`]})}),c&&O(`p`,{className:`mt-2 text-[10px] text-danger`,children:c})]}),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(o),disabled:i||c!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:i?O(P,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}S();var ce=`bg-primary/10 text-primary`,le=`bg-foreground-subtle/10 text-foreground-subtle`;function J(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function ue(e){return e?e===`*`?`*`:e.join(`, `):``}function de(){let t=E(),n=e(),{data:r,isLoading:i}=a(),{data:o}=d(),c=w(()=>r??[],[r]),l=w(()=>o??[],[o]),u=()=>t.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),p=()=>t.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[m,h]=D(!1),[g,v]=D(null),y=s({onSuccess:u}),b=f({onSuccess:({token:e,record:t})=>{p(),h(!1),v({token:e,label:t.name})}}),x=_({onSuccess:p}),S=async(e,t)=>{await n({title:`Revoke "${t}"?`,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,t)=>{await n({title:`Revoke "${t}"?`,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:l.length===0,title:l.length===0?`Create a user first`:`Issue a scoped token`,children:[O(L,{className:`h-3.5 w-3.5`}),`New token`]})]}),C(fe,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[l.length===0&&O(me,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),l.map(e=>O(ge,{userId:e.id,username:e.username,onRevoke:(e,t)=>{T(e,t)},revokePending:x.isPending,revokeId:x.variables?.id},e.id))]}),c.length>0&&O(fe,{title:`Legacy API keys`,subtitle:`${c.length} pre-existing — revoke only`,children:O(he,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:c.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?ce:le}`,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:ue(e.allowedProviders)||`all`}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(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(P,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),i&&O(pe,{}),m&&O(_e,{users:l.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(ve,{token:g.token,label:g.label,onClose:()=>v(null)})]})}function fe({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 pe(){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 me({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 he({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 ge({userId:e,username:t,onRevoke:n,revokePending:r,revokeId:i}){let{data:a,isLoading:o}=p({userId:e}),s=a??[];return o||s.length===0?null:C(`div`,{className:`space-y-1.5`,children:[O(`div`,{className:`text-[11px] font-medium text-foreground`,children:t}),O(he,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:s.map(e=>{let t=r&&i===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:J(e.expiresAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:C(`button`,{onClick:()=>n(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(P,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function _e({users:e,onClose:t,onSubmit:n,submitting:i}){let{user:a}=z(),o=a?.isAdmin===!0?null:a?.scopes??[],[s,c]=D(e[0]?.id??``),[l,u]=D(``),[d,f]=D([{type:`capability`,target:``,access:[`view`,`create`]}]),[p,h]=D(``),g=r(d),_=s!==``&&l.trim().length>0&&d.length>0&&g===null&&!i;return C(ye,{title:`Create scoped token`,onClose:t,children:[C(`div`,{className:`space-y-3`,children:[O(Y,{label:`On behalf of user`,children:O(`select`,{value:s,onChange:e=>c(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(Y,{label:`Name`,children:O(`input`,{value:l,onChange:e=>u(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(Y,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[O(m,{value:d,onChange:f,clampToParent:o}),g&&O(`p`,{className:`mt-1 text-[10px] text-danger`,children:g})]}),O(Y,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:O(`input`,{type:`number`,min:1,value:p,onChange:e=>h(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(be,{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(p,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;n({userId:s,name:l.trim(),scopes:d,expiresAt:t})},disabled:!_,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[i?O(P,{className:`h-3.5 w-3.5 animate-spin`}):O(L,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function ve({token:e,label:t,onClose:n}){let[r,i]=D(!1),a=async()=>{try{await navigator.clipboard.writeText(e),i(!0)}catch{}};return C(ye,{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(be,{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(N,{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 ye({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(R,{className:`h-4 w-4`})})]}),O(`div`,{className:`p-4`,children:n})]})})}function be({children:e}){return O(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Y({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 X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function xe(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 Se(){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 Ce({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 we({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 Te(){let n=E(),r=e(),{data:i,isLoading:a}=o(),s=w(()=>i??[],[i]),c=t({onSuccess:()=>n.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),l=async(e,t)=>{await r({title:`Revoke "${t}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&c.mutate({id:e})};return C(U,{icon:q,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[a&&O(Se,{}),!a&&s.length===0&&O(Ce,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!a&&s.length>0&&O(we,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:s.map(e=>{let t=e.revokedAt!==null,n=(c.isPending?c.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:xe(e)},t))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(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 `,X(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:()=>{l(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(P,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}S();var Z=3e4,Q=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],$={title:`Authentication providers`,subtitle:`Every registered authentication surface in one list: login providers (local password, OIDC, SAML, magic-link) and second-factor providers (passkeys / WebAuthn — configure the relying-party RP ID + origin inline; users enroll from My access → Passkeys). Multiple providers run in parallel — enable/disable each independently. Disabling one only removes that method; local password login is unaffected.`,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,installLabel:`Add provider`};function Ee(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 is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:F,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:F,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:V,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:V,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:L,bullets:[`Generic authentication provider. No additional hints registered.`]}}function De(){let e=b({capName:Q[0].capName},{refetchInterval:Z}),t=b({capName:Q[1].capName},{refetchInterval:Z}),n=v(void 0,{refetchInterval:Z}),r=w(()=>G(n.data??[]),[n.data]),i=w(()=>{let n=[],i=[e.data??[],t.data??[]];for(let[e,t]of Q.entries())for(let a of i[e]??[])n.push({addonId:a.addonId,displayName:r.get(a.addonId)??a.addonId,isActive:a.isActive,capName:t.capName,stageBadge:t.stageBadge});return n},[e.data,t.data,r]);return O(M,{title:$.title,subtitle:$.subtitle,pageIcon:L,itemIcon:L,capability:Q[0].capName,installButtonLabel:$.installLabel,items:i,isLoading:e.isLoading||t.isLoading,emptyTitle:$.emptyTitle,emptyDescription:$.emptyDescription,renderStatusBadges:e=>e.stageBadge===null?null:O(`span`,{className:`inline-flex items-center rounded-full border border-primary/30 bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary`,children:e.stageBadge}),renderExpandedPanel:e=>O(Oe,{addonId:e.addonId})})}function Oe({addonId:e}){let t=Ee(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(K,{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(H,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),C(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,O(`a`,{href:`/system/my-access`,className:`underline text-primary`,children:`My access`}),` `,`→ “Two-factor authentication” → Enable 2FA. Admins can only remove a user’s active enrollment (lost device) from the`,` `,O(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function ke(){return O(`div`,{className:`flex flex-col p-4`,children:O(W,{tabs:[{id:`users`,label:`Users`,icon:re,content:O(ae,{})},{id:`api-keys`,label:`Tokens`,icon:j,content:O(de,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:q,content:O(Te,{})},{id:`authentication`,label:`Authentication`,icon:L,content:O(De,{})}]})})}export{ke as IdentityPage};
@@ -1 +0,0 @@
1
- import{Ba as e,Cn as t,Ct as n,Mn as r,Pn as i,U as a,Un as o,W as s,ar as c,bn as l,ct as u,d,dn as f,dr as p,eo as m,et as h,fn as g,g as _,hn as v,kn as y,ln as b,lr as x,mn as S,nt as C,or as w,pr as ee,sr as te,un as ne,x as T,yn as E}from"./src-P2A2VEVG.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{w as F}from"./src-DNVzx9ag.js";import{p as I}from"./player-overlays-CDSEY_-X.js";import{t as L}from"./ProviderIcon-BeZnXEB7.js";import{t as R}from"./FormBuilder-iTpxBqBc.js";import{t as z}from"./plus-CWmuK222.js";import{n as B,r as ae,t as oe}from"./ScanNetworkModal-C_pd8W_5.js";import{t as se}from"./refresh-cw-7j7eJ_7S.js";import{t as ce}from"./rotate-cw-Dl9N7lTh.js";import{t as V}from"./wifi-D9-_VL0_.js";import{D as H,H as le,I as U,J as ue,K as de,L as W,O as fe,P as pe,S as G,W as K,i as q,m as me,o as J,p as he,q as ge,s as _e,t as ve}from"./index-BVO5AjpN.js";var ye=K(`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:i,onClose:a}){let{t:s}=ve(),c=M(),[l,u]=N({}),[d,f]=N(!1),[p,m]=N(null),[h,g]=N(X),v=r({addonId:i},{enabled:e}),y=v.data?.deviceType??null,b=t({addonId:i,type:y??F.Camera},{enabled:e&&v.isSuccess&&y!==null}),x=b.data??null;ie(()=>{e&&(u(x?Y(x.sections.flatMap(e=>e.fields)):{}),g(X()),f(!1),m(null))},[e,n,x]);let C=A(()=>({...l,_probeRequestId:h}),[l,h]),w=S({onSuccess:()=>{c.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ee=o(),te=D(async(e,t)=>{f(!0);let n=await ee.mutateAsync({addonId:i,type:y??F.Camera,key:e,value:t,formValues:C});return n.status===`ok`&&n.suggestedValues&&u(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},[ee,i,C,y]),{testAllStatus:ne,hasProbeFields:T,probeResults:E,handleTestAll:re,clearProbeResult:O}=xe(x??{sections:[]},l,te);async function j(e){m(null);try{await w.mutateAsync({addonId:i,type:y??F.Camera,config:l,integrationId:n}),e?u(x?Y(x.sections.flatMap(e=>e.fields)):{}):a()}catch(e){m(e instanceof Error?e.message:String(e))}}if(!e)return null;let I=Se((x?.sections??[]).flatMap(e=>e.fields)).filter(e=>Ce(l[e])),L=I.length===0,z=v.isLoading||y!==null&&b.isLoading,B=v.isError||v.isSuccess&&y===null||b.isError||b.isSuccess&&x===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:a}),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:s(`integrations.addDevice`)}),P(`button`,{onClick:a,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:P(q,{className:`h-4 w-4`})})]}),P(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:z?P(`div`,{className:`flex items-center justify-center py-8`,children:P(G,{className:`h-5 w-5 animate-spin text-primary`})}):B?k(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[P(J,{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:i}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):P(R,{schema:x,values:l,onChange:u,onTestField:te,probeResults:E,onClearProbe:O})}),!B&&!z&&k(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[k(`button`,{type:`button`,onClick:()=>f(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(me,{className:`h-3.5 w-3.5`}),`Test logs`,P(`span`,{className:`font-mono text-[9px] opacity-60`,children:h.slice(0,14)})]}),P(U,{className:`h-3.5 w-3.5 transition-transform ${d?`rotate-180`:``}`})]}),d&&P(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:P(_,{addonId:i,requestId:h,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!B&&!z&&(p||I.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(J,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),P(`p`,{className:`text-[11px] text-destructive`,children:p||`Required: ${I.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:a,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:s(`integrations.cancel`)}),!B&&T&&k(`button`,{type:`button`,onClick:re,disabled:ne===`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:[ne===`testing`?P(G,{className:`h-3.5 w-3.5 animate-spin`}):P(V,{className:`h-3.5 w-3.5`}),`Test All`]})]}),k(`div`,{className:`flex items-center gap-2`,children:[P(`button`,{onClick:()=>j(!0),disabled:B||!L||w.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:s(`integrations.saveAndNew`)}),P(`button`,{onClick:()=>j(!1),disabled:B||!L||w.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:w.isPending?s(`integrations.saving`):s(`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}=ve(),[i,o]=N(new Set),[s,c]=N(new Set),[l,u]=N(new Map),[d,p]=N(null),{data:m}=te(),_=(m??[]).find(t=>t.addonId===e)?.supportsLocationImport??!1,[v,y]=N(!0),x=ne({addonId:e,integrationId:t}).data?.filters,S=x&&x.length>0?x:[Te],[w,ee]=N(S.find(e=>e.isDefault)?.id??(S.some(e=>e.id===Q)?Q:S[0].id)),T=w!==Q,E=g(),O=f({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=b(),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=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),se=D((e,t)=>{u(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})},[]),V=D(e=>{let t={};for(let n of e){let e=l.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[l]),H=D(async()=>{p(null);let r=[...i];if(r.length!==0)try{let i=V(r);await B.mutateAsync({addonId:e,integrationId:t,filter:w,childNativeIds:r,...i?{perCandidate:i}:{},..._?{importLocations:v}:{}}),o(new Set),u(new Map),await A(),n()}catch(e){p(e instanceof Error?e.message:String(e))}},[i,V,B,e,t,w,A,_,v]),le=D(e=>{ee(e),o(new Set),c(new Set),u(new Map),p(null)},[]),U=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:[_&&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:v,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(q,{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(J,{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})]})]})}),S.length>1&&P(ke,{filters:S,activeFilter:w,onSelect:le}),P(`div`,{className:`flex-1 min-h-0`,children:P(a,{mode:`generic`,items:R,pageSize:De,getKey:e=>e.childNativeId,getSearchText:Z,getFilterType:e=>e.type,filterOptions:h(),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(ce,{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:s.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=C(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(W,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!T&&s.has(e.childNativeId),renderExpanded:T?void 0:e=>P(Ae,{candidate:e,hiddenChildIds:l.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`:``})})]}),d&&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(J,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),P(`p`,{className:`text-[11px] text-destructive`,children:d})]})}),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:H,disabled:U===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(G,{className:`h-3.5 w-3.5 animate-spin`}),r(`integrations.addSelected`,{defaultValue:`Add selected`}),U>0?` (${U})`:``]})]})]})]})]})}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?U:pe,{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?fe:H,{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}=ve(),c=M(),l=r===`device-adoption`,{data:u}=x({id:e},{enabled:l}),d=A(()=>{let e=u?.brokerId;return typeof e==`string`?e:null},[u]),f=p();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(q,{className:`h-4 w-4`})})]}),l?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.`})}),d&&k(`p`,{className:`text-[11px] text-foreground`,children:[s(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,P(`span`,{className:`font-mono text-foreground-subtle`,children:d})]}),f.isPending?k(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[P(G,{className:`h-3 w-3 animate-spin`}),s(`integrations.saving`,{defaultValue:`Saving…`})]}):P(B,{kind:i,onResolved:t=>{f.mutate({id:e,settings:{brokerId:t}},{onSuccess:()=>{c.invalidateQueries(),o()}})},onBack:o}),f.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(T,{trpc:a,addonId:t,nodeId:`hub`,title:n})]})})}O();function Me(){let{t}=ve(),{integrationId:r}=ge(),o=M(),f=de(),[p,h]=ue(),g=I(),[b,x]=N(!1),[S,C]=N(!1),[ne,T]=N(!1),[re,O]=N(!1),[F,R]=N(!1),{data:B,isLoading:ce}=w({id:r??``},{enabled:!!r}),{data:V}=u({addonId:B?.addonId??``,nodeId:`hub`},{enabled:!!B?.addonId}),{data:H,isSuccess:U}=te(),W=A(()=>{let e=B?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[H,B?.addonId,U]),{data:fe}=E({}),pe=A(()=>(fe?.providers??[]).some(e=>e.addonId===B?.addonId),[fe,B?.addonId]),K=W!==null,be=K?W===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),xe=A(()=>{let e=B?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.brokerKind??null},[H,B?.addonId,U]),Se=A(()=>{let e=B?.addonId;return!e||!U?null:(H??[]).find(t=>t.addonId===e)?.mode??null},[H,B?.addonId,U]);ie(()=>{p.get(`add`)===`1`&&K&&(x(!0),h(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[p,K,h]);let Ce=V!=null&&Array.isArray(V.sections)&&V.sections.some(e=>e.fields.length>0),{data:Y}=y({},{refetchInterval:5e3}),X=[[`integrations`,`get`],{input:{id:r??``},type:`query`}],Z=ee({onMutate:async e=>{await o.cancelQueries({queryKey:X});let t=o.getQueryData(X);return t!=null&&o.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&o.setQueryData(X,r.previous)},onSettled:()=>{o.invalidateQueries({queryKey:[[`integrations`]]}),o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=c({onSuccess:()=>{o.invalidateQueries({queryKey:[[`integrations`]]}),o.invalidateQueries({queryKey:[[`deviceManager`]]}),O(!1),f(`/integrations`)}}),Te=n({onSuccess:()=>{o.invalidateQueries({queryKey:[[`integrations`]]}),o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ee=i({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),De=v({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=l({onSuccess:()=>{o.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=>f(`/devices/${String(e)}`),[f]),Fe=A(()=>{let e=B?.addonId;return e?$.filter(t=>t.addonId===e):[]},[$,B?.addonId]),Ie=A(()=>s(Fe).length,[Fe]);return ce?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`})]}):B?k(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[P(e,{items:[{label:`Integrations`,onClick:()=>f(`/integrations`)},{label:B.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/${B.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:B.name}),k(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[B.addonId,` · `,Ie,` `,t(`integrations.devices`)]})]})]}),k(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[pe&&k(`button`,{onClick:()=>C(!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(ae,{className:`h-3.5 w-3.5`}),`Scan network`]}),k(`button`,{onClick:()=>x(!0),disabled:!K,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(z,{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`:``} ${B.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[P(m,{checked:B.enabled,onCheckedChange:e=>Z.mutate({id:r,enabled:e}),disabled:Z.isPending,"aria-label":B.enabled?`Disable integration`:`Enable integration`}),P(`span`,{className:`text-[11px] font-medium ${B.enabled?`text-success`:`text-foreground-subtle`}`,children:B.enabled?`Enabled`:`Disabled`}),Z.isPending&&P(G,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Se!==`standalone`&&(Ce||W===`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(he,{className:`h-3 w-3`}),t(`integrations.config`)]}),k(`button`,{onClick:()=>R(!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(me,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),P(d,{label:`Restart`,icon:se,title:`Restart "${B.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:B.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(_e,{className:`h-3 w-3`}),t(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),P(a,{context:`integration-detail`,devices:$,trpc:g.trpcClient,defaultView:`cards`,forceAddon:B.addonId,urlScope:`root`,lsKey:`integration-detail:${B.addonId}`,resolveIntegrationIcon:Ne,resolveParent:Me,onNavigate:Pe,batchActions:{remove:Ee.mutate,disable:De.mutate,enable:ke.mutate},onDeleteDevice:e=>Ee.mutate({deviceId:e.id})}),b&&r&&W===`device-adoption`&&P(Oe,{addonId:B.addonId,integrationId:r,onClose:()=>x(!1)}),b&&r&&W===`device-provider`&&P(we,{open:b,integrationId:r,addonId:B.addonId,onClose:()=>x(!1)}),S&&B&&P(oe,{open:S,scope:{addonId:B.addonId,label:B.name},onClose:()=>C(!1)}),ne&&r&&W!==null&&P(je,{integrationId:r,addonId:B.addonId,name:B.name,kind:W,brokerKind:xe,trpc:g.trpcClient,onClose:()=>T(!1)}),F&&P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>R(!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(me,{className:`h-4 w-4 text-primary shrink-0`}),P(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:B.name}),k(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[B.addonId,r?` · ${r}`:``]})]}),P(`button`,{onClick:()=>R(!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(q,{className:`h-4 w-4`})})]}),P(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:P(_,{addonId:B.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(J,{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:B.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:r}),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(G,{className:`h-3 w-3 animate-spin`}),t(`integrations.deleting`,{defaultValue:`Deleting…`})]}):k(j,{children:[P(_e,{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:r??``})})]}),k(`button`,{onClick:()=>f(`/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(le,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{Me as IntegrationDetailPage};