@camstack/addon-admin-ui 1.1.19 → 1.1.20

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 (106) hide show
  1. package/dist/assets/{AddLocationWizard-DlIuy7PK.js → AddLocationWizard-Brlh9UJ9.js} +1 -1
  2. package/dist/assets/AddonCollectionPage-Bg5OVL_9.js +1 -0
  3. package/dist/assets/Addons-2VeHH2Fx.js +1 -0
  4. package/dist/assets/{AdminPage-vtcsGqRq.js → AdminPage-BwmGKnRf.js} +1 -1
  5. package/dist/assets/{AdminTabs-Cyrx86NX.js → AdminTabs-DVI3osLb.js} +1 -1
  6. package/dist/assets/{BrokerForm-BU7fpWoT.js → BrokerForm-CS__YhVd.js} +1 -1
  7. package/dist/assets/Capabilities-sR8ZG2Sp.js +1 -0
  8. package/dist/assets/{CapabilityBadges-C7OuLfh8.js → CapabilityBadges-BtwEWtSB.js} +1 -1
  9. package/dist/assets/Cluster-BsMp1-aa.js +1 -0
  10. package/dist/assets/{Dashboard-DOxZXqyK.js → Dashboard-cUXiEA9q.js} +1 -1
  11. package/dist/assets/Data-FggSTTQB.js +1 -0
  12. package/dist/assets/{DetectionIntelligence-DqOJ15Er.js → DetectionIntelligence-BG1dq_BC.js} +1 -1
  13. package/dist/assets/DeviceDetail-DD7tVaBH.js +2 -0
  14. package/dist/assets/{Devices-C3jy25Bw.js → Devices-DfYGm_-Y.js} +1 -1
  15. package/dist/assets/{EmbedPlayerPage-C4PqItRF.js → EmbedPlayerPage-2oboqnId.js} +1 -1
  16. package/dist/assets/FormBuilder-B6OIFE8M.js +1 -0
  17. package/dist/assets/Identity-CiOHNQP2.js +1 -0
  18. package/dist/assets/IntegrationDetail-BVhsZAdC.js +1 -0
  19. package/dist/assets/{Integrations-CNJgYeN5.js → Integrations-BOUUPSGH.js} +1 -1
  20. package/dist/assets/{Integrations-DsYPT3r2.js → Integrations-CVCNKHh5.js} +1 -1
  21. package/dist/assets/{Logs-5bYEoeMq.js → Logs-C_K69uCx.js} +1 -1
  22. package/dist/assets/{MaskShapeCanvas-CQ2SgaNa.js → MaskShapeCanvas-pGn6MKOi.js} +1 -1
  23. package/dist/assets/MotionZonesSettings-BnjJUOgY.js +1 -0
  24. package/dist/assets/MyAccess-BKZkUhvb.js +2 -0
  25. package/dist/assets/Network-Bu7lrlmc.js +1 -0
  26. package/dist/assets/{NodeAddonsSettingsPanel-oVi7MC28.js → NodeAddonsSettingsPanel-CsBUUhBI.js} +1 -1
  27. package/dist/assets/{NotificationTargets-CI-nn-rf.js → NotificationTargets-DlPYj2Ic.js} +1 -1
  28. package/dist/assets/Pipeline-CFOZ4ITe.js +1 -0
  29. package/dist/assets/PrivacyMaskSettings-RUAuOFuS.js +1 -0
  30. package/dist/assets/{ProviderIcon-BlnoCop3.js → ProviderIcon-RCIWUZYh.js} +1 -1
  31. package/dist/assets/{ScanNetworkModal-CxjeMDho.js → ScanNetworkModal-CVTAzCpc.js} +1 -1
  32. package/dist/assets/{SchemaTabBar-DRo5sGP1.js → SchemaTabBar-Lx0lVN3x.js} +1 -1
  33. package/dist/assets/{Settings-5VzV0eVZ.js → Settings-BRGkGmWW.js} +1 -1
  34. package/dist/assets/{Showroom-DrEy5G_m.js → Showroom-nB3ihbXc.js} +1 -1
  35. package/dist/assets/{StatusBadge-BSsUNFG6.js → StatusBadge-Dcr2bw58.js} +1 -1
  36. package/dist/assets/_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CCEnK7l6.js +1 -0
  37. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js} +1 -1
  38. package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DkcC9IVF.js +1 -0
  39. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-DcnMG4y9.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-D9-wIasd.js} +1 -1
  40. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-CUURKTLp.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-DstpX0yz.js} +1 -1
  41. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.js-xmx-auwe.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.js-BBBrLLEa.js} +3 -3
  42. package/dist/assets/circle-check-big-DUVoa4K8.js +1 -0
  43. package/dist/assets/{copy-C4G6c4Ys.js → copy-Dx6PkNh2.js} +1 -1
  44. package/dist/assets/dist-B40Mc3dp.js +6 -0
  45. package/dist/assets/{dist-LQLUbjed.js → dist-BcfEPpAI.js} +1 -1
  46. package/dist/assets/{download-BXqeElYK.js → download-hTrdF0db.js} +1 -1
  47. package/dist/assets/{esm-C86u2nhh.js → esm-CU8QwYlu.js} +3 -3
  48. package/dist/assets/{hostInit-eCexcRoY.js → hostInit-Bkxnbz6r.js} +1 -1
  49. package/dist/assets/index-DpDrVUWD.css +2 -0
  50. package/dist/assets/index-DvxZ6VPS.js +4 -0
  51. package/dist/assets/{key-round-BNduVRhj.js → key-round-CME-3JbN.js} +1 -1
  52. package/dist/assets/{mf-entry-bootstrap-0-62a708e5.js → mf-entry-bootstrap-0-b91b99eb.js} +2 -2
  53. package/dist/assets/{pencil-x4bNLykx.js → pencil-DJ_y_Wy8.js} +1 -1
  54. package/dist/assets/{player-overlays-BK-_BrgW.js → player-overlays-DEDwF8Uo.js} +1 -1
  55. package/dist/assets/plus-BgpJnRYz.js +1 -0
  56. package/dist/assets/{radio-D7QKOm_q.js → radio-C_HfliiA.js} +1 -1
  57. package/dist/assets/{refresh-cw-sAaM2a8A.js → refresh-cw-9oudg8kg.js} +1 -1
  58. package/dist/assets/remoteEntry-Buh8tQ2B.js +1 -0
  59. package/dist/assets/{rotate-ccw-DmmfCbwP.js → rotate-ccw-5_RfArHn.js} +1 -1
  60. package/dist/assets/rotate-cw-ClWkf91I.js +1 -0
  61. package/dist/assets/search-CxsQfiZy.js +1 -0
  62. package/dist/assets/{server-9jJq82Vu.js → server-CQ1LH5PQ.js} +1 -1
  63. package/dist/assets/{sparkles-Cf43SJhp.js → sparkles-DvV1ODWG.js} +1 -1
  64. package/dist/assets/square-CQY_D8K1.js +1 -0
  65. package/dist/assets/{square-check-big-CKe1iFeG.js → square-check-big-64TOhDex.js} +1 -1
  66. package/dist/assets/src-50esl92F.js +61 -0
  67. package/dist/assets/src-BnbSKfdg.js +6 -0
  68. package/dist/assets/{upload-DeGWObu4.js → upload-BgSvbRWR.js} +1 -1
  69. package/dist/assets/{useBodyScrollLock-B2OWVaf_.js → useBodyScrollLock-B_rtaBV1.js} +1 -1
  70. package/dist/assets/useDevice-BGpZXQ7x.js +1 -0
  71. package/dist/assets/useEventInvalidation-BTia6ZIb.js +1 -0
  72. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_--tYWwZy7.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-tX1XrtZb.js} +2 -2
  73. package/dist/assets/{wifi-dLfxxYcz.js → wifi-Ctshxl91.js} +1 -1
  74. package/dist/assets/{zap-lXnTrd14.js → zap-BgTF9BOT.js} +1 -1
  75. package/dist/index.html +6 -6
  76. package/dist/server/addon.js +45 -2
  77. package/package.json +1 -1
  78. package/dist/assets/AddonCollectionPage-B4YZsZ2N.js +0 -1
  79. package/dist/assets/Addons-CF3JeZJs.js +0 -1
  80. package/dist/assets/Capabilities-BEyROSgm.js +0 -1
  81. package/dist/assets/Cluster-tcDpGJRa.js +0 -1
  82. package/dist/assets/Data-t_YbtZxL.js +0 -1
  83. package/dist/assets/DeviceDetail-DQbwOLvC.js +0 -2
  84. package/dist/assets/FormBuilder-B7tUioUm.js +0 -1
  85. package/dist/assets/Identity-BEvc1UzE.js +0 -1
  86. package/dist/assets/IntegrationDetail-lPxvINqs.js +0 -1
  87. package/dist/assets/MotionZonesSettings-DpdNJlNH.js +0 -1
  88. package/dist/assets/MyAccess-0WTyoQQ1.js +0 -2
  89. package/dist/assets/Network-BggdRVzo.js +0 -1
  90. package/dist/assets/Pipeline-BI2SWq0a.js +0 -1
  91. package/dist/assets/PrivacyMaskSettings-CrOgd9eg.js +0 -1
  92. package/dist/assets/_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CLDXRGbV.js +0 -1
  93. package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DqrXu-jG.js +0 -1
  94. package/dist/assets/circle-check-big-MfDWxk9K.js +0 -1
  95. package/dist/assets/dist-DK88lvvz.js +0 -6
  96. package/dist/assets/index-DP9bur77.css +0 -2
  97. package/dist/assets/index-idVLv2oj.js +0 -4
  98. package/dist/assets/plus-ByEqM_KR.js +0 -1
  99. package/dist/assets/remoteEntry-CorFK6mn.js +0 -1
  100. package/dist/assets/rotate-cw-Dq3dsGth.js +0 -1
  101. package/dist/assets/search-Cbx2Urnx.js +0 -1
  102. package/dist/assets/square-C0pQT5rA.js +0 -1
  103. package/dist/assets/src-B7BVQkY2.js +0 -61
  104. package/dist/assets/src-D7qnpDWK.js +0 -6
  105. package/dist/assets/useDevice-D_sz9YbZ.js +0 -1
  106. package/dist/assets/useEventInvalidation-BMv3kB-_.js +0 -1
@@ -1 +0,0 @@
1
- import{Ui as e}from"./src-B7BVQkY2.js";import{K as t,S as n,W as r,Z as i,a,t as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{p as c}from"./player-overlays-BK-_BrgW.js";import{t as l}from"./circle-check-big-MfDWxk9K.js";import{j as u,u as d,x as f}from"./index-idVLv2oj.js";import{t as p}from"./AdminPage-vtcsGqRq.js";i();var m={detection:`border-green-500`,detector:`border-green-500`,streaming:`border-blue-500`,decode:`border-blue-500`,decoder:`border-blue-500`,recording:`border-orange-500`,recorder:`border-orange-500`,transcoding:`border-purple-500`,transcoder:`border-purple-500`,restream:`border-cyan-500`,restreamer:`border-cyan-500`,storage:`border-yellow-500`,notification:`border-pink-500`,notifier:`border-pink-500`,faces:`border-indigo-500`},h={detection:`bg-green-500/5`,detector:`bg-green-500/5`,streaming:`bg-blue-500/5`,decode:`bg-blue-500/5`,decoder:`bg-blue-500/5`,recording:`bg-orange-500/5`,recorder:`bg-orange-500/5`,transcoding:`bg-purple-500/5`,transcoder:`bg-purple-500/5`,restream:`bg-cyan-500/5`,restreamer:`bg-cyan-500/5`,storage:`bg-yellow-500/5`,notification:`bg-pink-500/5`,notifier:`bg-pink-500/5`,faces:`bg-indigo-500/5`};function g({entry:e,actions:t}){let r=e.name.toLowerCase(),i=m[r]??`border-primary`,a=h[r]??`bg-primary/5`,o=e.providers.find(e=>e.active),c=t?.pendingCapability===e.name;return n(`div`,{className:`rounded-lg border-t-2 border border-border ${i} ${a} p-3 space-y-2`,children:[n(`div`,{className:`flex items-center justify-between gap-2`,children:[n(`span`,{className:`text-xs font-semibold text-foreground capitalize flex items-center gap-1.5`,children:[e.name,c&&s(f,{className:`h-3 w-3 animate-spin text-primary`})]}),s(`span`,{className:`rounded-full px-2 py-0.5 text-[10px] font-medium ${e.mode===`singleton`?`bg-primary/10 text-primary`:`bg-info/10 text-info`}`,children:e.mode})]}),e.mode===`singleton`?s(_,{entry:e,actions:t,activeProvider:o,isPending:c}):s(v,{entry:e,actions:t,isPending:c})]})}function _({entry:e,actions:t,activeProvider:r,isPending:i}){if(!t)return s(`div`,{children:r?n(`div`,{className:`flex items-center gap-1.5 text-[10px] text-foreground`,children:[s(l,{className:`h-3 w-3 text-green-400 shrink-0`}),s(`span`,{className:`font-medium`,children:r.addonName}),s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):s(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No active provider`})});if(e.providers.length===0)return s(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});let a=`__inherit__`;return n(`div`,{className:`space-y-2`,children:[s(`div`,{className:`space-y-1`,children:e.providers.map(r=>{let a=r.active;return n(`button`,{type:`button`,disabled:i||a,onClick:()=>t.onSelectSingleton(e.name,r.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${a?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[s(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${a?`border-green-400 bg-green-400`:`border-border`}`}),s(`span`,{className:`font-medium truncate`,children:r.addonName}),a&&s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},r.addonId)})}),e.perNode&&e.perNode.length>0&&s(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:e.perNode.map(r=>{let o=r.hasOverride&&r.resolvedActive?r.resolvedActive:a,c=[{value:a,label:`Inherit global${r.resolvedActive?` (${r.resolvedActive})`:``}`},...r.providers.map(e=>({value:e,label:e}))],l=n=>{n===a?t.onClearNodeSingleton(e.name,r.nodeId):t.onSelectNodeSingleton(e.name,r.nodeId,n)},u=i;return n(`div`,{className:`space-y-0.5`,children:[n(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[r.nodeId,r.hasOverride&&s(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:`override`})]}),c.map(e=>{let t=o===e.value;return n(`button`,{type:`button`,disabled:u||t,onClick:()=>l(e.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${t?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[s(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${t?`border-green-400 bg-green-400`:`border-border`}`}),s(`span`,{className:`font-medium truncate`,children:e.label}),t&&e.value!==a&&s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},e.value)})]},r.nodeId)})})]})}function v({entry:e,actions:t,isPending:r}){if(e.providers.length===0)return s(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});if(!t)return s(`div`,{className:`space-y-1`,children:e.providers.map(e=>n(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[s(`span`,{className:`text-foreground-subtle`,children:e.addonName}),e.active&&s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},e.addonId))});let i=e.providers.filter(e=>e.active).map(e=>e.addonId),a=(n,r)=>{let a=r?[...new Set([...i,n])]:i.filter(e=>e!==n);t.onToggleCollection(e.name,a)};return s(`div`,{className:`space-y-1`,children:e.providers.map(e=>n(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${r?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[n(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[s(`input`,{type:`checkbox`,checked:e.active,disabled:r,onChange:t=>a(e.addonId,t.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),s(`span`,{className:`text-foreground truncate`,children:e.addonName})]}),e.active&&s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},e.addonId))})}function y({capabilities:e,actions:t}){return e.length===0?s(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:`No capabilities registered`}):s(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>s(g,{entry:e,actions:t},e.name))})}var b=[`capabilities`,`listCapabilities`];function x(e){return e===`singleton`||e===`collection`}function S(e){let t=e.indexOf(`@`);return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function C(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:S(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function w(){let i=c(),[f,m]=t(null),[h,g]=t(null),_=a({queryKey:b,queryFn:()=>i.trpcClient.capabilities.listCapabilities.query()}),v=r(()=>{let e=(_.data??[]).flatMap(e=>x(e.mode)?[C(e,e.mode)]:[]),t=e.filter(e=>e.mode===`singleton`).toSorted((e,t)=>e.name.localeCompare(t.name)),n=e.filter(e=>e.mode===`collection`).toSorted((e,t)=>e.name.localeCompare(t.name));return[...t,...n]},[_.data]),S=r(()=>v.filter(e=>e.mode===`singleton`),[v]),w=r(()=>v.filter(e=>e.mode===`collection`),[v]),T=o({mutationFn:e=>i.trpcClient.capabilities.setActiveSingleton.mutate({capability:e.capName,addonId:e.addonId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} → ${t.addonId} is now active.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),E=o({mutationFn:e=>i.trpcClient.capabilities.setActiveSingleton.mutate({capability:e.capName,addonId:e.addonId,nodeId:e.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} → ${t.addonId}.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),D=o({mutationFn:e=>i.trpcClient.capabilities.clearSingletonNodeOverride.mutate({capability:e.capName,nodeId:e.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} now inherits the global default.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to clear ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),O=o({mutationFn:e=>i.trpcClient.capabilities.setCollectionEnabledProviders.mutate({capability:e.capName,enabledAddonIds:[...e.enabledAddonIds]}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName}: ${t.enabledAddonIds.length} provider(s) enabled.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to update ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),k={onSelectSingleton:(e,t)=>T.mutate({capName:e,addonId:t}),onSelectNodeSingleton:(e,t,n)=>E.mutate({capName:e,nodeId:t,addonId:n}),onClearNodeSingleton:(e,t)=>D.mutate({capName:e,nodeId:t}),onToggleCollection:(e,t)=>O.mutate({capName:e,enabledAddonIds:t}),pendingCapability:f};return n(p,{icon:d,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&n(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?s(l,{className:`h-3.5 w-3.5 shrink-0`}):s(u,{className:`h-3.5 w-3.5 shrink-0`}),s(`span`,{children:h.message})]}),_.isLoading&&s(`div`,{className:`flex items-center justify-center py-16`,children:s(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),_.isError&&!_.isLoading&&s(e,{title:`Failed to load capabilities`,message:_.error instanceof Error?_.error.message:`Unknown error`,onRetry:()=>void _.refetch()}),!_.isLoading&&!_.isError&&v.length===0&&s(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No capabilities registered.`}),!_.isLoading&&!_.isError&&v.length>0&&n(`div`,{className:`space-y-6`,children:[S.length>0&&n(`section`,{className:`space-y-2`,children:[s(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Singleton — pick one provider`}),s(y,{capabilities:S,actions:k})]}),w.length>0&&n(`section`,{className:`space-y-2`,children:[s(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Collection — enable a set`}),s(y,{capabilities:w,actions:k})]})]})]})}export{w as CapabilitiesPage,w as default};
@@ -1 +0,0 @@
1
- import{Cr as e,Hi as t,Jr as n,Sr as r,Wr as i,Yi as a,Zr as o,br as s,ca as c,dr as l,fr as u,g as d,h as f,ii as p,la as m,m as h,qi as g,sa as _,ua as v,vr as y,wr as b,xr as x,yr as S}from"./src-B7BVQkY2.js";import{G as C,I as w,K as T,S as E,W as D,Z as O,b as k,o as A,x as j,z as M}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{t as N}from"./pencil-x4bNLykx.js";import{t as P}from"./radio-D7QKOm_q.js";import{t as F}from"./refresh-cw-sAaM2a8A.js";import{t as I}from"./rotate-cw-Dq3dsGth.js";import{t as L}from"./server-9jJq82Vu.js";import{t as R}from"./upload-DeGWObu4.js";import{F as ee,L as te,M as z,P as B,V,i as ne,k as re,o as ie,p as H,s as U,x as W}from"./index-idVLv2oj.js";import{t as G}from"./format-size-CO9d3C3-.js";import{t as K}from"./NodeAddonsSettingsPanel-oVi7MC28.js";import{a as q,i as J,n as Y,r as X,t as ae}from"./esm-C86u2nhh.js";var Z=V(`ghost`,[[`path`,{d:`M9 10h.01`,key:`qbtxuw`}],[`path`,{d:`M15 10h.01`,key:`1qmjsl`}],[`path`,{d:`M12 2a8 8 0 0 0-8 8v12l3-3 2.5 2.5L12 19l2.5 2.5L17 19l3 3V10a8 8 0 0 0-8-8z`,key:`uwwb07`}]]),oe=V(`git-fork`,[[`circle`,{cx:`12`,cy:`18`,r:`3`,key:`1mpf1b`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`path`,{d:`M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9`,key:`1uq4wg`}],[`path`,{d:`M12 12v3`,key:`158kv8`}]]),se=V(`memory-stick`,[[`path`,{d:`M6 19v-3`,key:`1nvgqn`}],[`path`,{d:`M10 19v-3`,key:`iu8nkm`}],[`path`,{d:`M14 19v-3`,key:`kcehxu`}],[`path`,{d:`M18 19v-3`,key:`1vh91z`}],[`path`,{d:`M8 11V9`,key:`63erz4`}],[`path`,{d:`M16 11V9`,key:`fru6f3`}],[`path`,{d:`M12 11V9`,key:`ha00sb`}],[`path`,{d:`M2 15h20`,key:`16ne18`}],[`path`,{d:`M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z`,key:`lhddv3`}]]),Q=V(`skull`,[[`path`,{d:`m12.5 17-.5-1-.5 1h1z`,key:`3me087`}],[`path`,{d:`M15 22a1 1 0 0 0 1-1v-1a2 2 0 0 0 1.56-3.25 8 8 0 1 0-11.12 0A2 2 0 0 0 8 20v1a1 1 0 0 0 1 1z`,key:`1o5pge`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}]]),ce=V(`table-2`,[[`path`,{d:`M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18`,key:`gugj83`}]]);O();function le(e){let t=new FormData;return t.append(`file`,e.file,e.file.name),t.append(`nodeId`,e.nodeId),e.addonId&&t.append(`addonId`,e.addonId),new Promise((n,r)=>{let i=new XMLHttpRequest;i.open(`POST`,`/api/addons/upload`),e.token&&i.setRequestHeader(`Authorization`,`Bearer ${e.token}`),i.upload.addEventListener(`progress`,t=>{t.lengthComputable&&e.onProgress(Math.round(t.loaded/t.total*100))}),i.addEventListener(`load`,()=>{let e;try{e=JSON.parse(i.responseText)}catch{r(Error(`HTTP ${i.status}`));return}i.status>=200&&i.status<300?n(e):r(Error(e.error??`HTTP ${i.status}`))}),i.addEventListener(`error`,()=>r(Error(`Network error during upload`))),i.addEventListener(`abort`,()=>r(Error(`Upload aborted`))),i.send(t)})}function ue({nodeId:e,addons:n,isHub:r}){let i=A(),a=t(),[o,c]=T(null),[l,u]=T(null),[d,f]=T(!1),[p,m]=T(null),[h,g]=T(0),_=C(null),v=s(),x=b(),S=y({nodeId:e}),w=S.data??[],D=new Map(n.map(e=>[e.id,e.capabilities])),O=w.length>0?w.map(e=>({id:e.id,status:e.status,capabilities:D.get(e.id)??[],version:e.version,packageName:e.packageName})):n.map(e=>({id:e.id,status:e.status,capabilities:e.capabilities,version:void 0,packageName:void 0})),k=()=>{i.invalidateQueries({queryKey:[[`nodes`,`topology`]]}),S.refetch()},M=async t=>{c(t);try{await v.mutateAsync({nodeId:e,addonId:t}),k()}catch(e){console.error(`Failed to restart addon:`,e)}finally{c(null)}},N=async t=>{if(await a({title:`Uninstall addon`,message:`Remove "${t}" from ${e}? The addon directory will be deleted on disk.`,confirmLabel:`Uninstall`,variant:`danger`})){u(t);try{await x.mutateAsync({nodeId:e,addonId:t}),k()}catch(e){console.error(`Failed to uninstall addon:`,e)}finally{u(null)}}},P=E(`div`,{className:`flex items-center gap-2 mb-2`,children:[j(`input`,{ref:_,type:`file`,accept:`.tgz,.tar.gz`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(n){t.target.value=``,m(null),f(!0),g(0);try{await le({file:n,nodeId:e,token:localStorage.getItem(`camstack_admin_token`),onProgress:g}),k()}catch(e){m(e instanceof Error?e.message:String(e))}finally{f(!1),g(0)}}}}),E(`button`,{onClick:()=>_.current?.click(),disabled:d,className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[d?j(W,{className:`h-3 w-3 animate-spin`}):j(R,{className:`h-3 w-3`}),d?`Uploading… ${h}%`:`Upload addon (.tgz)`]}),d&&j(`div`,{className:`flex-1 h-1 rounded-full bg-muted overflow-hidden max-w-[140px]`,children:j(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${h}%`}})}),p&&j(`span`,{className:`text-[10px] text-destructive`,children:p})]});return O.length===0?E(`div`,{children:[P,j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:S.isLoading?`Loading addons…`:`No addons on this node`})]}):E(`div`,{children:[P,E(`table`,{className:`w-full text-xs`,children:[j(`thead`,{children:E(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`py-2 font-medium`,children:`Addon`}),j(`th`,{className:`py-2 font-medium`,children:`Version`}),j(`th`,{className:`py-2 font-medium`,children:`Capabilities`}),j(`th`,{className:`py-2 font-medium`,children:`Status`}),j(`th`,{className:`py-2 font-medium w-16`})]})}),j(`tbody`,{children:O.map(e=>E(`tr`,{className:`border-t border-border/50`,children:[E(`td`,{className:`py-2 font-medium`,children:[j(`div`,{children:e.id}),e.packageName&&j(`div`,{className:`text-[9px] text-muted-foreground`,children:e.packageName})]}),j(`td`,{className:`py-2 text-muted-foreground`,children:e.version??`—`}),j(`td`,{className:`py-2`,children:j(`div`,{className:`flex flex-wrap gap-1`,children:e.capabilities.length>0?e.capabilities.map(e=>j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400`,children:e},e)):j(`span`,{className:`text-muted-foreground`,children:`—`})})}),j(`td`,{className:`py-2`,children:j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e.status===`running`?`bg-success/10 text-success`:e.status===`error`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e.status})}),j(`td`,{className:`py-2`,children:E(`div`,{className:`flex items-center gap-1 justify-end`,children:[j(`button`,{onClick:()=>M(e.id),disabled:o===e.id||l===e.id,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.id}`,children:j(I,{className:`h-3 w-3 ${o===e.id?`animate-spin`:``}`})}),j(`button`,{onClick:()=>N(e.id),disabled:o===e.id||l===e.id,className:`p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50`,title:`Uninstall ${e.id}`,children:l===e.id?j(W,{className:`h-3 w-3 animate-spin`}):j(U,{className:`h-3 w-3`})})]})})]},e.id))})]})]})}O();function de(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function fe({state:e}){return j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var pe=[`trace`,`debug`,`info`,`warn`,`error`];function me({proc:e,nodeId:t,defaultExpanded:n,activePanel:i,onTogglePanel:a}){let o=e.services??[],l=o.length===1,[u,f]=T(l||n),[p,g]=T(null),[y,b]=T(`info`),S=e.name.includes(`(core)`),C=s(),w=x(),D=r(),O=async e=>{g(e);try{await C.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{g(null)}},k=async()=>{g(e.name);try{await w.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{g(null)}},A=async n=>{let r=`${t}/${e.name}`;try{await D.mutateAsync({nodeId:r,level:n}),b(n)}catch(e){console.error(`Failed to set log level:`,e)}};return E(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[E(`div`,{role:l?void 0:`button`,tabIndex:l?void 0:0,onClick:l?void 0:()=>f(!u),onKeyDown:l?void 0:e=>{(e.key===`Enter`||e.key===` `)&&f(!u)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${l?``:`hover:bg-muted/40 cursor-pointer`}`,children:[l?j(`span`,{className:`h-3 w-3 shrink-0`}):j(u?B:z,{className:`h-3 w-3 text-muted-foreground shrink-0`}),S?j(L,{className:`h-3.5 w-3.5 text-primary shrink-0`}):j(te,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),j(`span`,{className:`text-xs font-semibold flex-1`,children:e.name}),E(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,e.pid]}),j(fe,{state:e.state}),E(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[e.cpuPercent,`% CPU`]}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:G(e.memoryRss)}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:de(e.uptimeSeconds)}),!S&&E(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[E(_,{children:[j(v,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:y}),j(c,{align:`end`,className:`min-w-[70px] py-0.5`,children:pe.map(e=>j(m,{onClick:()=>A(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===y?`text-primary font-semibold`:``}`,children:e},e))})]}),j(`button`,{onClick:k,disabled:p===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:j(I,{className:`h-3 w-3 ${p===e.name?`animate-spin`:``}`})})]})]}),u&&o.length>0&&j(`div`,{className:`divide-y divide-border/30`,children:o.map(e=>E(`div`,{children:[E(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[j(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),j(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&E(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&E(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),E(`div`,{className:`flex items-center gap-1 shrink-0`,children:[j(`button`,{onClick:()=>a(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:j(H,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>a(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:j(P,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>O(e.addonId),disabled:p===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:j(I,{className:`h-3 w-3 ${p===e.addonId?`animate-spin`:``}`})})]})]}),i?.addonId===e.addonId&&i.type===`logs`&&j(`div`,{className:`border-t border-border/40 bg-muted/5`,children:j(d,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>a(e.addonId,`logs`)})}),i?.addonId===e.addonId&&i.type===`events`&&j(`div`,{className:`border-t border-border/40 bg-muted/5`,children:j(h,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>a(e.addonId,`events`)})})]},e.addonId))}),u&&o.length===0&&j(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function he({nodeId:e,processes:t}){let[n,r]=T(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):j(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>j(me,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}O();function ge(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function _e(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function ve({nodeId:e}){let n=A(),r=t(),[i,a]=T(`all`),o=g(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:s}=u({nodeId:e}),c=o?.processes??s,d=D(()=>c?[...c]:[],[c]),f=D(()=>i===`ghost`?d.filter(e=>e.classification===`ghost`):d,[d,i]),p=D(()=>{let e=d.filter(e=>e.classification===`ghost`),t=new Map;for(let n of e)t.has(n.ppid)||t.set(n.ppid,[]),t.get(n.ppid).push(n);return[...t.entries()].filter(([,e])=>e.length>1).map(([e,t])=>({ppid:e,children:t})).toSorted((e,t)=>t.children.length-e.children.length)},[d]),m=l({onSettled:()=>{n.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]})}}),h=D(()=>{let e=new Map;for(let t of d)e.set(t.pid,t.classification);return e},[d]),_=async(t,n)=>{if(t.classification===`root`||t.classification===`system`)return;let i=t.classification===`ghost`?`ghost`:t.addonId??`process`,a=n?`SIGKILL`:`SIGTERM`;await r({title:`Send ${a}?`,message:`Target pid ${t.pid} (${i}) on node ${e}.`,confirmLabel:`Send ${a}`,variant:`danger`})&&m.mutate({nodeId:e,pid:t.pid,force:n})},v=async(t,n)=>{try{await m.mutateAsync({nodeId:e,pid:t,force:n})}catch{}},y=async t=>{let i=h.get(t.ppid);if(i===`root`||i===`system`){await r({title:`Cannot kill protected ancestor`,message:i===`root`?`pid ${t.ppid} is the current node supervisor. Restart the node via the cluster page instead.`:`pid ${t.ppid} is a system ancestor (concurrently / vite / npm wrapper). Killing it would tear down the dev tree.`,confirmLabel:`OK`,cancelLabel:`Close`,variant:`warning`});return}await r({title:`Kill ghost parent + ${t.children.length} child(ren)?`,message:`SIGKILL parent pid ${t.ppid} and SIGTERM ${t.children.length} ghost child(ren) on node ${e}.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all([v(t.ppid,!0),...t.children.map(e=>v(e.pid,!1))]),n.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},b=async()=>{let t=d.filter(e=>e.classification===`ghost`);t.length!==0&&await r({title:`Kill all ${t.length} ghost process(es)?`,message:`SIGKILL ${t.length} ghost process(es) on node ${e}. This is irreversible.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all(t.map(e=>v(e.pid,!0))),n.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},x=d.filter(e=>e.classification===`ghost`).length,S=d.filter(e=>e.classification===`managed`).length,C=d.filter(e=>e.classification===`root`).length,w=d.filter(e=>e.classification===`system`).length;return E(`div`,{className:`space-y-4`,children:[E(`div`,{className:`flex items-start justify-between gap-4`,children:[E(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`ps`," scan + kernel `$process.list` cross-reference. Ghosts = camstack-shaped commands with no managed binding (usually orphaned to ppid=1). Refreshes every 10s."]}),E(`button`,{type:`button`,onClick:()=>n.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[j(F,{className:`h-3 w-3`}),` Refresh`]})]}),E(`div`,{className:`grid grid-cols-4 gap-3`,children:[E(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Root`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:C})]}),E(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Managed`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:S})]}),E(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`System`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:w})]}),E(`div`,{className:`rounded-lg border p-3 ${x>0?`border-destructive/40 bg-destructive/5`:`border-border`}`,children:[E(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle flex items-center gap-1`,children:[x>0&&j(Q,{className:`h-3 w-3 text-destructive`}),` Ghosts`]}),j(`div`,{className:`text-xl font-semibold ${x>0?`text-destructive`:`text-foreground`}`,children:x})]})]}),p.length>0&&E(`div`,{className:`rounded-lg border border-amber-500/40 bg-amber-500/5 p-3`,children:[E(`div`,{className:`flex items-center gap-1 text-[11px] font-semibold text-amber-400 mb-2`,children:[j(ie,{className:`h-3 w-3`}),` Recurring ghost parents (`,p.length,`)`]}),j(`div`,{className:`space-y-1.5`,children:p.map(e=>E(`div`,{className:`text-[11px] text-foreground flex items-center justify-between gap-2`,children:[E(`div`,{className:`flex items-center gap-2`,children:[E(`span`,{className:`font-mono text-foreground-subtle`,children:[`ppid `,e.ppid]}),E(`span`,{children:[`→ `,e.children.length,` ghost(s)`]})]}),E(`button`,{type:`button`,disabled:m.isPending,onClick:()=>{y(e)},className:`inline-flex items-center gap-1 rounded border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-400 hover:bg-amber-500/20 disabled:opacity-30`,children:[j(Q,{className:`h-3 w-3`}),` Kill parent + `,e.children.length]})]},e.ppid))})]}),E(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[E(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Filter:`}),E(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${i===`all`?`bg-primary text-primary-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>a(`all`),children:[`All (`,d.length,`)`]}),E(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${i===`ghost`?`bg-destructive text-destructive-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>a(`ghost`),children:[`Ghost only (`,x,`)`]})]}),x>0&&E(`button`,{type:`button`,disabled:m.isPending,onClick:()=>{b()},className:`inline-flex items-center gap-1 rounded border border-destructive/40 bg-destructive/10 px-2 py-1 text-[11px] font-medium text-destructive hover:bg-destructive/20 disabled:opacity-30`,children:[j(Q,{className:`h-3 w-3`}),` Kill all `,x,` ghost(s)`]})]}),j(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:E(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`bg-surface`,children:E(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[j(`th`,{className:`text-left px-3 py-2`,children:`Class`}),j(`th`,{className:`text-right px-3 py-2`,children:`PID`}),j(`th`,{className:`text-right px-3 py-2`,children:`PPID`}),j(`th`,{className:`text-left px-3 py-2`,children:`Addon`}),j(`th`,{className:`text-left px-3 py-2`,children:`Command`}),j(`th`,{className:`text-right px-3 py-2`,children:`CPU%`}),j(`th`,{className:`text-right px-3 py-2`,children:`RSS`}),j(`th`,{className:`text-right px-3 py-2`,children:`Uptime`}),j(`th`,{className:`w-44`})]})}),E(`tbody`,{children:[f.length===0&&j(`tr`,{children:j(`td`,{colSpan:9,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:i===`ghost`?`No ghost processes detected.`:`Scanning…`})}),f.map(e=>E(`tr`,{className:`border-t border-border ${e.classification===`ghost`?`bg-destructive/5`:``}`,children:[j(`td`,{className:`px-3 py-2`,children:j(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`ghost`?`bg-destructive/20 text-destructive`:e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})}),j(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.pid}),E(`td`,{className:`px-3 py-2 text-right font-mono text-foreground-subtle`,children:[e.ppid,e.orphaned?` ⚠`:``]}),j(`td`,{className:`px-3 py-2 text-foreground-subtle text-[11px]`,children:e.addonId??`—`}),j(`td`,{className:`px-3 py-2 font-mono text-[10px] text-foreground-subtle break-all`,children:_e(e.command)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:e.cpuPercent.toFixed(1)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:G(e.memoryRssBytes)}),j(`td`,{className:`px-3 py-2 text-right text-foreground-subtle`,children:ge(e.uptimeSec)}),j(`td`,{className:`px-3 py-2 text-right`,children:E(`div`,{className:`inline-flex gap-1`,children:[E(`button`,{type:`button`,disabled:m.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{_(e,!1)},title:`SIGTERM`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-border text-[10px] text-foreground hover:bg-surface-hover disabled:opacity-30`,children:[j(U,{className:`h-3 w-3`}),` Term`]}),E(`button`,{type:`button`,disabled:m.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{_(e,!0)},title:`SIGKILL`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-destructive/30 text-[10px] text-destructive hover:bg-destructive/10 disabled:opacity-30`,children:[j(Q,{className:`h-3 w-3`}),` Kill`]})]})})]},e.pid))]})]})}),m.isError&&E(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,m.error instanceof Error?m.error.message:`unknown`]})]})}function ye({nodeId:e,addonIds:t}){return t.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No addons on this node`}):j(`div`,{className:`w-full py-2`,children:j(K,{nodeId:e,addonIds:t,level:`global`})})}O();function be({nodeId:e,addons:t}){let n=A(),{data:r,isLoading:a}=i({nodeId:e}),o=D(()=>{let e=new Map;for(let n of t)for(let t of n.capabilities){let r=e.get(t)??[];r.push(n.id),e.set(t,r)}return[...e.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({capName:e,providers:t}))},[t]),s=p({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return o.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No capabilities on this node`}):E(`table`,{className:`w-full text-xs`,children:[j(`thead`,{children:E(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`py-2 font-medium w-1/2`,children:`Capability`}),j(`th`,{className:`py-2 font-medium`,children:`Bound provider`})]})}),j(`tbody`,{children:o.map(({capName:t,providers:n})=>{let i=r?.[t]??n[0]??``,o=n.length===1;return E(`tr`,{className:`border-t border-border/50`,children:[j(`td`,{className:`py-2 font-medium`,children:t}),j(`td`,{className:`py-2`,children:j(`select`,{value:i,onChange:n=>s.mutate({nodeId:e,capName:t,addonId:n.target.value}),disabled:o||s.isPending||a,className:`w-full rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-60`,title:o?`Only one provider installed — choice becomes available once a second addon registers this capability`:void 0,children:n.map(e=>j(`option`,{value:e,children:e},e))})})]},t)})})]})}O();function xe(e){if(e==null)return`—`;let t=Math.floor(e/1e3),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return n>0?`${n}d ${r}h ${i}m`:r>0?`${r}h ${i}m`:`${i}m`}function Se(e){let[t,n]=T(!1),[r,i]=T(e.name),a=A(),o=S({onSuccess:()=>{a.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),s=(e.localIps??[]).filter(e=>!e.includes(`:`)),c=(e.localIps??[]).filter(e=>e.includes(`:`)),l=async()=>{if(!r.trim()||r===e.name){n(!1);return}try{await o.mutateAsync({nodeId:e.nodeId,name:r.trim()}),n(!1)}catch(e){console.error(`Rename failed:`,e)}},u=[[`Node ID`,j(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,t?E(`div`,{className:`flex items-center gap-1.5`,children:[j(`input`,{type:`text`,className:`flex-1 px-2 py-0.5 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary`,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&l(),e.key===`Escape`&&n(!1)},disabled:o.isPending,autoFocus:!0}),j(`button`,{onClick:()=>void l(),disabled:o.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:`Save`,children:j(ee,{className:`h-3.5 w-3.5`})}),j(`button`,{onClick:()=>n(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:`Cancel`,children:j(ne,{className:`h-3.5 w-3.5`})})]}):E(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&j(`button`,{onClick:()=>{i(e.name),n(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:`Rename`,children:j(N,{className:`h-3 w-3`})})]})],[`Hostname`,j(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:`Hub`}):j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`Agent`})],[`Platform`,E(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,E(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,e.cpuCores,` cores)`]})],[`Memory`,j(`span`,{className:`text-xs`,children:e.memoryMB>0?`${(e.memoryMB/1024).toFixed(1)} GB`:`—`})],[`Uptime`,j(`span`,{className:`text-xs`,children:xe(e.uptime)})],[`Engines`,e.engines.length>0?j(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e))}):j(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return s.length>0&&u.push([`IPv4`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:s.map((e,t)=>j(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),c.length>0&&u.push([`IPv6`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map((e,t)=>j(`span`,{className:`font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]`,title:e,children:e},`${e}-${t}`))})]),j(`div`,{className:`py-2`,children:j(`table`,{className:`w-full text-sm`,children:j(`tbody`,{children:u.map(([e,t],n)=>E(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[j(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),j(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}O();function Ce({node:e}){let[t,n]=T(`info`),r=e.processes??[],i=e.addons.map(e=>e.id);return e.isOnline?E(`div`,{className:`border border-border rounded-xl overflow-hidden`,children:[E(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),E(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),E(`div`,{className:`ml-auto flex gap-3 text-xs text-muted-foreground`,children:[E(`span`,{className:`flex items-center gap-1`,children:[j(re,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),E(`span`,{className:`flex items-center gap-1`,children:[j(se,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),j(`div`,{className:`flex border-b border-border px-4`,children:[`info`,`addons`,`forks`,`processes`,`settings`,`capabilities`].map(i=>j(`button`,{onClick:()=>n(i),className:`px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===i?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:i===`info`?`Info`:i===`addons`?`Addons (${e.addons.length})`:i===`forks`?`Forks (${r.length})`:i===`processes`?`Processes`:i===`settings`?`Settings`:`Capabilities`},i))}),E(`div`,{className:`px-4 py-2`,children:[t===`info`&&j(Se,{nodeId:e.id,name:e.name,hostname:e.hostname,platform:e.platform,arch:e.arch,cpuModel:e.cpuModel,cpuCores:e.cpuCores,memoryMB:e.memoryMB,engines:e.engines,isHub:e.isHub,uptime:e.uptime,localIps:e.localIps}),t===`addons`&&j(ue,{nodeId:e.id,addons:e.addons,isHub:e.isHub}),t===`forks`&&j(he,{nodeId:e.id,processes:r}),t===`processes`&&j(ve,{nodeId:e.id}),t===`settings`&&j(ye,{nodeId:e.id,addonIds:i}),t===`capabilities`&&j(be,{nodeId:e.id,addons:e.addons})]})]}):E(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[E(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),E(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),j(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`})]}),E(`div`,{className:`px-4 py-3 text-xs text-muted-foreground`,children:[e.addons.length,` addon`,e.addons.length===1?``:`s`,` assigned — will resume when node reconnects`]})]})}O();function we({nodes:e,focusNodeId:t,focusNonce:n}){let r=[...e].toSorted((e,t)=>e.isHub?-1:t.isHub?1:e.isOnline&&!t.isOnline?-1:!e.isOnline&&t.isOnline?1:e.name.localeCompare(t.name)),i=C(null);return M(()=>{if(!t)return;let e=i.current?.querySelector(`#node-card-${CSS.escape(t)}`);e&&e.scrollIntoView({behavior:`smooth`,block:`start`})},[t,n]),j(`div`,{ref:i,className:`flex flex-col gap-4`,children:r.map(e=>j(`div`,{id:`node-card-${e.id}`,children:j(Ce,{node:e})},e.id))})}O();function Te(e){return e===`running`||e===`online`?`bg-success`:e===`crashed`||e===`failed`?`bg-destructive`:`bg-muted-foreground`}function Ee({runner:e,nodeId:t,expanded:n,pid:r,onToggleCaps:i}){let[a,o]=T(!1),c=s();function l(){c.mutateAsync({nodeId:t,addonId:e.addonId})}function u(){o(e=>!e)}return E(`div`,{className:`border border-border rounded-md px-2 py-1.5 text-xs space-y-1`,children:[E(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[j(`span`,{className:`shrink-0 h-1.5 w-1.5 rounded-full ${Te(e.state)}`,"aria-label":`status: ${e.state}`}),j(`span`,{className:`font-medium truncate flex-1 min-w-0`,children:e.name}),E(`span`,{className:`shrink-0 text-muted-foreground`,children:[e.cpu.toFixed(1),`%`]}),j(`span`,{className:`shrink-0 text-muted-foreground`,children:G(e.mem)}),E(`button`,{type:`button`,"aria-label":`caps: ${e.caps.length}`,onClick:()=>i(r),className:`shrink-0 inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-muted text-muted-foreground hover:bg-muted/80`,children:[j(n?B:z,{className:`h-2.5 w-2.5`,"aria-hidden":!0}),E(`span`,{children:[`caps: `,e.caps.length]})]}),j(`button`,{type:`button`,"aria-label":`Restart addon`,onClick:l,className:`shrink-0 p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted`,children:j(I,{className:`h-3 w-3`})}),j(`button`,{type:`button`,"aria-label":`Logs`,onClick:u,className:`shrink-0 p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted`,children:j(H,{className:`h-3 w-3`})})]}),n&&e.caps.length>0&&j(`ul`,{className:`pl-3 space-y-0.5`,children:e.caps.map(e=>E(`li`,{className:`text-muted-foreground`,children:[j(`span`,{className:`text-foreground`,children:e.name}),` · `,j(`span`,{children:e.addonId})]},`${e.name}\0${e.addonId}`))}),a&&j(f,{addonId:e.addonId,agentId:t,showScope:!0,onClose:()=>o(!1)})]})}O();function De(e){return e?`bg-success`:`bg-muted-foreground`}function $({data:e}){let[t,n]=T(new Set),r=w(e=>{n(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]);return M(()=>{e.expandAllNonce!==0&&(e.expandAllValue?n(new Set(e.runners.map(e=>e.pid))):n(new Set))},[e.expandAllNonce,e.expandAllValue,e.runners]),E(`div`,{className:`border border-border rounded-xl bg-background shadow-md min-w-[280px] max-w-[360px] flex flex-col${e.isOnline?``:` opacity-50`}`,children:[j(X,{type:`target`,position:q.Left}),j(X,{type:`source`,position:q.Right}),E(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[j(`span`,{className:`text-[10px] font-semibold px-1.5 py-0.5 rounded bg-muted text-muted-foreground shrink-0`,children:e.isHub?`HUB`:`AGENT`}),j(`span`,{className:`h-2 w-2 rounded-full shrink-0 ${De(e.isOnline)}`,"aria-label":e.isOnline?`online`:`offline`}),j(`span`,{className:`font-semibold text-sm truncate flex-1 min-w-0`,children:e.identity.name}),j(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:e.identity.ip}),E(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:[e.identity.cpu,`%`]}),E(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:[e.identity.mem,`%`]}),j(`button`,{type:`button`,"aria-label":`Open node detail`,onClick:()=>e.onOpenNodeDetail(e.nodeId),className:`shrink-0 text-xs text-muted-foreground hover:text-foreground underline-offset-2 hover:underline ml-1`,children:`↗`})]}),E(`div`,{className:`flex flex-col gap-1 p-2 max-h-96 overflow-auto`,children:[e.runners.map(n=>j(Ee,{runner:n,nodeId:e.nodeId,expanded:t.has(n.pid),onToggleCaps:r,pid:n.pid},n.pid)),e.runners.length===0&&j(`span`,{className:`text-xs text-muted-foreground px-1`,children:`No processes`})]})]})}O();var Oe={nodeBox:$};function ke(e,t){let n=new Map,r=0,i=0;for(let a=0;a<e.length;a++){let o=e[a];o!==void 0&&(t[a]?(n.set(o,{x:0,y:i*340}),i++):(n.set(o,{x:480,y:r*340}),r++))}return n}function Ae(e,t){if(e===``)return!0;let n=e.toLowerCase();return t.identity.name.toLowerCase().includes(n)?!0:t.runners.some(e=>e.name.toLowerCase().includes(n)||e.addonId.toLowerCase().includes(n)||e.caps.some(e=>e.name.toLowerCase().includes(n)||e.addonId.toLowerCase().includes(n)))}function je({graph:e,onOpenNodeDetail:t}){let[n,r]=T(``),[i,a]=T(!1),[o,s]=T(0),c=w(()=>{a(!0),s(e=>e+1)},[]),l=w(()=>{a(!1),s(e=>e+1)},[]),u=w(e=>{t?.(e)},[t]),d=D(()=>ke(e.nodes.map(e=>e.nodeId),e.nodes.map(e=>e.isHub)),[e.nodes]),f=D(()=>e.nodes.map(e=>{let t=d.get(e.nodeId)??{x:0,y:0},r={...e,onOpenNodeDetail:u,expandAllValue:i,expandAllNonce:o},a=n!==``&&!Ae(n,r);return{id:e.nodeId,type:`nodeBox`,position:t,data:r,hidden:a}}),[e.nodes,d,u,n,i,o]),p=D(()=>e.edges.map(e=>({id:e.id,source:e.source,target:e.target,label:`moleculer`,style:e.online?{}:{strokeDasharray:`5,5`,opacity:.4},animated:!1})),[e.edges]);return E(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[E(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[j(`input`,{type:`search`,placeholder:`Filter by node / runner / cap…`,value:n,onChange:e=>r(e.target.value),className:`flex-1 text-xs border border-border rounded px-2 py-1 bg-background focus:outline-none focus:ring-1 focus:ring-ring`}),j(`button`,{type:`button`,onClick:c,className:`text-xs px-2 py-1 rounded border border-border hover:bg-muted`,children:`Expand all`}),j(`button`,{type:`button`,onClick:l,className:`text-xs px-2 py-1 rounded border border-border hover:bg-muted`,children:`Collapse all`})]}),j(`div`,{className:`flex-1 min-h-0 border-t border-border overflow-hidden`,children:E(J,{nodes:f,edges:p,nodeTypes:Oe,fitView:!0,proOptions:{hideAttribution:!0},children:[j(ae,{gap:20,size:1}),j(Y,{showInteractive:!1})]})})]})}function Me(e){if(e===void 0||e.length===0)return[];let t=new Set,n=[];for(let r of e)for(let e of r.capabilities){let i=`${e}\0${r.addonId}`;t.has(i)||(t.add(i),n.push({name:e,addonId:r.addonId}))}return n.toSorted((e,t)=>e.name.localeCompare(t.name))}function Ne(e){let t=e.services;return{pid:e.pid,name:e.name,addonId:t?.[0]?.addonId??``,cpu:e.cpuPercent,mem:e.memoryRss,state:e.state,caps:Me(t)}}function Pe(e){return{nodeId:e.id,isHub:e.isHub,isOnline:e.isOnline,identity:{name:e.name,ip:e.localIps?.[0]??``,cpu:e.cpuPercent,mem:e.memoryPercent,platform:e.platform,arch:e.arch},runners:e.processes.map(Ne)}}function Fe(e){let t=e.toSorted((e,t)=>{let n=+!!e.isHub;return+!!t.isHub-n}).map(Pe),n=t.find(e=>e.isHub);return n===void 0?{nodes:t,edges:[]}:{nodes:t,edges:t.filter(e=>!e.isHub).map(e=>({id:`hub:${n.nodeId}->${e.nodeId}`,source:n.nodeId,target:e.nodeId,online:e.isOnline&&n.isOnline}))}}O();function Ie({onlineNodeIds:e}){let r=A(),i=t(),{data:a,isLoading:s}=n(),c=o({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]})}}),l=D(()=>{if(!a)return[];let t=new Set(e);return t.add(`hub`),a.filter(e=>!t.has(e.nodeId))},[a,e]);if(s)return j(`section`,{className:`rounded-lg border border-border bg-surface p-6 text-xs text-muted-foreground animate-pulse`,children:`Loading persisted agent settings…`});let u=async e=>{await i({title:`Remove offline agent?`,message:`Drop the persisted orchestrator settings for "${e}". This won't affect a node that comes back online — it just clears stale addonDefaults so it stops cluttering the cluster view.`,confirmLabel:`Remove`,cancelLabel:`Keep`,variant:`danger`})&&c.mutate({agentNodeId:e})};return l.length===0?j(`section`,{className:`rounded-lg border border-border bg-surface p-6`,children:E(`div`,{className:`flex flex-col items-center gap-2 text-center text-muted-foreground`,children:[j(Z,{className:`h-6 w-6 opacity-40`}),j(`p`,{className:`text-xs`,children:`No stale agent entries.`}),j(`p`,{className:`text-[11px] opacity-60`,children:`Every persisted nodeId matches a node currently online in the cluster.`})]})}):E(`section`,{className:`rounded-lg border border-border bg-surface`,children:[E(`header`,{className:`flex items-center gap-2 px-4 py-3 border-b border-border`,children:[j(Z,{className:`h-4 w-4 text-muted-foreground`}),j(`h2`,{className:`text-sm font-semibold`,children:`Offline agents`}),E(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,children:[l.length,` stale `,l.length===1?`entry`:`entries`]})]}),j(`p`,{className:`px-4 pt-3 text-[11px] text-muted-foreground`,children:`Persisted orchestrator settings for nodes not currently in the live topology. Remove entries you don't expect to come back — leftover from data-dir resets, env-driven nodeId changes, or decommissioned hosts.`}),j(`ul`,{className:`divide-y divide-border`,children:l.map(e=>{let t=Object.keys(e.settings.addonDefaults??{}).length,n=Object.values(e.settings.addonDefaults??{}).filter(e=>e?.enabled).length;return E(`li`,{className:`flex items-center gap-3 px-4 py-2 text-xs`,children:[j(`span`,{className:`font-mono text-foreground`,children:e.nodeId}),E(`span`,{className:`text-muted-foreground`,children:[t,` addons configured`,t>0&&E(k,{children:[` · `,n,` enabled`]})]}),E(`button`,{type:`button`,onClick:()=>{u(e.nodeId)},disabled:c.isPending,className:`ml-auto flex items-center gap-1 px-2 py-1 rounded text-destructive hover:bg-destructive/10 disabled:opacity-50`,children:[j(U,{className:`h-3 w-3`}),`Remove`]})]},e.nodeId)})})]})}O();function Le(e){let[t,n]=T(()=>typeof window<`u`?window.matchMedia(e).matches:!1);return M(()=>{let t=window.matchMedia(e),r=e=>n(e.matches);return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}function Re(){let{data:t,isLoading:n}=e(void 0,{staleTime:1/0}),[r,i]=T(null);return a(`cluster.topology-snapshot`,e=>{let t=e.data?.nodes;Array.isArray(t)&&i(t)}),{nodes:D(()=>r??t??[],[r,t]),isLoading:n&&!r}}function ze(){let[e,t]=T(`table`),[r,i]=T(void 0),[a,o]=T(0),s=Le(`(max-width: 767px)`),c=s&&e===`graph`?`table`:e,{nodes:l,isLoading:u}=Re(),d=D(()=>Fe(l),[l]),f=l.filter(e=>e.isOnline).length,p=l.filter(e=>!e.isOnline).length,m=D(()=>l.map(e=>e.id??``).filter(Boolean),[l]),{data:h}=n(),g=D(()=>{if(!h)return 0;let e=new Set(m);return e.add(`hub`),h.filter(t=>!e.has(t.nodeId)).length},[h,m]),_=w(e=>{t(`table`),i(e),o(e=>e+1)},[]),v=(n,r,i,a)=>E(`button`,{onClick:()=>t(n),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${e===n?`bg-primary text-primary-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[j(i,{className:`h-3.5 w-3.5`}),r,a!==void 0&&a>0&&j(`span`,{className:`ml-1 inline-flex h-4 min-w-[1rem] items-center justify-center rounded-full px-1 text-[10px] font-semibold ${e===n?`bg-primary-foreground/20 text-primary-foreground`:`bg-destructive/15 text-destructive`}`,children:a})]});return E(`div`,{className:`flex flex-col h-full gap-4 p-4`,children:[E(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[E(`div`,{className:`flex items-center gap-2`,children:[f>0&&E(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-success/10 text-success`,children:[f,` online`]}),p>0&&E(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:[p,` offline`]})]}),E(`div`,{className:`flex gap-0.5 p-1 rounded-lg bg-muted`,children:[v(`table`,`Table`,ce),!s&&v(`graph`,`Graph`,oe),v(`offline-agents`,`Offline agents`,Z,g)]})]}),u?j(`div`,{className:`flex items-center justify-center flex-1 text-muted-foreground`,children:`Loading cluster topology...`}):c===`graph`?j(je,{graph:d,onOpenNodeDetail:_}):c===`table`?j(`div`,{className:`flex-1 overflow-auto`,children:j(we,{nodes:l,focusNodeId:r,focusNonce:a})}):j(`div`,{className:`flex-1 overflow-auto`,children:j(Ie,{onlineNodeIds:m})})]})}export{ze as ClusterPage};
@@ -1 +0,0 @@
1
- import{At as e,Ft as t,Hi as n,It as r,Ji as i,Mt as a,Nt as o,Ot as s,Pt as c,fi as l,ft as u,gi as d,jt as f,kt as p,mi as m,pi as h}from"./src-B7BVQkY2.js";import{I as g,K as _,S as v,W as y,Z as b,b as x,o as S,x as C,z as w}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{D as T}from"./src-D7qnpDWK.js";import{t as E}from"./download-BXqeElYK.js";import{i as D,n as O,r as k,t as A}from"./AddLocationWizard-DlIuy7PK.js";import{t as j}from"./plus-ByEqM_KR.js";import{t as M}from"./rotate-cw-Dq3dsGth.js";import{M as N,P,V as F,i as I,s as L,x as R,z as ee}from"./index-idVLv2oj.js";import{t as z}from"./AdminPage-vtcsGqRq.js";import{t as B}from"./format-size-CO9d3C3-.js";import{t as V}from"./AdminTabs-Cyrx86NX.js";var H=F(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),te=F(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),ne=F(`calendar-clock`,[[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M17.5 17.5 16 16.3V14`,key:`akvzfd`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]);b();function U(){let e=S(),t=n(),{data:r,isLoading:i,isError:a}=m({}),o=h(),s=y(()=>o.data??[],[o.data]),[c,u]=_(null),[f,p]=_(null),g=l({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),b=d({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),x=e=>{e.isDefault||b.mutate({id:e.id,type:e.type,providerId:e.providerId,displayName:e.displayName,config:e.config,isDefault:!0})},w=async e=>{if(e.isDefault){await t({title:`Cannot delete default location`,message:`"${e.displayName}" is the default for type "${e.type}". Mark another location as default first, then delete this one.`,confirmLabel:`OK`,variant:`warning`});return}await t({title:`Delete location "${e.displayName}"?`,message:`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`,confirmLabel:`Delete`,variant:`danger`})&&g.mutate({id:e.id})},T=y(()=>{let e=new Map;for(let t of r??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[r]),E=i||o.isLoading,D=a||o.isError;return v(z,{children:[E&&C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),D&&C(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!E&&!D&&v(`div`,{className:`space-y-3`,children:[s.length===0&&C(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),s.map(e=>C(k,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:T.get(e.id)??[],onAdd:e=>u(e),onEdit:e=>p(e),onDelete:e=>{w(e)},onSetDefault:e=>x(e)},e.id))]}),c!==null&&C(A,{initialType:c,onClose:()=>u(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),u(null)}}),f!==null&&C(O,{location:f,onClose:()=>p(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),p(null)}})]})}b();var W=[[`backup`,`listDestinations`]],G=[`backup`,`listArchives`];function K({destinationId:t,restoreSupported:r,onOpenRestoreWizard:i}){let a=S(),o=n(),{data:c,isLoading:l,isError:u}=e({destinationId:t}),d=c??[],f=s({onSuccess:()=>{a.invalidateQueries({queryKey:[[...G]]}),a.invalidateQueries({queryKey:W})}}),p=g(async e=>{await o({title:`Delete this archive?`,message:`Permanently deletes "${e.label??e.id}" and frees ${B(e.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&f.mutate({destinationId:t,backupId:e.id})},[o,t,f]),[m,h]=_(null),b=g(async e=>{h(e.id);try{let n=localStorage.getItem(`camstack_admin_token`),r={};n&&(r.Authorization=`Bearer ${n}`);let i=await fetch(q(t,e.id),{headers:r});if(!i.ok)throw Error(`download failed: ${i.status} ${i.statusText}`);let a=await i.blob(),o=URL.createObjectURL(a),s=document.createElement(`a`);s.href=o,s.download=`${e.label??e.id}.tar.gz`,document.body.appendChild(s),s.click(),s.remove(),URL.revokeObjectURL(o)}finally{h(null)}},[t]),x=y(()=>[...d].toSorted((e,t)=>t.createdAt-e.createdAt),[d]);return l?C(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):u?C(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):x.length===0?C(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):C(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:v(`table`,{className:`w-full text-xs min-w-[640px]`,children:[C(`thead`,{children:v(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),C(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),C(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),C(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),C(`tbody`,{children:x.map(e=>v(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[C(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:J(e.createdAt)}),C(`td`,{className:`px-3 py-1.5 text-foreground`,children:e.label??C(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),C(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:e.locations.join(`, `)}),C(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:B(e.sizeBytes)}),C(`td`,{className:`px-3 py-1.5`,children:v(`div`,{className:`flex items-center justify-end gap-1`,children:[v(`button`,{onClick:()=>{b(e)},disabled:m===e.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 disabled:opacity-50`,title:`Download archive`,children:[m===e.id?C(R,{className:`h-3 w-3 animate-spin`}):C(E,{className:`h-3 w-3`}),`Download`]}),r&&i&&v(`button`,{onClick:()=>i({destinationId:t,archiveId:e.id}),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10`,title:`Restore from this archive`,children:[C(M,{className:`h-3 w-3`}),`Restore`]}),C(`button`,{onClick:()=>{p(e)},disabled:f.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete archive`,children:f.isPending?C(R,{className:`h-3 w-3 animate-spin`}):C(L,{className:`h-3 w-3`})})]})})]},e.id))})]})})}function q(e,t){return`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function J(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}b();var Y=[{id:`manual`,label:`Manual only`,cron:``},{id:`hourly`,label:`Every hour`,cron:`0 * * * *`,description:`On the hour`},{id:`every-3h`,label:`Every 3 hours`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,label:`Every 6 hours`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,label:`Daily at 03:00`,cron:`0 3 * * *`,description:`Every night at 3 AM`},{id:`weekly-sun`,label:`Weekly Sunday 03:00`,cron:`0 3 * * 0`,description:`Sunday morning at 3 AM`}];function X(e){let t=e.trim();for(let e of Y)if(e.cron===t)return e.id;return`custom`}function Z({value:e,onChange:t,previewCount:n=5,disabled:r=!1}){let i=X(e),[a,s]=_(i===`custom`);w(()=>{i!==`custom`&&s(!1)},[i]);let c=ae(e,250),l=o({cron:c,count:n},{enabled:c.trim().length>0}),u=l.data??null,d=e=>{s(!1),t(e.cron)},f=a||i===`custom`;return v(`div`,{className:`space-y-3`,children:[v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),v(`div`,{className:`flex flex-wrap gap-1.5`,children:[Y.map(e=>C(`button`,{type:`button`,onClick:()=>d(e),disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!a&&i===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.description??e.label,children:e.label},e.id)),C(`button`,{type:`button`,onClick:()=>{s(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(f?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),f&&v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),C(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:r,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),v(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,C(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),C(re,{cron:c,preview:u,loading:l.isFetching})]})}function re({cron:e,preview:t,loading:n}){return n&&t===null?v(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[C(R,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?C(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:`No future runs match this expression.`}):v(`div`,{className:`space-y-1`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),C(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>v(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[C(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),C(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:ie(e)})]},`${e}-${t}`))})]}):C(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??`Invalid cron expression`})}function ie(e){let t=e-Date.now();if(t<=0)return`now`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function ae(e,t){let[n,r]=_(e),i=y(()=>e,[e]);return w(()=>{let e=setTimeout(()=>r(i),t);return()=>clearTimeout(e)},[i,t]),n}b();var oe=[[`backup`,`listDestinations`]];function se({onCreateAt:e,onOpenRestoreWizard:t}){let{data:n,isLoading:r,isError:i}=f(),a=n??[],[o,s]=_(null),c=e=>{s(t=>t===e?null:e)},l=fe();return r?C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading destinations…`}):i?C(`div`,{className:`text-xs text-danger`,children:`Failed to load destinations`}):a.length===0?C(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:C(`p`,{className:`text-xs text-foreground-subtle`,children:"No `backups`-typed storage locations registered. Add one in Settings → Storage to begin."})}):C(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:v(`table`,{className:`w-full text-xs min-w-[720px]`,children:[C(`thead`,{children:v(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[C(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),C(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Destination`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-28`,children:`Retention`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-56`,children:`Schedule`}),C(`th`,{className:`text-left px-3 py-2 font-medium w-44`,children:`Last success`}),C(`th`,{className:`text-right px-3 py-2 font-medium w-44`,children:`Actions`})]})}),C(`tbody`,{children:a.map(n=>{let r=l.get(n.id);return C(ce,{row:n,isOpen:o===n.id,onToggle:()=>c(n.id),onCreateAt:e,liveLastSuccessAt:r?.at,liveLastSuccessSizeBytes:r?.sizeBytes,...t?{onOpenRestoreWizard:t}:{}},n.id)})})]})})}function ce({row:e,isOpen:t,onToggle:n,onCreateAt:i,onOpenRestoreWizard:a,liveLastSuccessAt:o,liveLastSuccessSizeBytes:s}){let c=S(),l=r({onSuccess:()=>{c.invalidateQueries({queryKey:oe})}}),[u,d]=_(String(e.retentionCount));w(()=>{d(String(e.retentionCount))},[e.retentionCount]);let[f,p]=_(!1),m=g(t=>{l.mutate({locationId:e.id,enabled:t,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[l,e.id,e.retentionCount,e.label,e.cron]),h=g(()=>{let t=Number.parseInt(u,10);if(Number.isNaN(t)||t<1){d(String(e.retentionCount));return}t!==e.retentionCount&&l.mutate({locationId:e.id,enabled:e.enabled,retentionCount:t,...e.label===void 0?{}:{label:e.label},...e.cron===void 0?{}:{cron:e.cron}})},[l,u,e.id,e.enabled,e.retentionCount,e.label,e.cron]),y=g(t=>{l.mutate({locationId:e.id,enabled:e.enabled,retentionCount:e.retentionCount,...e.label===void 0?{}:{label:e.label},cron:t},{onSuccess:()=>{p(!1)}})},[l,e.id,e.enabled,e.retentionCount,e.label]);return v(x,{children:[v(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[C(`td`,{className:`px-2 py-2`,children:C(`button`,{onClick:n,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:t?`Hide archives`:`Show archives`,children:C(t?P:N,{className:`h-3.5 w-3.5`})})}),C(`td`,{className:`px-3 py-2`,children:v(`button`,{onClick:n,className:`text-left hover:underline focus:outline-none`,title:`View archives`,children:[C(`div`,{className:`text-foreground font-medium`,children:e.displayName}),v(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[C(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-background border border-border rounded px-1.5 py-0.5`,children:e.kind}),C(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]})}),C(`td`,{className:`px-3 py-2`,children:C(`label`,{className:`inline-flex items-center cursor-pointer`,children:C(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:l.isPending,onChange:e=>m(e.target.checked)})})}),C(`td`,{className:`px-3 py-2`,children:C(`input`,{type:`number`,min:1,max:1e3,value:u,disabled:l.isPending,onChange:e=>d(e.target.value),onBlur:h,onKeyDown:t=>{t.key===`Enter`&&t.target.blur(),t.key===`Escape`&&d(String(e.retentionCount))},className:`w-16 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})}),C(`td`,{className:`px-3 py-2`,children:C(le,{cron:e.cron,nextRunAt:e.nextRunAt,onEdit:()=>p(!0),disabled:l.isPending})}),C(`td`,{className:`px-3 py-2 text-foreground-subtle`,children:(()=>{let t=pe(o,e.lastSuccessAt),n=t===o?s:e.lastSuccessSizeBytes;return t===void 0?C(`span`,{className:`italic`,children:`Never`}):C(me,{at:t,sizeBytes:n})})()}),C(`td`,{className:`px-3 py-2`,children:C(`div`,{className:`flex items-center justify-end gap-1.5`,children:e.triggerSupported&&v(`button`,{onClick:()=>i(e),className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90`,children:[C(j,{className:`h-3 w-3`}),`Create here`]})})})]}),t&&C(`tr`,{className:`border-t border-border bg-background/30`,children:C(`td`,{colSpan:7,className:`px-4 py-3`,children:C(K,{destinationId:e.id,restoreSupported:e.restoreSupported,...a?{onOpenRestoreWizard:a}:{}})})}),f&&C(de,{destinationName:e.displayName,currentCron:e.cron??``,onSave:y,onClose:()=>p(!1),saving:l.isPending,saveError:l.error instanceof Error?l.error.message:null})]})}function le({cron:e,nextRunAt:t,onEdit:n,disabled:r}){let i=typeof e==`string`&&e.trim().length>0;return v(`button`,{type:`button`,onClick:n,disabled:r,className:`group flex flex-col items-start gap-0.5 text-left rounded px-1.5 py-1 -mx-1.5 hover:bg-primary/5 disabled:opacity-50`,title:`Edit schedule`,children:[v(`div`,{className:`flex items-center gap-1.5`,children:[C(ne,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),C(`span`,{className:i?`font-mono text-foreground`:`italic text-foreground-subtle`,children:i?e:`Manual`})]}),i&&t!==void 0&&v(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[`next `,ue(t)]})]})}function ue(e){let t=e-Date.now();if(t<=0)return`imminent`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function de({destinationName:e,currentCron:t,onSave:n,onClose:r,saving:i,saveError:a}){let[o,s]=_(t);return C(`tr`,{children:C(`td`,{colSpan:7,className:`p-0`,children:C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:v(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Schedule`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e]})]}),C(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,title:`Close`,children:C(I,{className:`h-4 w-4`})})]}),v(`div`,{className:`p-4`,children:[C(Z,{value:o,onChange:s,disabled:i}),a!==null&&C(`div`,{className:`mt-3 rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:a})]}),v(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[C(`button`,{onClick:r,disabled:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground disabled:opacity-50`,children:`Cancel`}),C(`button`,{onClick:()=>n(o.trim()),disabled:i||o.trim()===t.trim(),className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:i?`Saving…`:`Save`})]})]})})})})}function fe(){let{map:e}=i(T.BackupCompleted,e=>e.destinationId);return y(()=>{let t=new Map;for(let[n,r]of e)t.set(n,{at:Date.now(),sizeBytes:r.sizeMB*1024*1024});return t},[e])}function pe(e,t){return e===void 0?t:t===void 0||e>t?e:t}function me({at:e,sizeBytes:t}){let n=he(e);return v(`span`,{title:y(()=>new Date(e).toLocaleString(),[e]),className:`text-foreground tabular-nums`,children:[n,t!==void 0&&v(`span`,{className:`ml-1 text-foreground-subtle`,children:[`· `,B(t)]})]})}function he(e){let[,t]=_(0);return w(()=>{let e=setInterval(()=>t(e=>e+1),3e4);return()=>clearInterval(e)},[]),ge(e)}function ge(e){let t=Math.max(0,Date.now()-e),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(a/365)}y ago`}b();var _e=[[`backup`,`list`]];function ve({initialDestinationId:t,initialArchiveId:n,onClose:r,onScheduled:i}){let a=S(),[o,s]=_(t&&n?2:1),[l,u]=_(t),[d,m]=_(n),[h,g]=_(new Set),{data:b}=f(),x=b??[],{data:T,isLoading:E}=e({destinationId:l??``},{enabled:!!l}),D=T??[];w(()=>{if(l!==void 0)return;let e=x.filter(e=>e.restoreSupported);e.length===1&&u(e[0].id)},[l,x]);let{data:O}=p({destinationId:l??``,backupId:d??``},{enabled:!!l&&!!d}),k=y(()=>O?.locations??[],[O]);w(()=>{k.length!==0&&g(e=>e.size===0?new Set(k):e)},[k]);let A=c({onSuccess:()=>{a.invalidateQueries({queryKey:_e}),i(),r()}}),j=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},N=!!l&&!!d,P=h.size>0,F=N&&P&&!A.isPending,L=()=>{!l||!d||A.mutate({destinationId:l,backupId:d,locations:[...h]})};return C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:r,children:v(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,o,` of 3 —`,` `,o===1?`pick source`:o===2?`pick locations`:`confirm`]})]}),C(`button`,{onClick:r,className:`text-foreground-subtle hover:text-foreground`,children:C(I,{className:`h-4 w-4`})})]}),o===1&&C(ye,{destinations:x,destinationId:l,onPickDestination:e=>{u(e),m(void 0),g(new Set)},archives:D,archivesLoading:E,archiveId:d,onPickArchive:m}),o===2&&C(be,{locations:k,picked:h,onToggle:j}),o===3&&C(xe,{destinationName:x.find(e=>e.id===l)?.displayName??l??``,archive:D.find(e=>e.id===d),picked:[...h]}),v(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[C(`div`,{children:o>1&&v(`button`,{onClick:()=>s(e=>e===3?2:1),className:`inline-flex items-center gap-1 rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:[C(ee,{className:`h-3 w-3`}),`Back`]})}),v(`div`,{className:`flex items-center gap-2`,children:[C(`button`,{onClick:r,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),o<3?v(`button`,{disabled:o===1&&!N||o===2&&!P,onClick:()=>s(e=>e===1?2:3),className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[`Next`,C(te,{className:`h-3 w-3`})]}):v(`button`,{onClick:L,disabled:!F,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[A.isPending?C(R,{className:`h-3.5 w-3.5 animate-spin`}):C(M,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function ye({destinations:e,destinationId:t,onPickDestination:n,archives:r,archivesLoading:i,archiveId:a,onPickArchive:o}){let s=e.filter(e=>e.restoreSupported);return v(`div`,{className:`p-4 space-y-3`,children:[v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),v(`select`,{value:t??``,onChange:e=>n(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[C(`option`,{value:``,disabled:!0,children:`Select destination…`}),s.map(e=>v(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&C(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&i&&C(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!i&&r.length===0&&C(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&r.length>0&&C(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:r.map(e=>{let t=a===e.id;return v(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>o(e.id),className:`accent-primary`}),v(`div`,{children:[C(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),C(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),C(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:B(e.sizeBytes)})]},e.id)})})]})]})}function be({locations:e,picked:t,onToggle:n}){return e.length===0?C(`div`,{className:`p-4`,children:C(`div`,{className:`text-xs text-foreground-subtle`,children:`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`})}):v(`div`,{className:`p-4 space-y-3`,children:[C(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),C(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>v(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[C(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),C(`span`,{className:`font-mono text-foreground`,children:e}),C(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ce(e)})]},e))})]})]})}function xe({destinationName:e,archive:t,picked:n}){return v(`div`,{className:`p-4 space-y-3 text-xs`,children:[C(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300`,children:`Restore is applied at next server boot. Active connections will drop when you restart.`}),v(`dl`,{className:`space-y-1.5`,children:[C(Q,{term:`Destination`,value:e}),C(Q,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&C(Q,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${B(t.sizeBytes)}`}),C(Q,{term:`Locations`,value:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function Q({term:e,value:t}){return v(`div`,{className:`flex justify-between gap-3`,children:[C(`dt`,{className:`text-foreground-subtle`,children:e}),C(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Se={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function Ce(e){return Se[e]??``}b();var $=[[`backup`,`list`]],we=[[`backup`,`listLocations`]];function Te(){let e=S(),r=n(),{data:i}=a(),o=t({onSuccess:()=>{e.invalidateQueries({queryKey:$}),e.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),e.invalidateQueries({queryKey:[[`backup`,`listArchives`]]})}}),s=u(),[c,l]=_(null),[d,f]=_(null),[p,m]=_(!1),[h,g]=_(!1),[y,b]=_(!1),x=async()=>{await r({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&s.mutate({confirm:!0})};return v(z,{children:[v(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[v(`button`,{onClick:()=>m(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[C(M,{className:`h-3.5 w-3.5`}),`Restore…`]}),v(`button`,{onClick:()=>b(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[C(j,{className:`h-3.5 w-3.5`}),`Add destination`]})]}),h&&C(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2.5 text-xs text-amber-700 dark:text-amber-300`,children:v(`div`,{className:`flex items-center justify-between gap-3`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(M,{className:`h-3.5 w-3.5`}),C(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),v(`button`,{onClick:()=>{x()},disabled:s.isPending,className:`inline-flex items-center gap-1.5 rounded bg-amber-500/20 px-2 py-1 font-medium text-amber-800 dark:text-amber-200 hover:bg-amber-500/30 disabled:opacity-50`,children:[s.isPending?C(R,{className:`h-3.5 w-3.5 animate-spin`}):C(M,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),C(se,{onCreateAt:e=>l(e),onOpenRestoreWizard:e=>f(e)}),c&&C(Ee,{destination:c,locations:i??[],onClose:()=>l(null),onSubmit:(t,n)=>{o.mutate({destinations:[c.id],locations:t,label:n||void 0},{onSuccess:()=>{l(null),e.invalidateQueries({queryKey:we})}})},submitting:o.isPending}),(d||p)&&C(ve,{...d?{initialDestinationId:d.destinationId,initialArchiveId:d.archiveId}:{},onClose:()=>{f(null),m(!1)},onScheduled:()=>g(!0)}),y&&C(A,{initialType:`backups`,onClose:()=>b(!1),onCreated:()=>{b(!1),e.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]})}})]})}function Ee({destination:e,locations:t,onClose:n,onSubmit:r,submitting:i}){let a=t.filter(e=>e.present),[o,s]=_(``),[c,l]=_(()=>new Set(a.map(e=>e.name))),u=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return C(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:v(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[v(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[v(`div`,{className:`space-y-0.5`,children:[C(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Create Backup`}),v(`p`,{className:`text-xs text-foreground-subtle`,children:[`→ `,e.displayName]})]}),C(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:C(I,{className:`h-4 w-4`})})]}),v(`div`,{className:`p-4 space-y-3`,children:[v(`div`,{className:`space-y-1`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Label (optional)`}),C(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`pre-upgrade`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),v(`div`,{className:`space-y-1.5`,children:[C(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Include`}),v(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:[a.length===0&&C(`div`,{className:`px-3 py-2 text-xs text-foreground-subtle italic`,children:`Nothing to back up.`}),a.map(e=>v(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[v(`div`,{className:`flex items-center gap-2`,children:[C(`input`,{type:`checkbox`,checked:c.has(e.name),onChange:()=>u(e.name),className:`accent-primary`}),C(`span`,{className:`font-mono text-foreground`,children:e.name})]}),v(`div`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[B(e.sizeBytes),` · `,e.fileCount,` files`]})]},e.name))]})]})]}),v(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[C(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),v(`button`,{onClick:()=>r(Array.from(c),o.trim()),disabled:i||c.size===0,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[i?C(R,{className:`h-3.5 w-3.5 animate-spin`}):C(H,{className:`h-3.5 w-3.5`}),i?`Creating…`:`Create`]})]})]})})}function De(){return C(`div`,{className:`flex flex-col p-4`,children:C(V,{tabs:[{id:`storage`,label:`Storage`,icon:D,content:C(U,{})},{id:`backup`,label:`Backup`,icon:H,content:C(Te,{})}]})})}export{De as DataPage};
@@ -1,2 +0,0 @@
1
- import{$i as e,$n as t,A as n,Cn as r,D as i,Da as a,Dn as o,Dt as s,E as c,Ea as l,En as u,G as d,H as f,Hi as p,Ii as m,J as h,Jr as g,Jt as _,K as v,Kn as y,Kr as b,L as x,Li as S,Lr as C,M as w,On as T,Or as E,Qi as ee,Qn as D,R as O,Ri as te,Sn as k,T as A,Tn as ne,U as re,Vr as j,W as M,Yt as N,_i as ie,_n as ae,a as oe,di as se,dt as ce,ea as le,er as P,f as ue,g as de,gn as F,gr as fe,hn as pe,i as I,in as me,j as he,kn as ge,l as _e,li as ve,ln as ye,m as be,mn as xe,n as Se,na as Ce,ni as we,nn as Te,o as Ee,oa as De,p as Oe,pn as L,q as ke,r as Ae,ra as je,u as R,un as Me,vi as Ne,vn as Pe,wn as Fe,xn as Ie,y as Le,z as Re}from"./src-B7BVQkY2.js";import{G as z,I as B,K as V,S as H,W as U,Z as W,b as ze,o as G,t as Be,x as K,z as q}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";import{c as Ve,k as He,p as J,r as Ue,t as We,u as Ge}from"./player-overlays-BK-_BrgW.js";import{C as Ke,E as qe,b as Y,g as Je,v as Ye}from"./src-D7qnpDWK.js";import{t as Xe}from"./CapabilityBadges-C7OuLfh8.js";import{n as Ze,t as Qe}from"./rotate-ccw-DmmfCbwP.js";import{t as $e}from"./ProviderIcon-BlnoCop3.js";import{t as et}from"./pencil-x4bNLykx.js";import{t as tt}from"./plus-ByEqM_KR.js";import{t as nt}from"./refresh-cw-sAaM2a8A.js";import{t as rt}from"./rotate-cw-Dq3dsGth.js";import{t as it}from"./server-9jJq82Vu.js";import{t as at}from"./wifi-dLfxxYcz.js";import{B as ot,F as st,G as ct,I as lt,O as ut,R as dt,U as ft,V as X,W as pt,_ as mt,a as ht,c as gt,i as _t,k as vt,p as yt,r as bt,s as xt,t as St,v as Ct,x as wt}from"./index-idVLv2oj.js";import{n as Tt,t as Et}from"./useDevice-D_sz9YbZ.js";import{t as Dt}from"./StatusBadge-BSsUNFG6.js";import{t as Ot}from"./useEventInvalidation-BMv3kB-_.js";import{n as kt,r as At,t as jt}from"./SchemaTabBar-DRo5sGP1.js";import{t as Mt}from"./FormBuilder-B7tUioUm.js";var Nt=X(`circle-help`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),Pt=X(`layers`,[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]]),Ft=X(`link-2-off`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7`,key:`10o201`}],[`path`,{d:`M15 7h2a5 5 0 0 1 4 8`,key:`1d3206`}],[`line`,{x1:`8`,x2:`12`,y1:`12`,y2:`12`,key:`rvw6j4`}],[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}]]),It=X(`link-2`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]),Lt=X(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]),Rt=X(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),zt=X(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),Bt=X(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]);W();function Vt({parentDeviceId:e}){let{t}=St(),n=ft(),r=J(),{data:i,isLoading:a,isError:o}=Tt(e),{data:s}=L({deviceId:e},{enabled:Number.isFinite(e)});if(a)return K(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:K(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(o)return K(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:K(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let c=i??[];if(c.length===0)return null;let l=re(s?.stableId??``,c,s?.childLayout),u=l.ungrouped,d=e=>n(`/devices/${String(e)}`),p=s?.name??``,m=e=>{let t=`${p} `;return p.length>0&&e.startsWith(t)?e.slice(t.length):e},h=(e,t)=>K(f,{trpc:r.trpcClient,device:{...t,name:m(t.name)},variant:`minimal`,onNavigate:d},e),g=u.some(e=>!!e.role),_=u.some(e=>!e.role),v=g&&!_?t(`device.accessories`,{defaultValue:`Accessories`}):!g&&_?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),y=u.length>0?H(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[K(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:v}),K(`div`,{className:`space-y-1`,children:u.map(e=>h(e.id,e))})]}):null,b=l.disabledSection===void 0?null:K(M,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:l.disabledSection.children.length,defaultOpen:!1,children:K(`div`,{className:`opacity-60 space-y-1`,children:l.disabledSection.children.map(e=>h(e.id,e))})},l.disabledSection.title);return l.sections.length===0?b===null?y:H(`div`,{className:`space-y-2`,children:[y,b]}):H(`div`,{className:`space-y-2`,children:[l.sections.map(e=>K(M,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>h(e.id,e))},e.title)),y,b]})}function Ht({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){return H(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[K($e,{type:n,size:`lg`}),H(`div`,{children:[K(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),K(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),H(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[K(Dt,{status:r?`online`:`offline`}),i.length>0&&K(Xe,{capabilities:i})]}),K(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:`No live view for this device type. Use the Config tab or the shortcut row to interact.`})]})}function Ut({deviceId:e}){let t=G(),n=_({deviceId:e},{refetchInterval:1e4,retry:!1}),r=N({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=U(()=>Wt(n.data??[]),[n.data]);return H(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[H(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[K(Gt,{label:`Discovered`,value:i.total,icon:K(mt,{className:`h-3.5 w-3.5`})}),K(Gt,{label:`Adopted`,value:i.adopted,accent:`success`}),K(Gt,{label:`Available`,value:i.available,accent:i.available>0?`primary`:void 0}),H(`button`,{type:`button`,onClick:()=>{r.mutateAsync({deviceId:e}).catch(()=>{})},disabled:r.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[r.isPending?K(wt,{className:`h-3.5 w-3.5 animate-spin`}):K(nt,{className:`h-3.5 w-3.5`}),K(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),H(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[K(Kt,{icon:K(at,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),K(Kt,{icon:K(Ct,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),K(Kt,{icon:K(ht,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?K(Kt,{icon:K(Nt,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function Wt(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 Gt({label:e,value:t,icon:n,accent:r}){return H(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[H(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,K(`span`,{className:`truncate`,children:e})]}),K(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function Kt({icon:e,label:t}){return H(`span`,{className:`inline-flex items-center gap-1`,children:[e,K(`span`,{children:t})]})}function qt({deviceId:e,features:t}){return K(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:K(S,{trpc:J().trpcClient,deviceId:e,features:t})})}function Jt({deviceId:e,features:t}){return K(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:K(m,{trpc:J().trpcClient,deviceId:e,features:t})})}function Z({deviceId:e,deviceType:t,features:n}){let r=J(),i=h(t)?.HeroCard??m,a=Ge(Ve(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?K(`div`,{className:`flex justify-center`,children:K(Re,{lastChangedAt:s})}):null,K(i,{trpc:r.trpcClient,deviceId:e,features:n})]})}function Yt({deviceId:e}){let t=J(),{data:n,isLoading:r}=Et(e),{data:i,isLoading:a}=Tt(e),o=r||a,s=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),c=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,l=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return o?K(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):K(`div`,{className:`flex h-full w-full flex-col`,children:K(O,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}var Xt={[Y.Switch]:Z,[Y.Siren]:Z,[Y.Light]:Z,[Y.Sensor]:Z,[Y.Button]:Z,[Y.Hub]:Ut,[Y.Cover]:qt,[Y.Valve]:Z,[Y.Humidifier]:Z,[Y.WaterHeater]:Z,[Y.Container]:Yt,[Y.Lock]:Z,[Y.Fan]:Z,[Y.Thermostat]:Z,[Y.Climate]:Z,[Y.MediaPlayer]:Z,[Y.Control]:Z,[Y.AlarmPanel]:Jt,[Y.EventEmitter]:Jt,[Y.Notifier]:Jt,[Y.Script]:Jt,[Y.Automation]:Jt,[Y.Presence]:Z,[Y.Update]:Z,[Y.Vacuum]:Z,[Y.LawnMower]:Z,[Y.Weather]:Z,[Y.Image]:Z};function Zt(e){return K(Xt[e.deviceType]??Ht,{...e})}function Qt(e){return oe(J().trpcClient,e)}W();function $t(e){let[n,r]=V(`idle`),[i,a]=V(null),o=z(null),s=z(null),c=z(null),l=z(!0),u=t(),d=D(),f=P(),p=B(()=>{if(o.current){try{o.current.close()}catch{}o.current=null}if(s.current){for(let e of s.current.getTracks())try{e.stop()}catch{}s.current=null}c.current=null},[]),m=B(async()=>{if(n===`idle`)return;r(`stopping`);let t=c.current;if(t&&e!==null)try{await Promise.race([f.mutateAsync({deviceId:e,sessionId:t}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}p(),l.current&&(r(`idle`),a(null))},[n,e,f,p]),h=B(async()=>{if(e===null||n!==`idle`&&n!==`error`)return;a(null);let t=null,i=null,p=null;try{r(`requesting-mic`),t=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),s.current=t,r(`starting`);let n=await u.mutateAsync({deviceId:e});p=n.sessionId,c.current=p,r(`connecting`),i=new RTCPeerConnection,o.current=i,i.oniceconnectionstatechange=()=>{if(!l.current)return;let e=i.iceConnectionState;e===`connected`||e===`completed`?r(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&l.current&&(a(e===`failed`?`WebRTC connection failed`:null),m())};for(let e of t.getAudioTracks())i.addTrack(e,t);await i.setRemoteDescription({type:`offer`,sdp:n.sdpOffer});let f=await i.createAnswer();await i.setLocalDescription(f);let h=i.localDescription?.sdp??f.sdp??``;await d.mutateAsync({deviceId:e,sessionId:p,sdpAnswer:h})}catch(n){let u=n instanceof Error?n.message:String(n);if(console.warn(`[intercom] start failed`,n),i)try{i.close()}catch{}if(t)for(let e of t.getTracks())try{e.stop()}catch{}if(o.current=null,s.current=null,p!==null)try{await f.mutateAsync({deviceId:e,sessionId:p})}catch{}c.current=null,l.current&&(a(u),r(`error`))}},[e,n,u,d,f,m]);return q(()=>(l.current=!0,()=>{l.current=!1;let t=c.current;if(t!==null&&e!==null&&f.mutate({deviceId:e,sessionId:t}),o.current){try{o.current.close()}catch{}o.current=null}if(s.current){for(let e of s.current.getTracks())try{e.stop()}catch{}s.current=null}c.current=null}),[e]),{state:n,error:i,start:h,stop:m,isTalking:n===`talking`}}W();var en=0;function Q(){return++en}function tn(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function nn(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 rn(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 an(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 on({scope:e,greeting:t,className:n}){let r=J(),[i,a]=V(()=>{let n=[];return t&&n.push({id:Q(),kind:`info`,text:t}),n.push({id:Q(),kind:`info`,text:`scope: ${tn(e)} — type help or context for available commands`}),n}),[o,s]=V(``),[c,l]=V([]),[u,d]=V(-1),f=z(null),p=z(null);q(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=B(()=>{f.current?.focus()},[]),h=Be({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: ${tn(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...nn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...an(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...rn(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: ${tn(e)}`}]))}let v={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return H(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??``}`,onClick:m,children:[H(`div`,{ref:p,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[i.map(e=>K(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&K(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),H(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[K(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),K(`input`,{ref:f,value:o,onChange:e=>s(e.target.value),onKeyDown:_,disabled:h.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function sn({deviceId:e,intercomAvailable:t=!1}){let n=J(),r=typeof window<`u`?window.location.origin:``,a=Number.isFinite(e),o=Qt(a?e:null),{streams:s,pipelineMetrics:c,createSession:l,sendAnswer:u,handleOffer:d,getIceServers:f,addIceCandidate:p,getIceCandidates:m,closeSession:h,getSessionState:g}=I(n.trpcClient,a?e:null),_=v(n.trpcClient,a?e:null),y=$t(a&&t?e:null),b=y.state===`requesting-mic`||y.state===`starting`||y.state===`connecting`||y.state===`stopping`,x=y.isTalking||b,S=()=>{y.state===`idle`||y.state===`error`?y.start():y.state!==`stopping`&&y.stop()},C=Ue(),w=i(),T=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,E=C.length>0?K(ze,{children:C.map(e=>K(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return K(Le,{serverUrl:r,createSession:l,sendAnswer:u,handleOffer:d,getIceServers:f,addIceCandidate:p,getIceCandidates:m,closeSession:h,getSessionState:g,...w.request?{playbackUrl:w.request.url,playbackAuthToken:T,...w.request.label?{playbackLabel:w.request.label}:{},onExitPlayback:()=>w.clear()}:{},streams:s,pipelineMetrics:c,phase:o.phase,detections:o,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:_.src,..._.src?{posterUrl:_.src}:{},snapshotLoading:_.loading,onRefreshSnapshot:_.refresh,intercomAvailable:t,intercomShown:x,onIntercomToggle:S,extraOverlay:E,chromeless:!0,className:`h-full`})}function cn({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full`,children:K(de,{...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 ln({deviceId:e}){if(!Number.isFinite(e))return H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
2
- `);return K(on,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function un({deviceId:e}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:K(be,{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 dn({deviceId:e}){return Number.isFinite(e)?K(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:K(ue,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):H(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function fn({deviceId:e}){let t=G(),n=Number.isFinite(e),{data:r}=L({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;Ot([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:a,isLoading:s,isError:c,error:l}=Me({deviceId:e},{enabled:n}),{data:u}=ae({deviceType:i},{enabled:!!i}),d=o({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(s)return K(`div`,{className:`p-4`,children:K(`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 a?.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:[K(Ze,{className:`h-8 w-8 opacity-40`}),K(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),K(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let 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:[K(`span`,{className:`font-medium text-foreground`,children:h}),` of `,m.length,` capabilit`,m.length===1?`y`:`ies`,` bound — rows marked `,K(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),K(Ce,{columns:[{key:`capability`,header:`Capability`,render:e=>K(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>K(pn,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>K(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||K(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?K(mn,{nodeId:e.providerNodeId}):K(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>K(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||K(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return K(hn,{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 pn({kind:e}){return e===`native`?H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[K(it,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[K(Pt,{className:`h-3 w-3`}),`wrapped`]}):H(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[K(Rt,{className:`h-3 w-3`}),`unbound`]})}function mn({nodeId:e}){return K(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function hn({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?K(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):K(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let i=e===t;return H(`button`,{disabled:n,onClick:()=>r(e),title:i?`Click to deactivate (revert to native)`:`Activate wrapper ${e}`,className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${i?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[K(i?st:Qe,{className:`h-3 w-3`}),e]},e)})})}W();function gn({schema:e,values:t,pendingKeys:n,onChange:r,onAction:i,onSave:a,onDiscard:o,disabled:s,activeSubTab:c,onSubTabChange:l,flattenTabs:u=!1}){let d=e.tabs??[],f=U(()=>{let t=new Map;for(let n of e.sections){let e=n.tab??`general`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t},[e.sections]),p=new Set(d.map(e=>e.id)),m=[...d,...[...f.keys()].filter(e=>!p.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],h=m[0]?.id??`general`,[g,_]=V(h),v=l!==void 0,y=new Set(m.map(e=>e.id)),b=v?c&&y.has(c)?c:h:y.has(g)?g:h,x=e=>{v?l(e):_(e)},S=f.get(b)??[],C={sections:S.length<=1?S.length===1?[{...S[0],title:``}]:S:S.every(e=>!e.title)?[{...S[0],title:``,fields:S.flatMap(e=>e.fields)}]:S},w=K(kt,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:s});if(u||m.length<=1)return H(`div`,{className:`flex flex-col gap-3`,children:[K(Mt,{schema:e,values:t,onChange:r,onAction:i,disabled:s}),w]});let T=new Map,E=new Map;for(let[e,t]of f){T.set(e,t.length);let r=new Set,i=e=>{for(let t of e)if(`key`in t&&typeof t.key==`string`&&r.add(t.key),t.type===`group`)i(t.fields);else if(t.type===`sub-tabs`)for(let e of t.tabs)i(e.fields)};for(let e of t)i(e.fields);let a=n.filter(e=>r.has(e)).length;a>0&&E.set(e,a)}return H(`div`,{className:`flex flex-col gap-3`,children:[K(jt,{tabs:m.map(e=>({id:e.id,label:e.label})),activeId:b,onChange:x,countByTab:T,pendingByTab:E}),K(Mt,{schema:C,values:t,onChange:r,onAction:i,disabled:s}),w]})}var _n=`device-export`,vn=`export`,yn=`Export`;function bn(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(bn):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(bn)):e.writerCapName===_n}function xn(e){return e.fields.some(bn)}W();function Sn(e,t){return t&&t===`admin`?e:!0}function Cn(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?xn(e)&&xn(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function wn(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 Tn(e){return e.key}function En(e){if(!wn(e))return e.value}function Dn(e){return wn(e)?null:e}function On(e,t){for(let n of e)if(t(n),n.type===`group`)On(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)On(e.fields,t)}function kn(e){if(!e)return{};let t={};for(let n of e.sections)On(n.fields,e=>{let n=Tn(e);n!==null&&(t[n]=En(e))});return t}function An(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(On(r.fields,e=>{if(n!==null||Tn(e)!==t)return;let r=Dn(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function jn(e){return{...e,fields:e.fields.map(Mn)}}function Mn(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function Nn(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=Dn(e);return n?Sn(t,n.minRole)?e:Mn(e):e})}))}}function Pn({deviceId:e,sectionFilter:t,activeSubTab:n,onSubTabChange:r,flattenSubTabs:i}){let a=G(),{user:o}=bt(),s=o?.isAdmin===!0,c=z(!1),{data:l,isLoading:u}=xe({deviceId:e},{refetchInterval:()=>c.current?!1:2500,enabled:Number.isFinite(e)}),{data:d}=L({deviceId:e},{enabled:Number.isFinite(e)}),f=l?.settings??null,p=l?.live??null,m=U(()=>{if(!f&&!p)return null;let e=f?.sections??[],n=(p?.sections??[]).map(jn),r=[...e,...n],i=t?r.filter(t):r.filter(e=>e.location!==`top-tab`&&!xn(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??[],...(p?.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,p,t]),h=U(()=>Cn(m),[m]),g=U(()=>Nn(h,s),[h,s]),_=U(()=>kn(g),[g]),v=Ne(),y=ie(),b=T(),x=k(),S=ge({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),C={isPending:S.isPending,mutate:t=>{S.mutate({deviceId:e,changes:[...t]})}},w=At({schema:g,serverValues:_,onImmediateSave:B(e=>{let t=Object.entries(e).map(([e,t])=>{let n=An(g,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&C.mutate(t)},[g,C]),onDeferredSave:B(e=>{let t=Object.entries(e).map(([e,t])=>{let n=An(g,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&C.mutate(t)},[g,C])}),{values:E,pendingKeys:ee,handleChange:D,handleSave:O,handleDiscard:te}=w;if(c.current=w.editingPaused,u)return H(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[K(wt,{className:`h-4 w-4 animate-spin mr-2`}),K(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!g||g.sections.length===0)return K(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:`No aggregate contributions for this device.`});async function A(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=Ke(e,r);await v.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 b.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=Ke(e,t),i=await y.mutateAsync({brokerId:r});return a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),i}if(t===`device-custom-action`){let t=await x.mutateAsync({deviceId:e,action:n,input:r});return a.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),t}throw Error(`[device-aggregate] unknown action "${t}"`)}return K(gn,{schema:g,values:E,pendingKeys:ee,onChange:D,onAction:A,onSave:O,onDiscard:te,disabled:C.isPending,activeSubTab:n,onSubTabChange:r,flattenTabs:i})}function Fn({deviceId:e,activeSubTab:t,onSubTabChange:n}){return K(`div`,{className:`flex flex-col gap-3`,children:K(Pn,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}W();function In(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 Ln(e,t,n){let r=e?.stepOverridesByAgent?.[t]?.[n];if(r)return r.enabled===!1?`off`:(r.enabled,`on`);let i=e?.stepToggles?.[n];return i===!1?`off`:i===!0?`on`:`inherit`}function Rn({agents:e,currentAgent:t,onPick:n}){let[r,i]=V(!1);return H(`div`,{className:`relative`,children:[K(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>i(e=>!e),children:`Mirror from ▾`}),r&&K(`div`,{className:`absolute top-full left-0 mt-1 min-w-[140px] bg-surface border border-border rounded shadow-lg z-10`,children:e.filter(e=>e!==t).map(e=>K(`button`,{type:`button`,className:`w-full text-left px-3 py-1.5 text-xs hover:bg-muted`,onClick:()=>{i(!1),n(e)},children:e},e))})]})}function zn({deviceId:t,refreshToken:n}){let r=G(),[i,o]=V(null),[s,c]=V(null),[l,u]=V(null),[d,f]=V(null),p=j({deviceId:t}),m=g(),h=b({deviceId:t}),_=C(),v=U(()=>h.data?.agentNodeId||_.data?.find(e=>e.online)?.nodeId||`hub`,[h.data?.agentNodeId,_.data]),y=s??v,x=E({nodeId:y??``},{enabled:!!y}),S=we({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),u(null)}}),w=U(()=>x.data?le(x.data):[],[x.data]),T=U(()=>{let e=p.data??null,t={};for(let n of m.data??[])for(let r of Object.keys(n.settings.addonDefaults)){let i=t[r]??[];i.push({agentNodeId:n.nodeId,state:Ln(e,n.nodeId,r)}),t[r]=i}return t},[p.data,m.data]),D=i?In(x.data??null,i):null,O=y?m.data?.find(e=>e.nodeId===y)??null:null,te=i&&O?O.settings.addonDefaults[i]??null:null,k=i&&y?p.data?.stepOverridesByAgent?.[y]?.[i]??null:null,A=x.data?.selectedEngine.format??`coreml`,ne=e=>{c(e),u(null),f(null)};return m.isLoading||x.isLoading?K(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`}):x.data?K(`div`,{className:`@container h-full`,style:{containerType:`inline-size`},children:H(`div`,{className:`flex flex-col @[720px]:flex-row h-full`,children:[K(`aside`,{className:`w-full @[720px]:w-[300px] @[720px]:flex-shrink-0 border-b @[720px]:border-b-0 @[720px]:border-r border-border overflow-y-auto max-h-[40vh] @[720px]:max-h-none`,children:K(e,{tree:w,selectedAddonId:i,onSelect:e=>{o(e),u(null),f(null)},agentDots:T})}),K(`section`,{className:`flex-1 min-w-0 p-4 overflow-y-auto`,children:!i||!D?K(`div`,{className:`text-sm text-foreground-subtle`,children:`Select a step on the left to configure it for this camera.`}):H(`div`,{className:`space-y-4`,children:[H(`div`,{children:[K(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle`,children:`Selected step`}),K(`div`,{className:`text-base font-semibold`,children:D.name})]}),H(`div`,{className:`flex items-end gap-3 flex-wrap`,children:[H(`div`,{children:[K(`div`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle mb-1`,children:`Agent`}),K(`div`,{className:`flex rounded border border-border overflow-hidden`,children:(m.data??[]).map(e=>K(`button`,{type:`button`,onClick:()=>ne(e.nodeId),className:`px-3 py-1 text-xs ${y===e.nodeId?`bg-primary text-primary-foreground`:`bg-surface hover:bg-muted`}`,children:e.nodeId},e.nodeId))})]}),K(Rn,{agents:(m.data??[]).map(e=>e.nodeId),currentAgent:y,onPick:e=>{if(!y||!i||!x.data||!m.data)return;let t=m.data.find(t=>t.nodeId===e),n=m.data.find(e=>e.nodeId===y);if(!t||!n)return;let[r]=a({source:{nodeId:t.nodeId,engine:{format:A},defaults:t.settings.addonDefaults},target:{nodeId:n.nodeId,engine:{format:A},defaults:n.settings.addonDefaults},catalog:x.data,addonIds:[i]});if(!r){f(`no mirror result`);return}if(r.outcome===`skip`){f(`skipped: ${r.reason??`no candidate`}`);return}u(r.patch),f(`${r.outcome} from ${e}`)}}),d&&K(`div`,{className:`text-[10px] text-foreground-subtle`,children:d})]}),te&&K(ee,{mode:`device`,addon:D,agentDefault:te,agentNodeId:y??``,currentPatch:l??k,engineFormat:A,onChangePatch:u}),H(`div`,{className:`flex items-center justify-between gap-2 pt-4 border-t border-border`,children:[K(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle`,disabled:!k||S.isPending,onClick:()=>{!y||!i||S.mutate({deviceId:t,agentNodeId:y,addonId:i,patch:null})},children:`Clear override`}),H(`div`,{className:`flex items-center gap-2`,children:[K(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:()=>u(null),children:`Reset draft`}),K(`button`,{type:`button`,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,disabled:!y||!i||S.isPending,onClick:()=>{!y||!i||S.mutate({deviceId:t,agentNodeId:y,addonId:i,patch:l})},children:S.isPending?`Saving…`:`Save`})]})]})]})})]})}):K(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`})}function $({label:e,value:t}){return H(`div`,{className:`${He} flex items-start gap-2 sm:gap-3`,children:[K(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),K(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}W();function Bn({deviceId:e,initialName:t}){let n=G(),[r,i]=V(!1),[a,o]=V(t),[s,c]=V(!1),l=z(null);q(()=>{r||o(t)},[t,r]),q(()=>{r&&l.current?.focus()},[r]);let u=ne({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?K($,{label:`Name`,value:H(`div`,{className:`flex items-center gap-1`,children:[K(`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`}),K(`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:K(st,{className:`h-3 w-3`})}),K(`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:K(_t,{className:`h-3 w-3`})})]})}):K($,{label:`Name`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[K(`span`,{className:`truncate`,children:t}),K(`button`,{type:`button`,onClick:()=>i(!0),className:`opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-surface-hover`,"aria-label":`Edit name`,children:K(et,{className:`h-3 w-3 text-foreground-subtle`})})]})})}W();function Vn({deviceId:e,initialLocation:t}){let n=G(),[r,i]=V(!1),[a,o]=V(t??``),[s,c]=V(!1),l=z(null),{data:u}=Pe(void 0,{enabled:r}),d=u??[];q(()=>{r||o(t??``)},[t,r]),q(()=>{r&&l.current?.focus()},[r]);let f=Fe({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?K($,{label:`Location`,value:H(`div`,{className:`relative`,children:[H(`div`,{className:`flex items-center gap-1`,children:[K(`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`}),K(`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:K(st,{className:`h-3 w-3`})}),K(`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:K(_t,{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:[K(Lt,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),K(`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:[K(`span`,{className:`text-foreground-subtle`,children:`Create`}),H(`span`,{className:`font-medium truncate`,children:[`"`,a.trim(),`"`]})]})]})]})}):K($,{label:`Location`,value:H(`div`,{className:`flex items-center gap-2 group`,children:[t?K(`span`,{className:`truncate`,children:t}):K(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),K(`button`,{type:`button`,onClick:()=>i(!0),className:`opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded hover:bg-surface-hover`,"aria-label":`Edit location`,children:K(et,{className:`h-3 w-3 text-foreground-subtle`})})]})})}W();function Hn({deviceId:e}){let t=G(),{data:n}=Et(e),{data:r}=Tt(e),[i,a]=V(null),o=u({onSuccess:()=>{a(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{a(`Could not change primary child: ${e.message}`)}});if(n==null||String(n.type??``)!==Y.Container)return null;let s=(r??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(s.length<=1)return null;let c=te(s,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return H(ze,{children:[K($,{label:`Primary child`,value:K(x,{childrenList:s,selectedId:c===null?s[0].id:c.id,onSetPrimary:t=>o.mutate({deviceId:e,primaryChildEntityId:t}),disabled:o.isPending})}),i!==null&&K(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:i})]})}W();var Un=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function Wn(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function Gn(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function Kn(){let e=he(),t=w(),{data:n}=L({deviceId:e??0},{enabled:e!==null}),{data:r}=Me({deviceId:e??0},{enabled:e!==null}),i=n??t??null,[a,o]=V(`identity`);if(e===null||!i)return null;let s=String(i.stableId??``),c=String(i.name??``),l=String(i.type??``),u=String(i.addonId??``),d=i.features??[],f=new Set([`device-status`,`feature-probe`,`device-ops`]),p=(r?.entries??[]).filter(e=>e.kind===`native`&&!f.has(e.capName)).map(e=>e.capName),m=d.length>0?d:p,h=i.location??null,g=i.metadata??null,_=g!==null&&Object.keys(g).length>0;return H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[H(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[K(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),_&&H(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[K(qn,{active:a===`identity`,onClick:()=>o(`identity`),label:`Identity`}),K(qn,{active:a===`hardware`,onClick:()=>o(`hardware`),label:`Hardware`})]})]}),(!_||a===`identity`)&&H(`div`,{className:`divide-y divide-border`,children:[K($,{label:`ID`,value:H(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,H(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,s,`)`]})]})}),K(Bn,{deviceId:e,initialName:c}),K(Vn,{deviceId:e,initialLocation:h}),K(Hn,{deviceId:e}),K($,{label:`Type`,value:l}),K($,{label:`Provider`,value:K($e,{type:u,size:`sm`,showLabel:!0})}),K($,{label:`Capabilities`,value:m.length>0?K(Xe,{capabilities:m,showLabels:!0}):K(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),_&&a===`hardware`&&K(Jn,{metadata:g})]})}function qn({active:e,onClick:t,label:n}){return K(`button`,{type:`button`,onClick:t,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${e?`bg-surface text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`}`,children:n})}function Jn({metadata:e}){let t=Un.filter(t=>t in e),n=Object.keys(e).filter(e=>!Un.includes(e)).toSorted(),r=[...t,...n];return H(`div`,{children:[K(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border bg-surface-subtle/40`,children:`Auto-populated by the driver on every connect. Read-only.`}),K(`div`,{className:`divide-y divide-border`,children:r.map(t=>K($,{label:Wn(t),value:K(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:Gn(e[t])})},t))})]})}W();function Yn({deviceId:e}){let[t,n]=V(null),r=Te({onSuccess:e=>{n(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>n(`Re-sync failed: ${e.message}`)});return H(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[H(`div`,{className:`flex items-center justify-between gap-3`,children:[H(`div`,{children:[K(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),K(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),H(`button`,{type:`button`,disabled:r.isPending,onClick:()=>{n(null),r.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[K(nt,{className:`h-3 w-3 ${r.isPending?`animate-spin`:``}`}),r.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&K(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}function Xn(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function Zn({device:e}){let t=ft(),n=typeof e.id==`number`?e.id:null,r=String(e.type??``),i=r===Y.Camera,a=r===Y.Hub,o=e.features??[],s=o.includes(Ye.Resyncable),{data:c}=fe({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),l=c?.streams??{},u=Object.entries(l),d=o.includes(Ye.DoorbellButton),f=Ae(d?{deviceId:n??void 0,historyLimit:10}:void 0),p=f.latest?Date.now()-f.latest.timestamp<3e4:!1;return H(`div`,{className:`space-y-5`,children:[a&&n!==null&&K(Oe,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),s&&n!==null&&K(Yn,{deviceId:n}),i&&n!==null&&K(A,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),d&&K(R,{history:f.history,latestIsFresh:p}),i&&n!==null&&K(A,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),i&&u.length>0&&H(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[K(`div`,{className:`border-b border-border px-4 py-2`,children:K(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),K(`div`,{className:`divide-y divide-border`,children:u.map(([e,t])=>H(`div`,{className:`px-4 py-2.5`,children:[H(`div`,{className:`flex items-center gap-2 mb-2`,children:[K(at,{className:`h-3 w-3 text-foreground-subtle`}),K(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),H(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[K(Qn,{label:`Nominal`,value:Xn(t.nominalBitrateKbps??0)}),K(Qn,{label:`Observed`,value:Xn(t.observedBitrateKbps??0)}),K(Qn,{label:`Peak`,value:Xn(t.peakBitrateKbps??0)}),K(Qn,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),K(Kn,{})]})}function Qn({label:e,value:t,warning:n}){return H(`div`,{children:[K(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),K(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}W();function $n(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function er(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=$n(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 nr(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 rr(e){return e==null?`identity`:e.kind}function ir({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=V(()=>rr(e)),[o,s]=V(()=>tr(e,n)),[c,l]=V(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=V(()=>nr(e));q(()=>{if(i===`enum-map`&&n?.kind===`enum`&&n.enumValues){let e=n.enumValues;s(t=>e.map(e=>({key:e,value:t.find(t=>t.key===e)?.value??``})))}},[n,i]),q(()=>{if(i===`identity`){t(void 0);return}if(i===`enum-map`){let e=er(o,r),n=c===``?void 0:$n(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(nr(void 0))},p=(e,t,n)=>{s(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r))},m=()=>s(e=>[...e,{key:``,value:``}]),h=e=>s(t=>t.filter((t,n)=>n!==e));return H(`div`,{className:`flex flex-col gap-3`,children:[H(`div`,{children:[K(`p`,{className:`text-[11px] font-medium text-foreground-subtle mb-1.5`,children:`Transform`}),K(`div`,{className:`flex items-center gap-4`,children:[`identity`,`enum-map`,`linear`].map(e=>H(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[K(`input`,{type:`radio`,name:`transform-kind`,value:e,checked:i===e,onChange:()=>f(e),className:`accent-primary`}),e===`identity`?`None`:e]},e))})]}),i===`enum-map`&&H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[K(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Key → Value mapping`}),o.map((e,t)=>H(`div`,{className:`flex items-center gap-1.5`,children:[K(`input`,{"aria-label":`enum key ${t}`,type:`text`,value:e.key,readOnly:n?.kind===`enum`,onChange:e=>p(t,`key`,e.target.value),placeholder:`source value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none read-only:opacity-70`}),K(`span`,{className:`text-foreground-subtle/50 text-xs`,children:`→`}),r===`boolean`?H(`select`,{"aria-label":`enum value ${t}`,value:e.value,onChange:e=>p(t,`value`,e.target.value),className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`,children:[K(`option`,{value:``,children:`—`}),K(`option`,{value:`true`,children:`true`}),K(`option`,{value:`false`,children:`false`})]}):K(`input`,{"aria-label":`enum value ${t}`,type:r===`number`?`number`:`text`,value:e.value,onChange:e=>p(t,`value`,e.target.value),placeholder:`target value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none`}),n?.kind!==`enum`&&K(`button`,{type:`button`,onClick:()=>h(t),className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] border border-border/80 text-foreground-subtle hover:text-danger hover:border-danger/50 transition-colors`,children:`✕`})]},t)),n?.kind!==`enum`&&K(`button`,{type:`button`,onClick:m,className:`self-start text-[10px] text-primary/70 hover:text-primary transition-colors`,children:`+ Add row`}),H(`div`,{className:`flex items-center gap-2 pt-1 border-t border-border/50`,children:[K(`label`,{className:`text-[10px] text-foreground-subtle/70 whitespace-nowrap`,children:`Fallback:`}),K(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`(leave empty for none)`,className:`flex-1 rounded border border-border bg-background px-2 py-0.5 text-xs font-mono text-foreground focus:border-primary outline-none`})]})]}),i===`linear`&&H(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[K(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Linear: value × scale + offset`}),H(`div`,{className:`grid grid-cols-2 gap-2`,children:[H(`label`,{className:`flex flex-col gap-0.5`,children:[K(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Scale`}),K(`input`,{type:`number`,value:u.scale,onChange:e=>d(t=>({...t,scale:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),H(`label`,{className:`flex flex-col gap-0.5`,children:[K(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Offset`}),K(`input`,{type:`number`,value:u.offset,onChange:e=>d(t=>({...t,offset:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]}),H(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[K(`input`,{type:`checkbox`,checked:u.useClamp,onChange:e=>d(t=>({...t,useClamp:e.target.checked})),className:`accent-primary`}),K(`span`,{className:`text-foreground-subtle`,children:`Clamp output`})]}),u.useClamp&&H(`div`,{className:`grid grid-cols-2 gap-2`,children:[H(`label`,{className:`flex flex-col gap-0.5`,children:[K(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Min`}),K(`input`,{type:`number`,value:u.clampMin,onChange:e=>d(t=>({...t,clampMin:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),H(`label`,{className:`flex flex-col gap-0.5`,children:[K(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Max`}),K(`input`,{type:`number`,value:u.clampMax,onChange:e=>d(t=>({...t,clampMax:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]})]})]})}W();function ar(e,t){return`${e.replace(/[^a-z0-9]/gi,`-`)}-${t.replace(/[^a-z0-9]/gi,`-`)}`}function or(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function sr({deviceId:e,parentDeviceId:t,deviceStableId:n,initial:r,onSave:i,onCancel:a}){let{data:o}=F({}),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}=pe({deviceId:e}),d=u?.caps??[],f=r==null?null:or(r.source.sourceKey,c,s),[p,m]=V(r?.target.cap??``),[h,g]=V(r?.target.fieldPath??``),[_,v]=V(f),[y,b]=V(r?.source.cap??``),[x,S]=V(r?.source.fieldPath??``),[C,w]=V(r?.transform);q(()=>{if(r!=null&&_===null&&s.length>0){let e=or(r.source.sourceKey,c,s);e!==null&&v(e)}},[r,_,s,c]);let{data:T}=pe({deviceId:_??0},{enabled:_!=null}),E=T?.caps??[],ee=d.find(e=>e.cap===p)?.fields??[],D=ee.find(e=>e.path===h),O=E.find(e=>e.cap===y)?.fields??[],te=O.find(e=>e.path===x),k=e=>{m(e),g(``)},A=e=>{v(e===``?null:Number(e)),b(``),S(``)},ne=e=>{b(e),S(``)},re=p!==``&&h!==``&&_!=null&&y!==``&&x!==``,j=()=>{if(!re)return;let e=s.find(e=>e.id===_),t=`${c}-`,n=e&&e.stableId.startsWith(t)?e.stableId.slice(t.length):``;i({id:r?.id??ar(p,h),source:{sourceKey:n,cap:y,fieldPath:x},target:{cap:p,fieldPath:h},...C==null?{}:{transform:C}})},M=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`;return H(`div`,{className:`flex flex-col gap-4 p-3`,children:[H(`fieldset`,{className:`flex flex-col gap-3`,children:[K(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Target (this device)`}),H(`div`,{children:[K(`label`,{htmlFor:`link-target-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target cap`}),H(`select`,{id:`link-target-cap`,value:p,onChange:e=>k(e.target.value),className:M,children:[K(`option`,{value:``,children:`— select a cap —`}),d.map(e=>K(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),H(`div`,{children:[K(`label`,{htmlFor:`link-target-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target field`}),H(`select`,{id:`link-target-field`,value:h,disabled:p===``,onChange:e=>g(e.target.value),className:M,children:[K(`option`,{value:``,children:`— select a field —`}),ee.map(e=>H(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]}),H(`fieldset`,{className:`flex flex-col gap-3`,children:[K(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Source (sibling device)`}),H(`div`,{children:[K(`label`,{htmlFor:`link-source-device`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source device`}),H(`select`,{id:`link-source-device`,value:_??``,onChange:e=>A(e.target.value),className:M,children:[K(`option`,{value:``,children:`— select a device —`}),l.map(e=>H(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),H(`div`,{children:[K(`label`,{htmlFor:`link-source-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source cap`}),H(`select`,{id:`link-source-cap`,value:y,disabled:_==null,onChange:e=>ne(e.target.value),className:M,children:[K(`option`,{value:``,children:`— select a cap —`}),E.map(e=>K(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),H(`div`,{children:[K(`label`,{htmlFor:`link-source-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source field`}),H(`select`,{id:`link-source-field`,value:x,disabled:y===``,onChange:e=>S(e.target.value),className:M,children:[K(`option`,{value:``,children:`— select a field —`}),O.map(e=>H(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]}),K(ir,{value:C,onChange:w,sourceField:te,targetKind:D?.kind}),H(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[K(`button`,{type:`button`,onClick:a,className:`px-3 py-1.5 rounded-md text-xs font-medium border border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,children:`Cancel`}),K(`button`,{type:`button`,disabled:!re,onClick:j,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`})]})]})}W();function cr({deviceId:e}){let t=J(),n=G(),{data:i,isLoading:a}=L({deviceId:e},{enabled:Number.isFinite(e),refetchInterval:1e4}),o=r({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),s=i?.deviceLinks??[],c=typeof i?.parentDeviceId==`number`?i.parentDeviceId:null,l=typeof i?.stableId==`string`?i.stableId:``,[u,d]=V(null),f=t=>{o.mutate({deviceId:e,deviceLinks:s.filter(e=>e.id!==t)})};return a?K(`div`,{className:`p-4`,children:K(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})}):u===null?H(`div`,{className:`flex flex-col gap-3 p-1`,children:[H(`div`,{className:`flex items-center justify-between`,children:[K(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Wiring`}),H(`button`,{type:`button`,onClick:()=>d(`new`),title:`Add a cross-device link`,className:`inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[K(tt,{className:`h-3 w-3`}),`Add link`]})]}),s.length===0?H(`div`,{className:`flex flex-col items-center justify-center gap-2 py-8 text-foreground-subtle`,children:[K(Ft,{className:`h-8 w-8 opacity-30`}),K(`p`,{className:`text-xs`,children:`No links yet.`}),K(`p`,{className:`text-[10px] opacity-60`,children:`Cross-device field wirings will appear here once authored.`})]}):K(`div`,{className:`flex flex-col divide-y divide-border rounded-lg border border-border overflow-hidden`,children:s.map(n=>K(lr,{deviceId:e,link:n,trpcClient:t.trpcClient,onDelete:()=>f(n.id),onEdit:()=>d(n),isPending:o.isPending},n.id))})]}):H(`div`,{className:`flex flex-col gap-3 p-1`,children:[K(`div`,{className:`flex items-center justify-between`,children:K(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:u===`new`?`Add link`:`Edit link`})}),K(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:K(sr,{deviceId:e,parentDeviceId:c,deviceStableId:l,initial:u===`new`?null:u,onSave:t=>{let n=s.some(e=>e.id===t.id)?s.map(e=>e.id===t.id?t:e):[...s,t];o.mutate({deviceId:e,deviceLinks:n}),d(null)},onCancel:()=>{d(null)}})})]})}function lr({deviceId:e,link:t,trpcClient:n,onDelete:r,onEdit:i,isPending:a}){let o=Se(n,e,t.target.cap),s=o===void 0?void 0:Je(o,t.target.fieldPath),c=s==null?`—`:String(s);return H(`div`,{className:`flex items-center gap-3 px-3 py-2.5 bg-surface hover:bg-surface-hover transition-colors`,children:[K(It,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle/40`}),H(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[H(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[K(`span`,{className:`font-mono text-[11px] font-medium text-foreground`,children:t.target.cap}),K(`span`,{className:`text-[10px] text-foreground-subtle/60`,children:`.`}),K(`span`,{className:`font-mono text-[11px] text-foreground-subtle`,children:t.target.fieldPath})]}),H(`div`,{className:`flex items-baseline gap-1 flex-wrap text-[10px] text-foreground-subtle/70`,children:[K(`span`,{children:`←`}),K(`span`,{className:`font-mono`,children:t.source.sourceKey}),K(`span`,{className:`opacity-60`,children:`/`}),K(`span`,{className:`font-mono`,children:t.source.cap}),K(`span`,{className:`opacity-60`,children:`.`}),K(`span`,{className:`font-mono`,children:t.source.fieldPath})]})]}),t.transform&&K(ur,{kind:t.transform.kind}),K(`span`,{className:`font-mono text-[11px] tabular-nums min-w-[2.5rem] text-right text-foreground-subtle`,title:`Live resolved value (from this device's runtime-state slice)`,children:c}),K(`button`,{type:`button`,"aria-label":`Edit link`,title:`Edit this link`,disabled:a,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-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:`Edit`}),K(`button`,{type:`button`,"aria-label":`Delete link`,title:`Remove this link`,disabled:a,onClick:r,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 ur({kind:e}){return K(`span`,{className:`inline-flex items-center rounded-md border border-primary/20 bg-primary/5 px-1.5 py-0.5 font-mono text-[10px] text-primary/80 shrink-0`,children:e})}W();var dr=[{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 fr(e){let t=e===Y.Camera;return dr.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var pr=[{id:`logs`,icon:yt,label:`Logs`},{id:`repl`,icon:gt,label:`REPL`},{id:`events`,icon:dt,label:`Events`},{id:`state`,icon:ut,label:`State`}];function mr(){let e=pt(),t=Number(e.deviceId),r=Number.isFinite(t),i=ft(),a=G(),o=p(),l=J(),[u,f]=ct(),m=u.get(`tab`)??`overview`,h=u.get(`sub`),[g,_]=V(`logs`),v=`device-detail.left-col-width-px`,[x,S]=V(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(v),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),C=z(x);C.current=x;function w(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??x??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{S(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=C.current;if(e!==null)try{window.localStorage.setItem(v,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:T,isLoading:E,isError:ee}=L({deviceId:t},{enabled:r,refetchInterval:5e3,retry:1}),{data:D}=xe({deviceId:t},{enabled:r}),O=U(()=>{let e=D?.settings?.sections??[],t=D?.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(xn)&&r.add(vn),[...r].map(e=>e===`export`?{id:e,label:yn,isAddonContrib:!0}:{id:e,label:qe[e]?.label??e,isAddonContrib:!0})},[D]),k=T,A=String(k?.name??e.deviceId??`Device`),ne=k?.online===!0,re=ne?`online`:`offline`,j=String(k?.addonId??`rtsp`),M=k?.features??[],N=k?.type,ie=N===Y.Camera,{data:ae}=Tt(r?t:0),oe=N===Y.Container,le=U(()=>(ae??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[ae]),P=U(()=>oe?te(le,typeof k?.linkDeviceId==`number`?k.linkDeviceId:null,typeof k?.primaryChildEntityId==`string`?k.primaryChildEntityId:null)?.id??null:null,[oe,le,k?.linkDeviceId,k?.primaryChildEntityId]),{data:ue}=xe({deviceId:P??0},{enabled:P!==null}),de=U(()=>{if(P===null)return[];let e=ue?.settings?.sections??[],t=ue?.live?.sections??[],n=new Set;for(let r of[...e,...t])r.location===`top-tab`&&r.tab&&n.add(r.tab);return[...n].map(e=>({id:e,label:qe[e]?.label??e,isAddonContrib:!0,childDeviceId:P}))},[P,ue]),F=typeof k?.parentDeviceId==`number`?k.parentDeviceId:null,{data:fe}=L({deviceId:F??0},{enabled:F!==null}),I=De(),he=k?.disabled!==!0,{data:ge}=pe({deviceId:t},{enabled:r}),be=(ge?.caps.length??0)>0,Se=U(()=>{let e=new Set,t=[];for(let n of[...fr(N),...O,...de])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!be)&&t.push(n));return t},[N,O,de,be]),Ce=U(()=>Se.some(e=>e.id===m)?m:`overview`,[Se,m]),we=B(e=>{f(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[f]),Te=B(e=>{f(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[f]),Oe=(ae??[]).length>0,Ae=U(()=>pr.filter(({featureGate:e})=>!e||M.includes(e)),[M]),{data:R}=y({addonId:j},{enabled:!!j&&j!==`rtsp`}),Me=Ie({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]}),i(R?.id?`/integrations/${R.id}`:`/integrations`)}}),Ne=ye({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Pe=me({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=se(),Le=ce({onSuccess:()=>{a.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Re=M.includes(Ye.Rebootable),W=M.includes(Ye.BatteryOperated),ze=ke(l.trpcClient,W&&r?t:null),[Be,q]=V(!1),He=Ve(l.trpcClient,r?t:null),Ue=async()=>{if(!(Be||!He)){q(!0);try{await He.snapshot?.invalidateCache({});let e=await He.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{q(!1)}}},Ge=Ne.isPending||Pe.isPending,{data:Ke}=b({deviceId:t},{enabled:r,refetchInterval:1e4}),Je=Ke?.agentNodeId??null,Ze=typeof Je==`string`&&Je.length>0&&!Je.startsWith(`addon:`)?Je:void 0,{data:Qe}=ve({deviceId:t,...Ze?{nodeId:Ze}:{}},{enabled:r,refetchInterval:3e3,retry:!1}),{data:et}=s({deviceId:t},{enabled:r,refetchInterval:3e3,retry:!1}),tt=et?.level?.dbfs??null;function it(){if(!r)return null;switch(Ce){case`overview`:return K(Zn,{device:k??{}});case`config`:return K(Fn,{deviceId:t,activeSubTab:h,onSubTabChange:Te});case`pipeline`:return K(zn,{deviceId:t,refreshToken:0});case`bindings`:return K(fn,{deviceId:t});case`wiring`:return K(cr,{deviceId:t});default:{let e=Ce,r=O.some(t=>t.id===e),i=de.find(t=>t.id===e);if(!r&&i===void 0)return null;let a=i?.childDeviceId??t;if(e===`export`)return K(Pn,{deviceId:t,sectionFilter:xn,activeSubTab:h,onSubTabChange:Te});let o=K(Pn,{deviceId:a,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:h,onSubTabChange:Te});return i!==void 0&&a!==t?K(n,{deviceId:a,children:o}):o}}}return r?E?H(`div`,{className:`flex flex-col h-full`,children:[H(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[K(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),K(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),K(`div`,{className:`flex-1 p-6`,children:K(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):ee||!T?H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[K(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),H(`p`,{className:`text-xs`,children:[`No device with ID`,` `,H(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,t]})]}),K(`button`,{onClick:()=>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:[K(`div`,{className:`mb-2`,children:K(je,{items:[{label:`Integrations`,onClick:()=>i(`/integrations`)},{label:R?.name??j,onClick:()=>R?.id&&i(`/integrations/${R.id}`)},{label:A}]})}),H(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[K($e,{type:j,size:`lg`}),H(`div`,{className:`min-w-0 flex-1`,children:[H(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[K(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:A}),K(Dt,{status:re}),W&&K(d,{status:ze,variant:`full`})]}),F!==null&&fe&&H(`button`,{type:`button`,onClick:()=>i(`/devices/${F}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${fe.name}`,children:[K(`span`,{children:`↑`}),K(`span`,{className:`truncate`,children:String(fe.name??`Device #${F}`)})]}),K(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:M.length>0&&K(Xe,{capabilities:M})})]}),Qe&&K(`div`,{className:`hidden lg:flex`,children:K(hr,{metrics:Qe,dbfs:tt})}),H(`div`,{className:`flex items-center gap-1 shrink-0`,children:[H(`button`,{onClick:async()=>{he?await o({title:`Disable "${A}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Pe.mutate({deviceId:t}):Ne.mutate({deviceId:t})},disabled:Ge,title:he?`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 ${he?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[K(zt,{className:`h-3.5 w-3.5`}),K(`span`,{className:`hidden sm:inline`,children:Ge?`Updating…`:he?`Enabled`:`Disabled`})]}),K(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),K(_e,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:lt,disabled:Be,onClick:()=>{Ue()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:rt,hidden:!Re,disabled:Fe.isPending,danger:!0,onClick:async()=>{await o({title:`Reboot "${A}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Fe.mutate({deviceId:t})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${R?.name??j}.`,icon:nt,disabled:Le.isPending,danger:!0,onClick:async()=>{await o({title:`Restart "${R?.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:xt,separatorBefore:!0,disabled:Me.isPending,danger:!0,onClick:async()=>{await o({title:`Delete "${A}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Me.mutate({deviceId:t})}}]})]})]})]}),K(n,{deviceId:t,device:k??void 0,children:K(c,{children:K(We,{children:K(Ee,{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`:`${x===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!I&&x!==null?{width:`${String(x)}px`}:void 0,children:[K(`div`,{className:ie?`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:ie?K(sn,{deviceId:t,intercomAvailable:M.includes(Ye.TwoWayAudio)}):K(Zt,{deviceId:t,deviceName:A,deviceType:N??`unknown`,provider:j,isOnline:ne,features:M})}),H(`div`,{className:I?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[K(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:K(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:Ae.map(({id:e,label:t,icon:n})=>H(`button`,{onClick:()=>_(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${g===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[K(n,{className:`h-3 w-3`}),t]},e))})}),H(`div`,{className:I?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[g===`logs`&&K(cn,{deviceId:t,containerDeviceId:N===`container`?t:void 0}),g===`repl`&&K(ln,{deviceId:t}),g===`events`&&K(un,{deviceId:t}),g===`state`&&K(dn,{deviceId:t})]})]})]}),!I&&K(`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:K(`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:[K(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:K(`div`,{className:`flex flex-wrap items-center gap-0`,children:Se.map(e=>{let t=Ce===e.id;return H(`button`,{onClick:()=>we(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&K(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),H(`div`,{className:I?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[Ce===`overview`&&Oe&&K(Vt,{parentDeviceId:t}),it()]})]})]})})})})})]}):H(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[K(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),H(`p`,{className:`text-xs`,children:[`The URL segment`,` `,K(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:e.deviceId}),` `,`is not a number.`]}),K(`button`,{onClick:()=>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 hr({metrics:e,dbfs:t}){let n=l(e.phase??`idle`);return H(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[H(`div`,{className:`flex items-center gap-1.5`,children:[K(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),K(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),K(`div`,{className:`h-3 w-px bg-border`}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[K(ot,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),K(`span`,{children:`fps`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[K(vt,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),K(`span`,{children:`ms`})]}),H(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[K(Bt,{className:`h-3 w-3`}),K(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),K(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&H(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{mr as DeviceDetailPage};
@@ -1 +0,0 @@
1
- import{C as e,w as t}from"./src-B7BVQkY2.js";import{K as n,S as r,Z as i,x as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CCjPq1YD.js";i();function o(e){return/^[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)+$/.test(e)}function s(e,t){if(e!==void 0)return t&&o(e)?t(e):e}function c({section:i,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,probeResults:f,onAction:p}){let[m,h]=n(i.defaultCollapsed??!1),g=i.style===`accordion`;if(i.fields.reduce((e,n)=>e+ +!!t(n,o,i.fields),0)===0)return null;let _=i.columns??2,v=_===1?`grid-cols-1`:_===3?`grid-cols-1 @[480px]:grid-cols-2 @[880px]:grid-cols-3`:_===4?`grid-cols-1 @[480px]:grid-cols-2 @[1140px]:grid-cols-4`:`grid-cols-1 @[480px]:grid-cols-2`,y=i.fields.length===1&&i.fields[0]?.type===`widget`?i.fields[0]:void 0;return r(`div`,{className:`@container rounded-lg border border-border bg-surface p-3`,style:{containerType:`inline-size`},children:[!(y!==void 0||!i.title&&!i.description)&&r(`div`,{className:[`flex items-center justify-between mb-2`,g?`cursor-pointer`:``].join(` `),onClick:g?()=>h(e=>!e):void 0,children:[r(`div`,{children:[i.title&&a(`h3`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wider`,children:s(i.title,u)}),i.description&&a(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:s(i.description,u)})]}),g&&a(`span`,{className:`text-foreground-subtle text-xs ml-2`,children:m?`▸`:`▾`})]}),!m&&(y===void 0?a(`div`,{className:`grid ${v} gap-x-3 gap-y-2.5`,children:i.fields.map(t=>a(e,{field:t,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,externalProbe:f?.[t.key],allFields:i.fields,onAction:p},t.key))}):a(e,{field:y,values:o,onChange:c,disabled:l,translationFn:u,onTestField:d,externalProbe:f?.[y.key],allFields:i.fields,onAction:p},y.key))]})}function l({schema:e,values:t,onChange:n,disabled:r,translationFn:i,onTestField:o,probeResults:s,onClearProbe:l,onAction:u}){let d=(e,r)=>{n({...t,[e]:r}),l?.(e)};return a(`div`,{className:`space-y-4`,children:e.sections.map((e,n)=>a(c,{section:e,values:t,onChange:d,disabled:r,translationFn:i,onTestField:o,probeResults:s,onAction:u},`${e.id}-${n}`))})}export{l as t};
@@ -1 +0,0 @@
1
- import{Ai as e,Ci as t,Di as n,Ei as r,Fi as i,Hi as a,Mi as o,Ni as s,Oi as c,Pi as l,Si as u,Ti as d,c as f,ji as p,ki as m,na as h,ot as g,s as _,st as v,wi as y,xa as b,xi as x}from"./src-B7BVQkY2.js";import{K as S,S as C,W as w,Z as T,b as E,o 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-CCjPq1YD.js";import{t as k}from"./circle-check-big-MfDWxk9K.js";import{t as A}from"./copy-C4G6c4Ys.js";import{t as j}from"./key-round-BNduVRhj.js";import{t as M}from"./AddonCollectionPage-B4YZsZ2N.js";import{t as ee}from"./plus-ByEqM_KR.js";import{C as N,F as P,V as F,d as I,i as L,l as R,r as z,s as B,w as V,x as H}from"./index-idVLv2oj.js";import{t as U}from"./AdminPage-vtcsGqRq.js";import{t as W}from"./AdminTabs-Cyrx86NX.js";var G=F(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),K=F(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),te=F(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),q=F(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),J=F(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);T();function ne({userId:e,username:t,onClose:n}){let r=D(),i=a(),o=d({userId:e}),s=o.data,c=()=>r.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),l=y({onSuccess:()=>{c(),n()}}),u=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(R,{className:`h-4 w-4 text-primary`}),C(`div`,{children:[O(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),C(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,O(`span`,{className:`font-mono`,children:t})]})]})]}),O(`button`,{onClick:n,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:O(L,{className:`h-4 w-4`})})]}),C(`div`,{className:`p-4 space-y-4`,children:[u===`loading`&&C(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[O(H,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),u===`not_enrolled`&&C(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[O(N,{className:`h-4 w-4 mt-0.5 shrink-0`}),C(`div`,{children:[O(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),O(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),u===`enrolled`&&s&&C(E,{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(b,{onClick:n,variant:`secondary`,children:`Close`}),C(`button`,{onClick:async()=>{await i({title:`Remove 2FA`,message:`Remove two-factor authentication for "${t}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&l.mutate({userId:e})},disabled:l.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:[l.isPending?O(H,{className:`h-3 w-3 animate-spin`}):O(L,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function Y(){let n=D(),{user:r}=z(),[o,s]=S(!1),[c,d]=S(``),[f,p]=S(``),[g,_]=S(!1),[v,y]=S(null),{data:b,isLoading:x,isError:w}=m(),T=a(),E=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),k=u({onSuccess:()=>{E(),s(!1),d(``),p(``),_(!1),y(null)},onError:e=>{y(e instanceof Error?e.message:`Failed to create user`)}}),A=t({onSuccess:E}),j=i({onSuccess:E}),M=e({onSuccess:E}),N=l({onSuccess:()=>{E(),F(null)}}),[P,F]=S(null),[V,W]=S(null),G=b??[];async function K(e){await T({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 q(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 T({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 J(e,t){t!==e.isAdmin&&j.mutate({id:e.id,isAdmin:t})}function Y(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:()=>s(!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`]})}),o&&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:()=>s(!1),className:`text-foreground-subtle hover:text-foreground`,children:O(L,{className:`h-4 w-4`})})]}),C(`div`,{className:`grid grid-cols-3 gap-3`,children:[C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),O(`input`,{type:`text`,value:c,onChange:e=>d(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:f,onChange:e=>p(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:g,onChange:e=>_(e.target.checked),className:`rounded border-border focus:ring-primary`}),O(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),v&&O(`p`,{className:`text-[10px] text-danger`,children:v}),C(`div`,{className:`flex justify-end gap-2`,children:[O(`button`,{onClick:()=>s(!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:c,password:f,isAdmin:g}),disabled:k.isPending||!c||!f,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`})]})]}),x&&O(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),w&&O(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!x&&!w&&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(h,{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=>J(t,e.target.checked),disabled:e(t),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),O(`span`,{className:t.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:t.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Scopes`,render:e=>{if(e.isAdmin)return O(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`unscoped`});let t=e.scopes??[];return C(`button`,{onClick:()=>F(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground`,title:`Edit scope grants`,children:[O(I,{className:`h-3 w-3`}),t.length===0?`no access`:`${t.length} grant${t.length===1?``:`s`}`]})}},{key:`createdAt`,header:`Created`,render:e=>O(`span`,{className:`text-foreground-subtle`,children:Y(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(R,{className:`h-3 w-3`}),`Remove 2FA`]}),C(`button`,{onClick:()=>q(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(te,{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(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:G,rowKey:e=>e.id,minWidthPx:560})})(),V&&O(ne,{userId:V.id,username:V.username,onClose:()=>W(null)}),P&&O(re,{user:P,onClose:()=>F(null),onSubmit:e=>N.mutate({userId:P.id,scopes:e}),submitting:N.isPending})]})}function re(e){let{user:t}=z(),n=t?.isAdmin===!0;return O(ie,{...e,callerScopes:n?null:t?.scopes??[]})}function ie({user:e,onClose:t,onSubmit:n,submitting:r,callerScopes:i}){let[a,o]=S(w(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),s=f(a);return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:C(`div`,{className:`w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl`,children:[C(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-3`,children:[C(`div`,{children:[C(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Edit scopes — `,e.username]}),O(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`Admin users bypass the scope check; this list is ignored.`:`Pick which capabilities this user can call, and which access flavours within each.`})]}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(L,{className:`h-4 w-4`})})]}),C(`div`,{className:`px-4 py-4`,children:[O(_,{value:a,onChange:o,clampToParent:i,emptyHint:C(E,{children:[`No scopes granted.`,` `,O(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until a scope is added.`]})}),s&&O(`p`,{className:`mt-2 text-[10px] text-danger`,children:s})]}),C(`div`,{className:`flex items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),O(`button`,{onClick:()=>n(a),disabled:r||s!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:r?O(H,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}T();var ae=`bg-primary/10 text-primary`,oe=`bg-foreground-subtle/10 text-foreground-subtle`;function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function se(e){return e?e===`*`?`*`:e.join(`, `):``}function ce(){let e=D(),t=a(),{data:n,isLoading:i}=r(),{data:o}=m(),c=w(()=>n??[],[n]),l=w(()=>o??[],[o]),u=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),d=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[f,h]=S(!1),[g,_]=S(null),v=p({onSuccess:u}),y=x({onSuccess:({token:e,record:t})=>{d(),h(!1),_({token:e,label:t.name})}}),b=s({onSuccess:d}),T=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&v.mutate({id:e})},E=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&b.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(I,{className:`h-3.5 w-3.5`}),`New token`]})]}),C(Z,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[l.length===0&&O(ue,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),l.map(e=>O(fe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{E(e,t)},revokePending:b.isPending,revokeId:b.variables?.id},e.id))]}),c.length>0&&O(Z,{title:`Legacy API keys`,subtitle:`${c.length} pre-existing — revoke only`,children:O(de,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:c.map(e=>{let t=!!e.isAdmin,n=v.isPending&&v.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?ae:oe}`,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:se(e.allowedProviders)||`all`}),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 text-right`,children:C(`button`,{onClick:()=>{T(e.id,e.label)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?O(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),i&&O(le,{}),f&&O(pe,{users:l.map(e=>({id:e.id,username:e.username})),onClose:()=>h(!1),onSubmit:e=>y.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:y.isPending}),g&&O(me,{token:g.token,label:g.label,onClose:()=>_(null)})]})}function Z({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 le(){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 ue({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 de({headers:e,rows:t}){return O(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[O(`thead`,{children:O(`tr`,{children:e.map((t,n)=>O(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),O(`tbody`,{children:t})]})})}function fe({userId:e,username:t,onRevoke:n,revokePending:r,revokeId:i}){let{data:a,isLoading:o}=c({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(de,{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:X(e.expiresAt)}),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 text-foreground-subtle border-b border-border`,children:X(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(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function pe({users:e,onClose:t,onSubmit:n,submitting:r}){let{user:i}=z(),a=i?.isAdmin===!0?null:i?.scopes??[],[o,s]=S(e[0]?.id??``),[c,l]=S(``),[u,d]=S([{type:`capability`,target:``,access:[`view`,`create`]}]),[p,m]=S(``),h=f(u),g=o!==``&&c.trim().length>0&&u.length>0&&h===null&&!r;return C(he,{title:`Create scoped token`,onClose:t,children:[C(`div`,{className:`space-y-3`,children:[O(Q,{label:`On behalf of user`,children:O(`select`,{value:o,onChange:e=>s(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>O(`option`,{value:e.id,children:e.username},e.id))})}),O(Q,{label:`Name`,children:O(`input`,{value:c,onChange:e=>l(e.target.value),placeholder:`cloudflare-tunnel-route`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})}),C(Q,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[O(_,{value:u,onChange:d,clampToParent:a}),h&&O(`p`,{className:`mt-1 text-[10px] text-danger`,children:h})]}),O(Q,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:O(`input`,{type:`number`,min:1,value:p,onChange:e=>m(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),C(ge,{children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),C(`button`,{onClick:()=>{let e=parseInt(p,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;n({userId:o,name:c.trim(),scopes:u,expiresAt:t})},disabled:!g,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[r?O(H,{className:`h-3.5 w-3.5 animate-spin`}):O(I,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function me({token:e,label:t,onClose:n}){let[r,i]=S(!1),a=async()=>{try{await navigator.clipboard.writeText(e),i(!0)}catch{}};return C(he,{title:`Token: ${t}`,onClose:n,children:[C(`div`,{className:`space-y-3`,children:[O(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),O(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),C(ge,{children:[C(`button`,{onClick:()=>{a()},className:`inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[r?O(P,{className:`h-3.5 w-3.5 text-primary`}):O(A,{className:`h-3.5 w-3.5`}),r?`Copied`:`Copy`]}),O(`button`,{onClick:n,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function he({title:e,onClose:t,children:n}){return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[C(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(L,{className:`h-4 w-4`})})]}),O(`div`,{className:`p-4`,children:n})]})})}function ge({children:e}){return O(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Q({label:e,hint:t,children:n}){return C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),n,t&&O(`p`,{className:`text-[10px] text-foreground-subtle`,children:t})]})}T();function $(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function _e(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function ve(){return O(`div`,{className:`space-y-2`,children:[1,2].map(e=>O(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function ye({text:e}){return O(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function be({headers:e,rows:t}){return O(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[O(`thead`,{children:O(`tr`,{children:e.map((t,n)=>O(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),O(`tbody`,{children:t})]})})}function xe(){let e=D(),t=a(),{data:r,isLoading:i}=n(),s=w(()=>r??[],[r]),c=o({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),l=async(e,n)=>{await t({title:`Revoke "${n}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&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:[i&&O(ve,{}),!i&&s.length===0&&O(ye,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!i&&s.length>0&&O(be,{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:_e(e)},t))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:$(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 border-b border-border`,children:t?C(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,$(e.revokedAt)]}):O(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!t&&C(`button`,{onClick:()=>{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(H,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}T();var Se=3e4;function Ce(e){let t=new Map;for(let n of e){let e=n?.manifest;e?.id&&t.set(e.id,e.packageDisplayName??e.name??e.id)}return t}function we(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:K,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA can be enrolled per-user from the Users page (added in v0.4).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:V,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:V,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:R,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:R,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:I,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Te(){let e=v({capName:`auth-provider`},{refetchInterval:Se}),t=g(void 0,{refetchInterval:Se}),n=w(()=>Ce(t.data??[]),[t.data]);return O(M,{title:`Authentication`,subtitle:`Identity providers exposed to the admin UI. Multiple providers can run in parallel — operators pick which to enable. Disabling a provider only removes that external login method; local password login is unaffected. Each provider’s settings + live logs are inline below.`,pageIcon:I,itemIcon:I,capability:`auth-provider`,installButtonLabel:`Add provider`,items:w(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,renderExpandedPanel:e=>O(Ee,{addonId:e.addonId})})}function Ee({addonId:e}){let t=we(e),n=t.icon;return C(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[C(`div`,{className:`flex items-start gap-2.5`,children:[O(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),O(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),O(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>O(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&C(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[C(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[O(G,{className:`h-3 w-3`}),`Setup steps`]}),O(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>O(`li`,{children:e},t))})]}),e===`local-auth`&&C(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[O(N,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),C(`span`,{children:[`TOTP / 2FA settings are exposed per-user from the`,` `,O(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page (added in v0.4). Enable for each user via the Actions column → “Enable TOTP”.`]})]})]})}function De(){return O(`div`,{className:`flex flex-col p-4`,children:O(W,{tabs:[{id:`users`,label:`Users`,icon:J,content:O(Y,{})},{id:`api-keys`,label:`Tokens`,icon:j,content:O(ce,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:q,content:O(xe,{})},{id:`authentication`,label:`Authentication`,icon:I,content:O(Te,{})}]})})}export{De as IdentityPage};
@@ -1 +0,0 @@
1
- import{$t as e,B as t,Bi as n,Gn as r,On as i,Qt as a,Un as o,V as s,Wn as c,X as l,Yn as u,Zn as d,_a as f,cn as p,d as m,dt as h,en as g,fn as _,g as ee,gn as v,in as y,ln as te,qn as b,ra as x,rn as S,tn as C,x as w,xn as T,yn as E,zi as ne}from"./src-B7BVQkY2.js";import{G as re,I as D,K as O,S as k,W as A,Z as j,b as M,o 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-CCjPq1YD.js";import{p as F}from"./player-overlays-BK-_BrgW.js";import{b as I}from"./src-D7qnpDWK.js";import{t as L}from"./ProviderIcon-BlnoCop3.js";import{t as R}from"./plus-ByEqM_KR.js";import{n as z,r as B,t as ae}from"./ScanNetworkModal-CxjeMDho.js";import{t as oe}from"./refresh-cw-sAaM2a8A.js";import{t as V}from"./rotate-cw-Dq3dsGth.js";import{t as se}from"./wifi-dLfxxYcz.js";import{E as H,F as U,G as ce,M as W,P as G,T as le,U as ue,V as de,W as fe,f as pe,i as me,o as K,p as he,s as ge,t as _e,x as q,z as ve}from"./index-idVLv2oj.js";import{t as J}from"./FormBuilder-B7tUioUm.js";var ye=de(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);j();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]=O(`idle`),[a,o]=O({}),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}}j();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:t,addonId:n,onClose:r}){let{t:a}=_e(),o=N(),[s,c]=O({}),[l,u]=O(!1),[d,f]=O(null),[p,m]=O(X),h=E({addonId:n},{enabled:e}),g=h.data?.deviceType??null,v=_({addonId:n,type:g??I.Camera},{enabled:e&&h.isSuccess&&g!==null}),y=v.data??null;ie(()=>{e&&(c(y?Y(y.sections.flatMap(e=>e.fields)):{}),m(X()),u(!1),f(null))},[e,t,y]);let te=A(()=>({...s,_probeRequestId:p}),[s,p]),b=S({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`]]})}}),x=i(),C=D(async(e,t)=>{u(!0);let r=await x.mutateAsync({addonId:n,type:g??I.Camera,key:e,value:t,formValues:te});return r.status===`ok`&&r.suggestedValues&&c(e=>{let t=!1,n={...e};for(let[i,a]of Object.entries(r.suggestedValues??{}))Ce(e[i])&&!Ce(a)&&(n[i]=a,t=!0);return t?n:e}),r},[x,n,te,g]),{testAllStatus:w,hasProbeFields:T,probeResults:ne,handleTestAll:re,clearProbeResult:j}=xe(y??{sections:[]},s,C);async function M(e){f(null);try{await b.mutateAsync({addonId:n,type:g??I.Camera,config:s,integrationId:t}),e?c(y?Y(y.sections.flatMap(e=>e.fields)):{}):r()}catch(e){f(e instanceof Error?e.message:String(e))}}if(!e)return null;let F=Se((y?.sections??[]).flatMap(e=>e.fields)).filter(e=>Ce(s[e])),L=F.length===0,R=h.isLoading||g!==null&&v.isLoading,z=h.isError||h.isSuccess&&g===null||v.isError||v.isSuccess&&y===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:r}),k(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[90vh] rounded-xl border border-border bg-background shadow-2xl`,children:[k(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:a(`integrations.addDevice`)}),P(`button`,{onClick:r,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:P(me,{className:`h-4 w-4`})})]}),P(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:R?P(`div`,{className:`flex items-center justify-center py-8`,children:P(q,{className:`h-5 w-5 animate-spin text-primary`})}):z?k(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[P(K,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),k(`div`,{className:`space-y-1`,children:[P(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),k(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,P(`span`,{className:`font-mono`,children:n}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):P(J,{schema:y,values:s,onChange:c,onTestField:C,probeResults:ne,onClearProbe:j})}),!z&&!R&&k(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[k(`button`,{type:`button`,onClick:()=>u(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[k(`span`,{className:`flex items-center gap-2`,children:[P(he,{className:`h-3.5 w-3.5`}),`Test logs`,P(`span`,{className:`font-mono text-[9px] opacity-60`,children:p.slice(0,14)})]}),P(G,{className:`h-3.5 w-3.5 transition-transform ${l?`rotate-180`:``}`})]}),l&&P(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:P(ee,{addonId:n,requestId:p,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!z&&!R&&(d||F.length>0)&&P(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:k(`div`,{className:`flex items-start gap-2`,children:[P(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),P(`p`,{className:`text-[11px] text-destructive`,children:d||`Required: ${F.join(`, `)}`})]})}),k(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[k(`div`,{className:`flex items-center gap-2`,children:[P(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.cancel`)}),!z&&T&&k(`button`,{type:`button`,onClick:re,disabled:w===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[w===`testing`?P(q,{className:`h-3.5 w-3.5 animate-spin`}):P(se,{className:`h-3.5 w-3.5`}),`Test All`]})]}),k(`div`,{className:`flex items-center gap-2`,children:[P(`button`,{onClick:()=>M(!0),disabled:z||!L||b.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:a(`integrations.saveAndNew`)}),P(`button`,{onClick:()=>M(!1),disabled:z||!L||b.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:b.isPending?a(`integrations.saving`):a(`integrations.save`)})]})]})]})]})}function Z(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}j();var Q=`devices`,Te={id:Q,label:`Devices`,isDefault:!0},Ee=2e4,De=100;function Oe({addonId:i,integrationId:o,onClose:s}){let{t:c}=_e(),[l,u]=O(new Set),[d,f]=O(new Set),[p,m]=O(new Map),[h,_]=O(null),{data:ee}=r(),v=(ee??[]).find(e=>e.addonId===i)?.supportsLocationImport??!1,[y,te]=O(!0),b=e({addonId:i,integrationId:o}).data?.filters,x=b&&b.length>0?b:[Te],[S,w]=O(x.find(e=>e.isDefault)?.id??(x.some(e=>e.id===Q)?Q:x[0].id)),T=S!==Q,E=C(),A=g({addonId:i,integrationId:o,page:1,pageSize:Ee,filter:S}),j=A.refetch,M=E.mutate,N=D(()=>{M({addonId:i,integrationId:o},{onSettled:()=>{j()}})},[M,i,o,j]),F=re(null);ie(()=>{let e=`${i}::${o}`;F.current===e||A.isLoading||(F.current=e,(A.data?.candidates.length??0)===0&&N())},[i,o,A.isLoading,A.data,N]);let I=E.isPending,L=E.isError?E.error instanceof Error?E.error.message:String(E.error):null,R=A.data?.candidates??[],z=A.isError?A.error instanceof Error?A.error.message:String(A.error):null,B=a(),ae=D(e=>{e.alreadyAdopted||u(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),oe=D(e=>{f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),se=D((e,t)=>{m(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),H=D(e=>{let t={};for(let n of e){let e=p.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[p]),ce=D(async()=>{_(null);let e=[...l];if(e.length!==0)try{let t=H(e);await B.mutateAsync({addonId:i,integrationId:o,filter:S,childNativeIds:e,...t?{perCandidate:t}:{},...v?{importLocations:y}:{}}),u(new Set),m(new Map),await j(),s()}catch(e){_(e instanceof Error?e.message:String(e))}},[l,H,B,i,o,S,j,v,y]),W=D(e=>{w(e),u(new Set),f(new Set),m(new Map),_(null)},[]),G=l.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:s}),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:c(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),P(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:c(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),k(`div`,{className:`flex items-center gap-3 shrink-0`,children:[v&&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:y,onChange:e=>te(e.target.checked),className:`accent-primary`}),c(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),P(`button`,{onClick:s,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:P(me,{className:`h-4 w-4`})})]})]}),k(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(L??z)&&R.length===0&&P(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:k(`div`,{className:`flex items-start gap-2`,children:[P(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),k(`div`,{className:`min-w-0`,children:[P(`p`,{className:`text-xs font-medium text-destructive`,children:c(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),P(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:L??z})]})]})}),x.length>1&&P(ke,{filters:x,activeFilter:S,onSelect:W}),P(`div`,{className:`flex-1 min-h-0`,children:P(t,{mode:`generic`,items:R,pageSize:De,getKey:e=>e.childNativeId,getSearchText:Z,getFilterType:e=>e.type,filterOptions:ne(),filterLabel:c(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:A.isLoading||I&&R.length===0,searchPlaceholder:c(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(L??z)&&R.length===0?``:c(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:k(`button`,{type:`button`,onClick:N,disabled:I,title:c(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[P(V,{className:`h-3.5 w-3.5 ${I?`animate-spin`:``}`}),c(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:c(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>P($,{candidate:e,expandable:!T,expanded:d.has(e.childNativeId),onToggleExpand:()=>oe(e.childNativeId),adoptedLabel:c(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:c(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=n(e.type),r=t.icon;return k(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[P(r,{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":l.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${l.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:l.has(e.childNativeId)&&P(U,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!T&&d.has(e.childNativeId),renderExpanded:T?void 0:e=>P(Ae,{candidate:e,hiddenChildIds:p.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>se(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:l.has(e.childNativeId)?`bg-primary/5`:``})})]}),h&&P(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:k(`div`,{className:`flex items-start gap-2`,children:[P(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),P(`p`,{className:`text-[11px] text-destructive`,children:h})]})}),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:s,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:c(`integrations.cancel`,{defaultValue:`Cancel`})}),k(`button`,{onClick:ce,disabled:G===0||B.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[B.isPending&&P(q,{className:`h-3.5 w-3.5 animate-spin`}),c(`integrations.addSelected`,{defaultValue:`Add selected`}),G>0?` (${G})`:``]})]})]})]})]})}function ke({filters:e,activeFilter:t,onSelect:n}){return P(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return P(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function $({candidate:e,expandable:t,expanded:n,onToggleExpand:r,adoptedLabel:i}){let a=(e.children??[]).length;return k(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&a>0?k(`button`,{type:`button`,onClick:r,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[P(n?G:W,{className:`h-3.5 w-3.5`}),a]}):P(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),P(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&P(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:i})]})}function Ae({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let r=e.children??[];return r.length===0?null:P(`div`,{className:`space-y-1 py-1`,children:r.map(e=>{let r=t.has(e.childNativeId),i=e.capabilities??[];return k(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${r?`opacity-50`:``}`,children:[P(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),i.length>0&&P(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:i.join(`, `)}),P(`button`,{onClick:()=>n(e.childNativeId),"aria-label":r?`Show child`:`Hide child`,title:r?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:P(r?H:le,{className:`h-3 w-3`})})]},e.childNativeId)})})}j();function je({integrationId:e,addonId:t,name:n,kind:r,brokerKind:i,trpc:a,onClose:o}){let{t:s}=_e(),c=N(),l=r===`device-adoption`,{data:d}=b({id:e},{enabled:l}),f=A(()=>{let e=d?.brokerId;return typeof e==`string`?e:null},[d]),p=u();return P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:o,children:k(`div`,{className:`max-h-[85vh] w-full max-w-md overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[k(`div`,{className:`mb-3 flex items-center justify-between`,children:[k(`h2`,{className:`text-sm font-semibold text-foreground`,children:[s(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),P(`button`,{onClick:o,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":s(`common.close`,{defaultValue:`Close`}),children:P(me,{className:`h-4 w-4`})})]}),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.`})}),f&&k(`p`,{className:`text-[11px] text-foreground`,children:[s(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,P(`span`,{className:`font-mono text-foreground-subtle`,children:f})]}),p.isPending?k(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[P(q,{className:`h-3 w-3 animate-spin`}),s(`integrations.saving`,{defaultValue:`Saving…`})]}):P(z,{kind:i,onResolved:t=>{p.mutate({id:e,settings:{brokerId:t}},{onSuccess:()=>{c.invalidateQueries(),o()}})},onBack:o}),p.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(w,{trpc:a,addonId:t,nodeId:`hub`,title:n})]})})}j();function Me(){let{t:e}=_e(),{integrationId:n}=fe(),i=N(),a=ue(),[u,g]=ce(),_=F(),[b,S]=O(!1),[C,w]=O(!1),[E,ne]=O(!1),[re,j]=O(!1),[I,z]=O(!1),{data:V,isLoading:se}=c({id:n??``},{enabled:!!n}),{data:H}=l({addonId:V?.addonId??``,nodeId:`hub`},{enabled:!!V?.addonId}),{data:U,isSuccess:W}=r(),G=A(()=>{let e=V?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[U,V?.addonId,W]),{data:le}=p({}),de=A(()=>(le?.providers??[]).some(e=>e.addonId===V?.addonId),[le,V?.addonId]),J=G!==null,be=J?G===`device-adoption`?e(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):e(`integrations.addDevice`):e(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),xe=A(()=>{let e=V?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.brokerKind??null},[U,V?.addonId,W]),Se=A(()=>{let e=V?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.mode??null},[U,V?.addonId,W]);ie(()=>{u.get(`add`)===`1`&&J&&(S(!0),g(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[u,J,g]);let Ce=H!=null&&Array.isArray(H.sections)&&H.sections.some(e=>e.fields.length>0),{data:Y}=v({},{refetchInterval:5e3}),X=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Z=d({onMutate:async e=>{await i.cancelQueries({queryKey:X});let t=i.getQueryData(X);return t!=null&&i.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&i.setQueryData(X,r.previous)},onSettled:()=>{i.invalidateQueries({queryKey:[[`integrations`]]}),i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=o({onSuccess:()=>{i.invalidateQueries({queryKey:[[`integrations`]]}),i.invalidateQueries({queryKey:[[`deviceManager`]]}),j(!1),a(`/integrations`)}}),Te=h({onSuccess:()=>{i.invalidateQueries({queryKey:[[`integrations`]]}),i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ee=T({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),De=y({onSuccess:()=>{i.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=te({onSuccess:()=>{i.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=>a(`/devices/${String(e)}`),[a]),Fe=A(()=>{let e=V?.addonId;return e?$.filter(t=>t.addonId===e):[]},[$,V?.addonId]),Ie=A(()=>s(Fe).length,[Fe]);return se?k(`div`,{className:`p-4`,children:[P(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),P(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):V?k(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[P(x,{items:[{label:`Integrations`,onClick:()=>a(`/integrations`)},{label:V.name}]}),k(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[k(`div`,{className:`flex items-center gap-3 min-w-0`,children:[P(`img`,{src:`/api/addon-assets/${V.addonId}/assets/icon.svg`,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),k(`div`,{className:`min-w-0`,children:[P(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:V.name}),k(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[V.addonId,` · `,Ie,` `,e(`integrations.devices`)]})]})]}),k(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[de&&k(`button`,{onClick:()=>w(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the network for devices (incl. a different subnet)`,children:[P(B,{className:`h-3.5 w-3.5`}),`Scan network`]}),k(`button`,{onClick:()=>S(!0),disabled:!J,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:be,children:[P(R,{className:`h-3.5 w-3.5`}),be]}),k(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${V.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:e(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[P(f,{checked:V.enabled,onCheckedChange:e=>Z.mutate({id:n,enabled:e}),disabled:Z.isPending,"aria-label":V.enabled?`Disable integration`:`Enable integration`}),P(`span`,{className:`text-[11px] font-medium ${V.enabled?`text-success`:`text-foreground-subtle`}`,children:V.enabled?`Enabled`:`Disabled`}),Z.isPending&&P(q,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Se!==`standalone`&&(Ce||G===`device-adoption`)&&k(`button`,{onClick:()=>ne(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[P(pe,{className:`h-3 w-3`}),e(`integrations.config`)]}),k(`button`,{onClick:()=>z(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:e(`integrations.logs`,{defaultValue:`View logs`}),children:[P(he,{className:`h-3 w-3`}),e(`integrations.logs`,{defaultValue:`Logs`})]}),P(m,{label:`Restart`,icon:oe,title:`Restart "${V.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ie} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Te.isPending,action:()=>Te.mutateAsync({addonId:V.addonId})}),k(`button`,{onClick:()=>j(!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:e(`integrations.delete`,{defaultValue:`Delete integration`}),children:[P(ge,{className:`h-3 w-3`}),e(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),P(t,{context:`integration-detail`,devices:$,trpc:_.trpcClient,defaultView:`cards`,forceAddon:V.addonId,urlScope:`root`,lsKey:`integration-detail:${V.addonId}`,resolveIntegrationIcon:Ne,resolveParent:Me,onNavigate:Pe,batchActions:{remove:Ee.mutate,disable:De.mutate,enable:ke.mutate},onDeleteDevice:e=>Ee.mutate({deviceId:e.id})}),b&&n&&G===`device-adoption`&&P(Oe,{addonId:V.addonId,integrationId:n,onClose:()=>S(!1)}),b&&n&&G===`device-provider`&&P(we,{open:b,integrationId:n,addonId:V.addonId,onClose:()=>S(!1)}),C&&V&&P(ae,{open:C,scope:{addonId:V.addonId,label:V.name},onClose:()=>w(!1)}),E&&n&&G!==null&&P(je,{integrationId:n,addonId:V.addonId,name:V.name,kind:G,brokerKind:xe,trpc:_.trpcClient,onClose:()=>ne(!1)}),I&&P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>z(!1),children:k(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[k(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[k(`div`,{className:`flex items-center gap-2 min-w-0`,children:[P(he,{className:`h-4 w-4 text-primary shrink-0`}),P(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:V.name}),k(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[V.addonId,n?` · ${n}`:``]})]}),P(`button`,{onClick:()=>z(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:P(me,{className:`h-4 w-4`})})]}),P(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:P(ee,{addonId:V.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),re&&P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Q.isPending&&j(!1),children:k(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[k(`div`,{className:`flex items-start gap-3`,children:[P(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:P(K,{className:`h-4 w-4 text-danger`})}),k(`div`,{className:`min-w-0`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),P(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:e(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:V.name,count:Ie})})]})]}),Q.error&&P(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Q.error instanceof Error?Q.error.message:String(Q.error)}),k(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[P(`button`,{onClick:()=>j(!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:e(`integrations.cancel`,{defaultValue:`Cancel`})}),P(`button`,{onClick:()=>Q.mutate({id:n}),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(M,{children:[P(q,{className:`h-3 w-3 animate-spin`}),e(`integrations.deleting`,{defaultValue:`Deleting…`})]}):k(M,{children:[P(ge,{className:`h-3 w-3`}),e(`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:e(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),P(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),k(`button`,{onClick:()=>a(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[P(ve,{className:`h-3 w-3`}),e(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{Me as IntegrationDetailPage};