@camstack/addon-admin-ui 1.2.673 → 1.2.675

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 (105) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/assets/Addons-B5cMCuEY.js +5 -0
  3. package/dist/assets/{AdminPage-bLxyruUe.js → AdminPage-BKJUlsLi.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-vnoSnjIu.js → AdminSectionedPage-DSB1PxSl.js} +1 -1
  5. package/dist/assets/AiProfiles-CO33unzR.js +3 -0
  6. package/dist/assets/{BootstrapSettingsForm-CpvlarTT.js → BootstrapSettingsForm-DjGLgW8y.js} +1 -1
  7. package/dist/assets/Build-BAHi2Di4.js +42 -0
  8. package/dist/assets/{Calendars-WPgNTXpb.js → Calendars-C0kIKe0_.js} +1 -1
  9. package/dist/assets/{CameraGrids-DNVLT_g-.js → CameraGrids-BLzTxMZq.js} +1 -1
  10. package/dist/assets/Cluster-DoTX3LAA.js +1 -0
  11. package/dist/assets/CompositionBlockEditor-DeFj50eP.js +2 -0
  12. package/dist/assets/{CompositionEditorPage-xZt9xNnb.js → CompositionEditorPage-D4_TRz9X.js} +1 -1
  13. package/dist/assets/{Data-CX-UI9DM.js → Data-BNtLAI2a.js} +2 -2
  14. package/dist/assets/DeviceDetail-eIUrMHhx.js +2 -0
  15. package/dist/assets/{Devices-KEps1UGm.js → Devices-RlDAUC2M.js} +1 -1
  16. package/dist/assets/{EmbedDevicePage-CXvRePXD.js → EmbedDevicePage-D4Eb7q8W.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-DOewSiDm.js → EmbedPlayerPage-CDyI6F2c.js} +1 -1
  18. package/dist/assets/History-C4Ug3VT5.js +1 -0
  19. package/dist/assets/{Identity-DEvMFJ8U.js → Identity-CiVu8loN.js} +1 -1
  20. package/dist/assets/{InstancesTable-Cn1INVUs.js → InstancesTable-C6Pf-j1u.js} +1 -1
  21. package/dist/assets/IntegrationDetail-B72YnGdY.js +1 -0
  22. package/dist/assets/{Integrations-DZ4d7yCu.js → Integrations-CpfjcIva.js} +1 -1
  23. package/dist/assets/{Integrations-BNPsvsDG.js → Integrations-DtDcBpo2.js} +2 -2
  24. package/dist/assets/{Library-DCLUmh7t.js → Library-B2JKAUaL.js} +1 -1
  25. package/dist/assets/Locations-Cw1FOrs0.js +3 -0
  26. package/dist/assets/Logs-BCZstE4C.js +1 -0
  27. package/dist/assets/{MaskShapeCanvas-BXQi3-T2.js → MaskShapeCanvas-CzmKAhNn.js} +1 -1
  28. package/dist/assets/{MotionZonesSettings-ucz7NSTu.js → MotionZonesSettings-Gtxon45n.js} +1 -1
  29. package/dist/assets/{MyAccess-CBlNgEUN.js → MyAccess-HDB1zCA-.js} +1 -1
  30. package/dist/assets/{Network-0wPLfJ0h.js → Network-DcO6iFcm.js} +1 -1
  31. package/dist/assets/{NodeAddonsSettingsPanel-Bk2zvhh-.js → NodeAddonsSettingsPanel-BU4x5-7q.js} +1 -1
  32. package/dist/assets/Notifications-BwPzQz_8.js +1 -0
  33. package/dist/assets/{Pipeline-CWjfmglV.js → Pipeline-G84v3ij0.js} +1 -1
  34. package/dist/assets/{PrivacyMaskSettings-BpKQjnTN.js → PrivacyMaskSettings-BY6sg6A4.js} +1 -1
  35. package/dist/assets/Recordings-CjXKbLTr.js +1 -0
  36. package/dist/assets/{SceneMonitorEditor-B4x-j-jS.js → SceneMonitorEditor-i7OhxRG-.js} +1 -1
  37. package/dist/assets/ServerShell-DWxCqodO.js +1 -0
  38. package/dist/assets/SessionsList-BCBUA0_b.js +2 -0
  39. package/dist/assets/{Showroom-B1RoJ593.js → Showroom-CbPxSS0-.js} +1 -1
  40. package/dist/assets/{StorageLocationsTable-BU2R2YDl.js → StorageLocationsTable-BAIDNYZE.js} +1 -1
  41. package/dist/assets/{System-9dHx6EzL.js → System-BN_0tWnK.js} +1 -1
  42. package/dist/assets/Terminal-BaeNBCrT.js +3 -0
  43. package/dist/assets/{Terminal-B_CcltGA.js → TerminalPanel-Bp1gZQoy.js} +3 -5
  44. package/dist/assets/{TrainingProviders-BAaea0d6.js → TrainingProviders-BG7fk3jP.js} +1 -1
  45. package/dist/assets/{Viewer-DrgoA7AH.js → Viewer-DeOj6NkB.js} +1 -1
  46. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CoNgx8LV.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-l9ng6Ybr.js} +1 -1
  47. package/dist/assets/{action-draft-DwvVnv-7.js → action-draft-r_kKMuf2.js} +1 -1
  48. package/dist/assets/{ai-page.helpers-C7D3n8iP.js → ai-page.helpers-B01d73HY.js} +1 -1
  49. package/dist/assets/{assignment-candidates-BSCyf2de.js → assignment-candidates-tXGiM44_.js} +1 -1
  50. package/dist/assets/{authed-media-CfvJyG-Y.js → authed-media-u_StVFnl.js} +1 -1
  51. package/dist/assets/{board-model-8UGMkm1I.js → board-model-C-1eQ0ae.js} +1 -1
  52. package/dist/assets/{client-CBrsD14Q.js → client-DbKXlEC4.js} +14 -14
  53. package/dist/assets/{command-vocab-DPH9ECZa.js → command-vocab-0n7AggZw.js} +1 -1
  54. package/dist/assets/{device-detail-K5TWmBwE.js → device-detail-C019bGlW.js} +1 -1
  55. package/dist/assets/{device-integration-icon-W3dt9ax1.js → device-integration-icon-CpZ0OBPQ.js} +1 -1
  56. package/dist/assets/device-picker-model-9s4juC85.js +1 -0
  57. package/dist/assets/{dist-Ch4acd_Z.js → dist-BnoF0i0M.js} +41 -41
  58. package/dist/assets/{dist-EQkuFJsn.js → dist-DDGjJPZi.js} +1 -1
  59. package/dist/assets/{format-CX-wK907.js → format-DfOVHXCT.js} +1 -1
  60. package/dist/assets/{hostInit-Di5WwrRQ.js → hostInit-CFCiEE_B.js} +1 -1
  61. package/dist/assets/i18n-1k63HMS1.js +1 -0
  62. package/dist/assets/{icons-2Ody3esI.js → icons-CBCEFkYd.js} +1 -1
  63. package/dist/assets/index-CWyWRkhx.css +2 -0
  64. package/dist/assets/index-cl6SWsBh.js +4 -0
  65. package/dist/assets/{linked-devices-model-BbPIMVq4.js → linked-devices-model-lSVw-dAG.js} +1 -1
  66. package/dist/assets/{mf-entry-bootstrap-0-80086b95.js → mf-entry-bootstrap-0-c0f4a27e.js} +2 -2
  67. package/dist/assets/mount-9s4juC85.js +1 -0
  68. package/dist/assets/{notification-rule-status-B61HDyRa.js → notification-rule-status-Nsg84Ad6.js} +1 -1
  69. package/dist/assets/{player-overlays-VrMHBBfa.js → player-overlays-BxDm01PX.js} +1 -1
  70. package/dist/assets/remoteEntry-COb4mVPT.js +1 -0
  71. package/dist/assets/{src-bJ4Hy4Cl.js → src-Cn1TCE2g.js} +18 -18
  72. package/dist/assets/{sso-popup-FSdroU2W.js → sso-popup-n86tgOtV.js} +1 -1
  73. package/dist/assets/{step-inspector-model-15-9NhxK.js → step-inspector-model-B1WsVC3m.js} +1 -1
  74. package/dist/assets/{use-scenes-feed-O_MsB8FF.js → use-scenes-feed-BE2grUhu.js} +1 -1
  75. package/dist/assets/{use-stationary-objects-JZ23WYEp.js → use-stationary-objects-C07MtPwR.js} +1 -1
  76. package/dist/assets/{useAdminDeviceRemoval-DCRpnpY6.js → useAdminDeviceRemoval-CVX0q4fL.js} +1 -1
  77. package/dist/assets/useEventInvalidation-9s4juC85.js +1 -0
  78. package/dist/assets/{useNodeUrlSelection-DAnBV8Yi.js → useNodeUrlSelection-8jpiE4sx.js} +1 -1
  79. package/dist/assets/useTemplateSave-Er9UcdNY.js +1 -0
  80. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DguMkCB-.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DxT73bEi.js} +2 -2
  81. package/dist/index.html +9 -9
  82. package/dist/server/addon.js +26 -4
  83. package/package.json +2 -2
  84. package/dist/assets/Addons-Dl4Ed0w_.js +0 -5
  85. package/dist/assets/AiProfiles-CUcDrrtc.js +0 -3
  86. package/dist/assets/Build-BVHmf4sa.js +0 -42
  87. package/dist/assets/Cluster-DXnmd3TJ.js +0 -1
  88. package/dist/assets/CompositionBlockEditor-CfazE3Js.js +0 -2
  89. package/dist/assets/DeviceDetail-bLQrVZ1A.js +0 -2
  90. package/dist/assets/History-DDdKnfJ2.js +0 -1
  91. package/dist/assets/IntegrationDetail-CeDutRAR.js +0 -1
  92. package/dist/assets/Locations-ejPYyz4D.js +0 -3
  93. package/dist/assets/Logs-BS4JYpzd.js +0 -1
  94. package/dist/assets/Notifications-BFiv-KUA.js +0 -1
  95. package/dist/assets/Recordings-B_JPtd9_.js +0 -1
  96. package/dist/assets/SessionsList-DMqcS-nT.js +0 -2
  97. package/dist/assets/device-picker-model-BG-DzgSt.js +0 -1
  98. package/dist/assets/i18n-BFxrpjSx.js +0 -1
  99. package/dist/assets/index-1bBrNxAK.js +0 -4
  100. package/dist/assets/index-CcsmeMTw.css +0 -2
  101. package/dist/assets/mount-BG-DzgSt.js +0 -1
  102. package/dist/assets/remoteEntry-BusdFyUc.js +0 -1
  103. package/dist/assets/useEventInvalidation-BG-DzgSt.js +0 -1
  104. package/dist/assets/useTemplateSave-C4_bd2To.js +0 -1
  105. /package/dist/assets/{Terminal-kHJ-D0s7.css → TerminalPanel-kHJ-D0s7.css} +0 -0
@@ -1 +0,0 @@
1
- import{C as e,K as t,S as n,Y as r,et as i,i as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Fr as s,Hn as c,Jn as l,Jr as u,Za as d,ct as f,en as p,ta as m,ut as h,vt as g,wt as _}from"./player-overlays-VrMHBBfa.js";import{ii as v,js as y}from"./client-CBrsD14Q.js";import{Ai as b,Ar as x,Ca as S,Cn as C,Cp as w,Da as T,Fi as E,Gi as D,Ni as O,Ns as k,Or as A,Pi as ee,Sn as j,Sp as M,Ud as te,Ui as ne,Wf as N,_n as re,an as ie,ba as ae,bn as oe,br as se,cn as ce,dn as P,en as le,fa as F,fn as ue,gn as de,ha as I,in as fe,ji as pe,jr as L,ki as me,ma as R,mn as he,nn as ge,os as _e,pn as ve,sn as ye,ss as be,tn as xe,un as z,vn as Se,wn as Ce,xn as we,xr as Te,yn as Ee}from"./src-bJ4Hy4Cl.js";import{t as B}from"./useTranslation-BJr-n0es.js";import{hi as De}from"./index-1bBrNxAK.js";import{t as Oe}from"./AdminPage-bLxyruUe.js";i();function V(e,t){return e.scope===``?e.displayName:`${e.displayName} · ${t?.(e)??e.scope}`}function ke(e,t,n){let r=[];for(let{device:t,series:i}of e)for(let e of i){let i={subject:{kind:`device`,deviceId:t.id},key:e.key,scope:e.scope};r.push({id:P(i),ref:i,info:e,subjectName:t.name,location:t.location??``,nodeId:``,metric:V(e,n)})}for(let{node:e,series:i}of t)for(let t of i){let i={subject:{kind:`node`,nodeId:e.id},key:t.key,scope:t.scope};r.push({id:P(i),ref:i,info:t,subjectName:e.name,location:``,nodeId:e.id,metric:V(t,n)})}return r}function Ae(e){return[e.subjectName,e.location,e.metric,e.info.key,e.info.unit??``,e.nodeId].join(` `)}function H(e,t,n){if(e.ref.subject.kind!==`device`||t===null)return e.subjectName;let r=t.byId.get(e.ref.subject.deviceId);return r===void 0?e.subjectName:ae(r,`compact`,t,n)}var je=[`energy`,`temperatures`,`nodes`,`storage`],Me=new Set([`cap:temperature-sensor.temperature`,`cap:climate-control.currentTemp`]),U=[`addon:metrics-native/node-cpu-percent`,`addon:metrics-native/node-memory-percent`],Ne=`addon:storage-orchestrator/location-used-percent`;function Pe(e,t){let n=(e,n)=>{let r=t.filter(e);return z((n?[...r].sort(n):r).map(e=>e.ref))};switch(e){case`energy`:return n(e=>e.ref.subject.kind===`device`&&e.info.key===`derived:energy.kwh`);case`temperatures`:return n(e=>e.ref.subject.kind===`device`&&Me.has(e.info.key)&&e.info.scope===``,(e,t)=>e.location.localeCompare(t.location)||e.subjectName.localeCompare(t.subjectName));case`nodes`:return n(e=>e.ref.subject.kind===`node`&&U.includes(e.info.key)&&e.info.scope===``,(e,t)=>U.indexOf(e.info.key)-U.indexOf(t.info.key)||e.subjectName.localeCompare(t.subjectName));case`storage`:return n(e=>e.ref.subject.kind===`node`&&e.info.key===Ne)}}function Fe(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=[],a=[],o=[];for(let t of z(e)){let e=n.get(P(t));if(e===void 0){o.push(t);continue}e.info.key===`derived:energy.kwh`?a.push(e):e.info.kind===`boolean`||e.info.kind===`enum`?i.push(e):r.push(e)}return{lines:r,states:i,energy:a,missing:o}}function W(e){return e.subject.kind===`device`?{deviceId:e.subject.deviceId,key:e.key,scope:e.scope}:{forNodeId:e.subject.nodeId,key:e.key,scope:e.scope}}var G=`history-page`;function Ie({part:r,window:i}){let{t:a}=B(),o=d(),s=T(),c=S(),l=e=>`${H(e,s,c)} · ${e.metric}`,u=t(()=>[...r.lines,...r.states,...r.energy],[r]),f=fe(t(()=>u.map(e=>W(e.ref)),[u]),i,!1),p=e=>f.status===`ok`?f.data.current.get(ge(W(e.ref))):void 0,h=e=>{let t=p(e);return t?.ok?t.result:void 0};if(u.length===0)return n(D,{icon:m,title:a(`history.page.emptyTitle`,`Pick series to compare`),description:a(`history.page.emptyHint`,`Choose up to 24 series on the left, or start from a panel above.`)});if(f.status===`error`)return n(F,{title:a(`history.page.readFailed`,`History could not be read`),message:f.error});let g=f.status===`pending`,_=u.map(e=>({c:e,e:p(e)})).filter(e=>e.e?.ok===!1),v=r.lines.map((e,t)=>{let n=h(e),r=re(e.info,n,i.from);return{id:e.id,label:l(e),unit:e.info.unit,colorIndex:t,points:r.points,gapMs:r.gapMs,interpolation:r.held&&n?.resolution===`raw`?`step`:`linear`}}),y=r.states.map((e,t)=>{let n=Se(e.info,h(e),i.from,i.to),r=he(e.info.key,o);return{id:e.id,label:l(e),kind:e.info.kind===`boolean`?`boolean`:`enum`,colorIndex:e.info.kind===`boolean`?t:0,states:n.states,segments:n.segments,totals:n.totals,stateLabel:e.info.kind===`boolean`?e=>e===`true`?r.on:r.off:void 0}}),b=r.energy.map(e=>({c:e,...de(h(e))})),x=b[0]?.bucketMs??36e5,w=[...new Set(b.flatMap(e=>e.buckets.map(e=>e.t)))].sort((e,t)=>e-t).map(e=>({t:e,values:b.map(t=>t.buckets.find(t=>t.t===e)?.values[0]??null)}));return e(`div`,{className:`space-y-5 min-w-0`,children:[_.length>0&&n(F,{title:a(`history.page.someFailed`,`Some series could not be read`),message:_.map(e=>`${l(e.c)}: ${e.e.error}`).join(` · `)}),v.length>0&&n(C,{title:a(`history.page.lines`,`Measurements`),series:v,range:i,height:260,syncKey:G,pending:g}),b.length>0&&n(ne,{title:a(`history.page.energy`,`Energy`),layers:b.map((e,t)=>({id:e.c.id,label:H(e.c,s,c),colorIndex:t})),buckets:w,bucketMs:x,range:i,unit:`kWh`,showTotal:!0,height:160,syncKey:G,pending:g}),y.length>0&&n(Ce,{title:y.length===1?y[0]?.label??``:a(`history.page.states`,`States`),rows:y,range:i,syncKey:G,pending:g})]})}function Le(e,t){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}async function Re(e,t){let n=[];for(let r of Le(e,50))try{let{results:e}=await t(r),i=new Map(e.map(e=>[e.seriesId,e]));for(let e of r)n.push(i.get(e)??{seriesId:e,ok:!1,reason:`not-found`})}catch(e){let t=e instanceof Error?e.message:String(e);for(let e of r)n.push({seriesId:e,ok:!1,reason:`request-failed`,message:t})}return n}function K(e){return e.raw+e[`5m`]+e[`1h`]+e[`1d`]}function ze(e){return e.reduce((e,t)=>t.ok?{...e,deleted:e.deleted+1,points:e.points+K(t.deleted)}:{...e,refused:e.refused+1},{deleted:0,refused:0,points:0})}function Be(e,t){let n=new Map(e.map(e=>[e.seriesId,e]));return t.flatMap(e=>{let t=n.get(e.seriesId);return t===void 0?[]:[{series:t,outcome:e}]})}var q=e=>new Date(e).toLocaleDateString(void 0,{dateStyle:`short`});function J(e,t,n){let r=t.get(e.deviceId);return r===void 0?e.reason===`device-gone`?n(`history.orphans.deviceRemoved`,`#{{id}} (removed)`,{id:e.deviceId}):n(`history.orphans.deviceId`,`#{{id}}`,{id:e.deviceId}):r}function Y(e){let t=e.displayName??e.key;return e.scope===``?t:`${t} · ${e.scope}`}function X(t,r,i){return{key:`series`,header:i(`history.orphans.colSeries`,`Series`),render:a=>{let o=t(a);return e(`div`,{className:`min-w-0 max-w-[16rem]`,children:[n(`div`,{className:`truncate text-foreground`,title:o.key,children:Y(o)}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:J(o,r,i)})]})},sortValue:e=>`${J(t(e),r,i)} ${Y(t(e))}`}}var Ve=[`raw`,`5m`,`1h`,`1d`];function He(e,t){return e===`raw`?t(`history.orphans.colRaw`,`Raw points`):e===`5m`?t(`history.orphans.col5m`,`5 min`):e===`1h`?t(`history.orphans.col1h`,`1 h`):t(`history.orphans.col1d`,`1 day`)}function Ue(t,r){return[X(e=>e,t,r),{key:`reason`,header:r(`history.orphans.colReason`,`Reason`),render:t=>e(`div`,{className:`flex flex-col items-start gap-0.5`,children:[n(R,{variant:t.reason===`device-gone`?`warning`:`neutral`,className:`text-[10px]`,children:t.reason===`device-gone`?r(`history.orphans.deviceGone`,`Device removed`):r(`history.orphans.undeclared`,`No longer declared`)}),t.missingSince!==null&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`history.orphans.since`,`since {{date}}`,{date:q(t.missingSince)})})]}),sortValue:e=>e.reason},{key:`span`,header:r(`history.orphans.colSpan`,`Recorded`),render:t=>e(`span`,{className:`tabular-nums text-foreground-muted`,children:[q(t.firstTs),` → `,q(t.lastTs)]}),sortValue:e=>e.lastTs},...Ve.map(e=>({key:`rows-${e}`,header:He(e,r),align:`right`,render:t=>n(`span`,{className:`tabular-nums text-foreground-muted`,children:t.rows[e].toLocaleString()}),sortValue:t=>t.rows[e]}))]}function We(e,t){if(e.ok)return n(R,{variant:`success`,className:`text-[10px]`,children:t(`history.orphans.deleted`,{count:K(e.deleted),points:K(e.deleted).toLocaleString(),defaultValue_one:`Deleted · {{points}} point`,defaultValue_other:`Deleted · {{points}} points`})});let r=e.reason===`request-failed`?t(`history.orphans.requestFailed`,`Not sent: {{message}}`,{message:e.message}):e.reason===`not-orphan`?t(`history.orphans.refusedNotOrphan`,`Kept: no longer orphan`):e.reason===`not-found`?t(`history.orphans.refusedNotFound`,`Already gone`):t(`history.orphans.refusedFailed`,`The hub could not delete it`);return n(R,{variant:e.reason===`not-found`?`neutral`:`warning`,className:`text-[10px]`,children:r})}function Ge(e,t){return[X(e=>e.series,e,t),{key:`result`,header:t(`history.orphans.colResult`,`Result`),render:e=>We(e.outcome,t),sortValue:e=>+!e.outcome.ok}]}i();function Ke({open:i,onClose:a,list:o,deviceNames:c,onDelete:u,onRefresh:d,refreshing:m}){let{t:h}=B(),g=f(),[_,v]=r(new Set),[y,S]=r(!1),[C,w]=r([]),T=t(()=>Ue(c,h),[c,h]),D=t(()=>Ge(c,h),[c,h]),k=t(()=>new Set(o.series.map(e=>String(e.seriesId))),[o.series]),A=[..._].filter(e=>k.has(e)).map(Number),j=ze(C.map(e=>e.outcome)),M=async()=>{if(await g({title:h(`history.orphans.confirmTitle`,{count:A.length,defaultValue_one:`Delete {{count}} series`,defaultValue_other:`Delete {{count}} series`}),message:h(`history.orphans.confirmMessage`,`Every recorded point of these series is removed from the hub. This cannot be undone.`),confirmLabel:h(`history.orphans.confirmLabel`,`Delete`),variant:`danger`})){S(!0);try{let e=await Re(A,u);w(Be(o.series,e)),v(new Set)}finally{S(!1),d()}}};return n(me,{open:i,onOpenChange:e=>!e&&a(),children:e(pe,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`orphan-series-dialog`,children:[n(ee,{children:n(E,{children:h(`history.orphans.title`,`Series no longer linked to a device`)})}),e(b,{className:`space-y-3`,children:[n(`p`,{className:`text-xs text-foreground-muted`,children:h(`history.orphans.intro`,`Nothing records into these series any more: their device was removed, or no capability declares them now. Select the ones to delete.`)}),o.truncated&&e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`orphan-truncated`,children:[n(`p`,{className:`text-xs text-warning`,children:h(`history.orphans.truncated`,`More series are unlinked than are listed here. Delete these, then load the rest.`)}),e(N,{size:`sm`,variant:`outline`,onClick:d,disabled:m,children:[n(l,{className:`h-3 w-3`,"aria-hidden":!0}),h(`history.orphans.loadAgain`,`Load again`)]})]}),C.length>0&&e(`div`,{className:`space-y-2`,"data-testid":`orphan-outcomes`,children:[n(`p`,{className:`text-xs text-foreground`,"aria-live":`polite`,children:h(`history.orphans.summary`,{count:j.deleted,refused:j.refused,points:j.points.toLocaleString(),defaultValue_one:`{{count}} series deleted ({{points}} points), {{refused}} kept.`,defaultValue_other:`{{count}} series deleted ({{points}} points), {{refused}} kept.`})}),n(x,{columns:D,rows:C,rowKey:e=>String(e.series.seriesId),minWidthPx:420,maxBodyHeight:`max-h-[60vh]`,emptyMessage:``})]}),n(x,{columns:T,rows:o.series,rowKey:e=>String(e.seriesId),minWidthPx:760,maxBodyHeight:L,defaultSort:{columnKey:`series`,dir:`asc`},emptyMessage:h(`history.orphans.empty`,`Every series is linked to a device.`),selection:{selected:_,onChange:v,rowLabel:e=>`${Y(e)} — ${J(e,c,h)}`,pageLabel:h(`history.orphans.selectAll`,`Select every listed series`)}})]}),e(O,{children:[n(`span`,{className:`mr-auto text-[11px] tabular-nums text-foreground`,"aria-live":`polite`,children:h(`history.orphans.selected`,{count:A.length,defaultValue_one:`{{count}} selected`,defaultValue_other:`{{count}} selected`})}),n(N,{variant:`ghost`,size:`sm`,onClick:a,children:h(`history.orphans.close`,`Close`)}),e(N,{variant:`danger`,size:`sm`,disabled:A.length===0||y,onClick:()=>void M(),children:[y?n(s,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):n(p,{className:`h-3 w-3`,"aria-hidden":!0}),h(`history.orphans.deleteSelected`,`Delete selected`)]})]})]})})}i();var Z=5*6e4;function qe({enabled:i}){let{t:a}=B(),[s,c]=r(!1),l=be({},{enabled:i,staleTime:Z}),u=k({projection:`slim`},{enabled:i}),d=_e(),f=t(()=>new Map((u.data??[]).map(e=>[e.id,e.name])),[u.data]),p=e=>d.mutateAsync({seriesIds:[...e]});if(!i||l.status===`pending`)return null;if(l.status===`error`)return n(F,{variant:`warning`,title:a(`history.orphans.checkFailedTitle`,`Could not check for unlinked series`),message:l.error.message,onRetry:()=>void l.refetch()});let m=l.data;if(m.series.length===0&&!s)return null;let h=m.series.length;return e(o,{children:[h>0&&n(F,{variant:`warning`,message:m.truncated?a(`history.orphans.noticeMore`,{count:h,defaultValue_one:`More than {{count}} series are no longer linked to a device.`,defaultValue_other:`More than {{count}} series are no longer linked to a device.`}):a(`history.orphans.notice`,{count:h,defaultValue_one:`{{count}} series is no longer linked to a device.`,defaultValue_other:`{{count}} series are no longer linked to a device.`}),action:n(N,{size:`sm`,variant:`outline`,onClick:()=>c(!0),children:a(`history.orphans.review`,`Review`)})}),n(Ke,{open:s,onClose:()=>c(!1),list:m,deviceNames:f,onDelete:p,onRefresh:()=>void l.refetch(),refreshing:l.isFetching})]})}i();var Q=`device`,Je=`node`;function Ye({catalog:r,selected:i,onChange:a,loading:o}){let{t:s}=B(),c=T(),l=S(),u=e=>H(e,c,l),d=se(r,{searchText:e=>[Ae(e)],facetGroups:[{id:`subject`,value:e=>e.ref.subject.kind===`device`?Q:Je},{id:`room`,value:e=>e.location},{id:`unit`,value:e=>e.info.unit??``}]}),f=t(()=>[{key:`metric`,header:s(`history.picker.series`,`Series`),render:t=>e(`div`,{className:`min-w-0`,children:[n(`div`,{className:`truncate text-foreground`,children:t.metric}),n(`div`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.location===``?u(t):`${u(t)} · ${t.location}`})]}),sortValue:e=>`${e.subjectName} ${e.metric}`},{key:`unit`,header:s(`history.picker.unit`,`Unit`),render:e=>n(`span`,{className:`text-foreground-muted`,children:e.info.unit??`—`}),sortValue:e=>e.info.unit??``}],[s,c,l]),p=i.size>=24;return e(`div`,{className:`space-y-2 min-w-0`,children:[n(Te,{state:d.state,facets:[],groups:[{...d.groups.find(e=>e.id===`subject`)??{id:`subject`,facets:[],selected:[]},label:s(`history.picker.subject`,`Source`),facetLabel:e=>e===Q?s(`history.picker.devices`,`Devices`):s(`history.picker.nodes`,`Nodes`)},{...d.groups.find(e=>e.id===`room`)??{id:`room`,facets:[],selected:[]},label:s(`history.picker.room`,`Room`),facetLabel:e=>e===``?s(`history.picker.noRoom`,`No room`):e},{...d.groups.find(e=>e.id===`unit`)??{id:`unit`,facets:[],selected:[]},label:s(`history.picker.metricType`,`Unit`),facetLabel:e=>e===``?s(`history.picker.noUnit`,`States & counts`):e}],labels:{searchPlaceholder:s(`history.picker.search`,`Search device, room, metric or node…`),searchLabel:s(`history.picker.searchLabel`,`Search series`),facetsLabel:s(`history.picker.facets`,`Filters`),clearLabel:s(`history.picker.clear`,`Clear`)},onSearch:d.setSearch,onToggleFacet:d.toggleFacet,onToggleGroupFacet:d.toggleGroupFacet,onClear:d.clear}),n(`p`,{className:`text-[10px] text-foreground-subtle`,"aria-live":`polite`,children:s(`history.picker.count`,`{{count}} of {{max}} selected`,{count:i.size,max:24})}),n(x,{columns:f,rows:d.rows,rowKey:e=>e.id,maxBodyHeight:L,pageSize:50,defaultSort:{columnKey:`metric`,dir:`asc`},emptyMessage:o?s(`history.picker.loading`,`Reading the series of every device…`):d.active?s(`history.picker.emptyFiltered`,`No series match these filters.`):s(`history.picker.empty`,`Nothing is recorded yet.`),selection:{selected:i,onChange:e=>{let t=[...e].filter(e=>i.has(e)),n=[...e].filter(e=>!i.has(e));a(new Set([...t,...n].slice(0,24)))},isSelectable:e=>i.has(e.id)||!p,rowLabel:e=>`${u(e)} · ${e.metric}`,pageLabel:s(`history.picker.selectPage`,`Select every series on this page`)}})]})}i();var Xe=new Set([y.Container]),$=5*6e4;function Ze(){let{t:r}=B(),i=M(`device-history`),[a,o]=De(),s=t(()=>z(a.getAll(`s`).flatMap(e=>{let t=ye(e);return t===null?[]:[t]})),[a]),l=a.get(`window`),d=we(l)?l:`7d`,p=Ee(a.get(`range`)),g=(e,t,n)=>{let r=new URLSearchParams;for(let t of z(e))r.append(`s`,ce(t));t!==`7d`&&r.set(`window`,t);let i=n===void 0?a.get(`range`):n;t===`custom`&&i&&r.set(`range`,i),o(r,{replace:!0})},v=Qe(i===`present`),y=j(d,Date.now(),p),b=j(d,xe(Date.now(),y.to-y.from),p),x=t(()=>Fe(s,v.candidates),[s,v.candidates]),S=t(()=>new Set(s.map(P)),[s]),C=le(),w=h(),T=f(),E=async()=>{let e=await w({title:r(`history.page.saveTitle`,`Save as panel`),label:r(`history.page.saveName`,`Panel name`),confirmLabel:r(`history.page.save`,`Save`)});e===null||e.trim()===``||await C.update(t=>ue(t,{id:`panel-${Date.now().toString(36)}`,name:e.trim().slice(0,80),window:d,selection:[...s]}))},O=async(e,t)=>{await T({title:r(`history.page.deleteTitle`,`Delete panel`),message:r(`history.page.deleteMessage`,`The panel "{{name}}" is removed from your account.`,{name:t}),confirmLabel:r(`history.page.delete`,`Delete`),variant:`danger`})&&await C.update(t=>ve(t,e))},k=e=>e===`energy`?r(`history.panels.energy`,`Total energy`):e===`temperatures`?r(`history.panels.temperatures`,`Temperatures by room`):e===`nodes`?r(`history.panels.nodes`,`Cluster nodes`):r(`history.panels.storage`,`Storage locations`);return n(Oe,{icon:m,title:r(`history.page.title`,`History`),subtitle:r(`history.page.subtitle`,`What devices, nodes and storage recorded over time, side by side.`),actions:i===`present`?e(N,{size:`sm`,variant:`outline`,onClick:()=>void E(),disabled:s.length===0||!C.writable,children:[n(c,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),r(`history.page.saveTitle`,`Save as panel`)]}):void 0,children:i===`pending`?n(I,{className:`h-64 w-full`}):i===`unknown`?n(F,{title:r(`history.page.presenceUnknownTitle`,`Could not reach the hub`),message:r(`history.page.presenceUnknown`,`The hub did not say whether device history is installed. Try again in a moment.`)}):i===`absent`?n(D,{icon:u,title:r(`history.page.absentTitle`,`Device history is not running on this hub`),description:r(`history.page.absent`,`Nothing is recorded until the device-history system addon is enabled.`)}):e(`div`,{className:`space-y-3 sm:space-y-4`,children:[n(qe,{enabled:i===`present`}),e(`div`,{className:`flex flex-wrap items-center gap-2`,role:`group`,"aria-label":r(`history.page.panels`,`Panels`),children:[je.map(e=>n(N,{size:`sm`,variant:`outline`,disabled:v.status!==`ok`,onClick:()=>g(Pe(e,v.candidates),d),children:k(e)},e)),C.value.panels.map(t=>e(`span`,{className:`inline-flex items-center`,children:[n(N,{size:`sm`,variant:`secondary`,onClick:()=>g(t.selection,t.window,null),children:t.name}),n(N,{size:`sm`,variant:`ghost`,"aria-label":r(`history.page.deleteNamed`,`Delete panel {{name}}`,{name:t.name}),onClick:()=>void O(t.id,t.name),disabled:!C.writable,children:n(_,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]},t.id))]}),e(`div`,{className:`grid grid-cols-1 gap-3 sm:gap-4 xl:grid-cols-5`,children:[n(`div`,{className:`min-w-0 xl:col-span-2`,children:n(A,{headingId:`history-picker`,title:r(`history.picker.title`,`Series`),children:n(`div`,{className:`p-2 sm:p-3`,children:v.status===`error`?n(F,{message:v.error}):n(Ye,{catalog:v.candidates,loading:v.status===`pending`,selected:S,onChange:e=>{let t=s.filter(t=>e.has(P(t))),n=v.candidates.filter(t=>e.has(t.id)&&!S.has(t.id)).map(e=>e.ref);g([...t,...n],d)}})})})}),n(`div`,{className:`min-w-0 xl:col-span-3`,children:n(A,{headingId:`history-overlay`,title:r(`history.page.overlay`,`Overlay`),actions:s.length>0?n(N,{size:`sm`,variant:`ghost`,onClick:()=>g([],d),children:r(`history.page.clear`,`Clear`)}):void 0,children:e(`div`,{className:`p-2 sm:p-3 space-y-3 min-w-0`,children:[n(ie,{value:d,onChange:e=>g(s,e),custom:p,onCustomChange:e=>g(s,`custom`,oe(e))}),v.status===`pending`&&s.length>0?n(I,{className:`h-64 w-full`}):n(Ie,{part:x,window:b}),x.missing.length>0&&v.status===`ok`&&n(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`history.page.missing`,{count:x.missing.length,defaultValue_one:`{{count}} selected series is no longer recorded.`,defaultValue_other:`{{count}} selected series are no longer recorded.`})})]})})})]})]})})}function Qe(e){let{t:n}=B(),r=n(`history.picker.wholeFrame`,`Whole frame`),i=g().trpcClient,o=k({projection:`slim`},{enabled:e}),{nodes:s}=w(),c=t(()=>(o.data??[]).filter(e=>!Xe.has(String(e.type))),[o.data]),l=a({queries:c.map(t=>({queryKey:[`device-history`,`listSeries`,t.id],queryFn:()=>i.deviceHistory.listSeries.query({deviceId:t.id}),enabled:e,staleTime:$}))}),u=a({queries:s.map(t=>({queryKey:[`device-history`,`listNodeSeries`,t.id],queryFn:()=>i.deviceHistory.listNodeSeries.query({forNodeId:t.id}),enabled:e,staleTime:$}))}),d=te({},{enabled:e,staleTime:$}),f=t(()=>new Map((d?.data??[]).map(e=>[e.id,e.displayName])),[d?.data]),p=l.map(e=>e.data),m=u.map(e=>e.data),h=t(()=>ke(c.flatMap((e,t)=>{let n=p[t];return n===void 0?[]:[{device:{id:e.id,name:e.name,location:e.location??null},series:n}]}),s.flatMap((e,t)=>{let n=m[t];return n===void 0?[]:[{node:{id:e.id,name:e.name},series:n}]}),e=>{if(e.key!==`addon:pipeline-analytics/occupancy`)return f.get(e.scope)??e.scope;let{zoneId:t,className:n}=v(e.scope),i=t===``?r:t;return n===void 0?i:`${i} · ${n}`}),[c,s,f,[...l,...u].map(e=>e.dataUpdatedAt).join(`,`),r]);return o.status===`error`?{status:`error`,error:o.error.message,candidates:[]}:{status:o.status===`pending`||l.some(e=>e.isPending)||u.some(e=>e.isPending)?`pending`:`ok`,error:``,candidates:h}}export{Ze as HistoryPage};
@@ -1 +0,0 @@
1
- import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Bn as d,Fa as f,Fn as p,Fr as m,Jn as h,Kn as g,Li as _,Ot as v,Qi as y,Ua as b,Ui as x,Xt as S,Za as C,Zn as w,ea as T,en as E,mi as D,pi as O,rr as ee,vt as k,yi as A}from"./player-overlays-VrMHBBfa.js";import{js as j}from"./client-CBrsD14Q.js";import{t as M}from"./chevron-down-CBb-F8DT.js";import{t as N}from"./search-x-C5ra3Aft.js";import{Ai as P,At as F,Bc as te,Cr as I,Cs as L,Fc as R,Fi as z,Fo as B,Hc as V,Io as H,Is as U,Jr as W,Kr as G,Mc as ne,Ni as K,Nr as re,Ns as ie,Os as q,Pi as ae,Qf as J,Rc as Y,Ss as oe,Ts as se,Us as X,Vc as ce,Wf as Z,Ws as Q,Yr as le,_p as ue,bp as de,cc as fe,ds as pe,ei as me,fa as he,fs as ge,gs as _e,i as ve,ji as ye,ki as be,lr as xe,ls as Se,ms as Ce,no as we,oa as Te,ps as Ee,qr as De,r as Oe,ri as ke,us as Ae,vs as je,vt as Me,xt as Ne,ys as Pe,yt as Fe,zc as Ie}from"./src-bJ4Hy4Cl.js";import{t as $}from"./useTranslation-BJr-n0es.js";import{J as Le,Mt as Re,X as ze,Y as Be,bt as Ve,ct as He,dt as Ue,ft as We,hi as Ge,li as Ke,lt as qe,mi as Je,nt as Ye,pi as Xe,ut as Ze}from"./index-1bBrNxAK.js";import{t as Qe}from"./useAdminDeviceRemoval-DCRpnpY6.js";import{t as $e}from"./device-integration-icon-W3dt9ax1.js";c();function et(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...et(n.fields));return t}function tt(e,t,i){let[a,s]=o(`idle`),[c,l]=o({}),u=n(()=>{let t=[];for(let n of e.sections)t.push(...et(n.fields));return t},[e]),d=u.length>0&&i!==void 0,f=r(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:r(async()=>{if(!i)return;let e=u.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;s(`testing`);let n={};for(let t of e)n[t]={status:`probing`};l(n);let r=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await i(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of r)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),s(`idle`)},[i,u,t]),clearProbeResult:f}}c();function nt(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(...nt(n.fields));return t}function rt(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function it(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){it(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function at(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function ot(e,t){let n=X({addonId:e,integrationId:t}),r=n.data?.deviceType??null,i=q({addonId:e,integrationId:t,type:r??j.Camera},{enabled:n.isSuccess&&r!==null});return n.isError?`unavailable`:n.isLoading?`loading`:r===null||i.isError?`unavailable`:i.isLoading||!i.isSuccess?`loading`:((i.data??null)?.sections??[]).some(e=>e.fields.length>0)?`available`:`unavailable`}function st({integrationId:t,addonId:s,onClose:c}){let{t:f}=$(),p=l(),[h,g]=o({}),[_,y]=o(!1),[b,x]=o(null),[C,w]=o(at),T=X({addonId:s,integrationId:t},{enabled:!0}),E=T.data?.deviceType??null,D=q({addonId:s,integrationId:t,type:E??j.Camera},{enabled:T.isSuccess&&E!==null}),O=D.data??null;a(()=>{g(O?it(O.sections.flatMap(e=>e.fields)):{}),w(at()),y(!1),x(null)},[!0,t,O]);let ee=n(()=>({...h,_probeRequestId:C}),[h,C]),k=je({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),A=fe(),N=r(async(e,t)=>{y(!0);let n=await A.mutateAsync({addonId:s,type:E??j.Camera,key:e,value:t,formValues:ee});return n.status===`ok`&&n.suggestedValues&&g(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))rt(e[i])&&!rt(a)&&(r[i]=a,t=!0);return t?r:e}),n},[A,s,ee,E]),{testAllStatus:F,hasProbeFields:te,probeResults:I,handleTestAll:L,clearProbeResult:R}=tt(O??{sections:[]},h,N);async function z(e){x(null);try{await k.mutateAsync({addonId:s,type:E??j.Camera,config:h,integrationId:t}),e?g(O?it(O.sections.flatMap(e=>e.fields)):{}):c()}catch(e){x(e instanceof Error?e.message:String(e))}}let B=nt((O?.sections??[]).flatMap(e=>e.fields)).filter(e=>rt(h[e])),V=B.length===0,H=T.isLoading||E!==null&&D.isLoading,U=T.isError||T.isSuccess&&E===null||D.isError||D.isSuccess&&O===null;return e(u,{children:[i(P,{className:`space-y-3`,children:H?i(`div`,{className:`flex items-center justify-center py-8`,children:i(m,{className:`h-5 w-5 animate-spin text-primary`})}):U?e(`div`,{className:`flex items-start gap-3 rounded-lg border border-danger/40 bg-danger/10 px-4 py-3`,children:[i(S,{className:`h-4 w-4 text-danger mt-0.5 shrink-0`}),e(`div`,{className:`space-y-1`,children:[i(`p`,{className:`text-xs font-medium text-danger`,children:f(`integrations.addDeviceDialog.providerUnavailable`,`Provider unavailable`)}),i(`p`,{className:`text-xs text-foreground-subtle`,children:i(Ke,{i18nKey:`integrations.addDeviceDialog.notReady`,values:{addonId:s},components:{mono:i(`span`,{className:`font-mono`})}})})]})]}):i(Re,{schema:O,values:h,onChange:g,onTestField:N,probeResults:I,onClearProbe:R})}),!U&&!H&&e(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[e(Z,{variant:`unstyled`,type:`button`,onClick:()=>y(e=>!e),className:`flex w-full items-center justify-between px-3 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[e(`span`,{className:`flex items-center gap-2`,children:[i(d,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceDialog.testLogs`,`Test logs`),i(`span`,{className:`font-mono text-[9px] opacity-60`,children:C.slice(0,14)})]}),i(M,{className:`h-3.5 w-3.5 transition-transform ${_?`rotate-180`:``}`})]}),_&&i(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:i(xe,{addonId:s,requestId:C,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!U&&!H&&(b||B.length>0)&&i(`div`,{className:`border-t border-danger/30 bg-danger/5 px-3 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(S,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-danger`,children:b||f(`integrations.addDeviceDialog.required`,`Required: {{value1}}`,{value1:B.join(`, `)})})]})}),e(K,{className:`justify-between`,children:[e(`div`,{className:`flex items-center gap-2`,children:[i(Z,{variant:`unstyled`,onClick:c,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.cancel`)}),!U&&te&&e(Z,{variant:`unstyled`,type:`button`,onClick:L,disabled:F===`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:[F===`testing`?i(m,{className:`h-3.5 w-3.5 animate-spin`}):i(v,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceDialog.testAll`,`Test All`)]})]}),e(`div`,{className:`flex items-center gap-2`,children:[i(Z,{variant:`unstyled`,onClick:()=>z(!0),disabled:U||!V||k.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:f(`integrations.saveAndNew`)}),i(Z,{variant:`unstyled`,onClick:()=>z(!1),disabled:U||!V||k.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:k.isPending?f(`integrations.saving`):f(`integrations.save`)})]})]})]})}var ct=1500;function lt({addonId:t,integrationId:n,jobId:r,onFinished:a}){let{t:o}=$(),s=Ae(),c=(Ee({addonId:t,integrationId:n},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?ct:!1}).data??[]).find(e=>e.jobId===r);if(!c)return null;let l=c.state===`running`,u=c.processed,d=c.total>0?Math.round(u/c.total*100):0;!l&&c.finishedAt!==null&&a();let f=[`${u}/${c.total} ${o(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&f.push(`${c.adopted} ${o(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&f.push(`${c.alreadyAdopted} ${o(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&f.push(`${c.failed} ${o(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return e(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[e(`div`,{className:`flex items-center gap-2`,children:[l?i(m,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?i(S,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?i(_,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):i(x,{className:`h-3.5 w-3.5 text-primary shrink-0`}),i(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&i(Z,{variant:`unstyled`,onClick:()=>s.mutate({jobId:r}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),i(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:i(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),c.results.filter(e=>e.outcome===`failed`).slice(0,5).map(t=>e(`p`,{className:`text-[11px] text-destructive`,children:[t.childNativeId,`: `,t.error]},t.childNativeId))]})}function ut(e){let t=e.map(e=>({...e,stableId:e.childNativeId})),n=new Map(e.map(e=>[e.childNativeId,e])),r=(e,t,i)=>e.flatMap(e=>{let a=n.get(e.candidate.childNativeId);return a===void 0?[]:[{candidate:a,depth:t,...i===void 0?{}:{parentName:i}},...r(e.children,t+1,a.name)]});return r(Be(t),0)}function dt(e){let t=e.metadata?.model,n=e.childNativeId.split(`:`).pop()??``;return[typeof t==`string`?t:``,n].filter(e=>e.length>0).join(` · `)}function ft(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(` `)}c();var pt=`devices`;function mt(e){return{id:pt,label:e(`integrations.adoptDevicesModal.defaultFilter`),isDefault:!0}}var ht=2e4,gt=100;function _t({addonId:s,integrationId:c,onClose:d}){let f=C(),{t:p}=$(),h=l(),[_,v]=o(new Set),[y,x]=o(new Set),[w,E]=o(new Map),[D,O]=o(null),{data:ee}=te(),k=(ee??[]).find(e=>e.addonId===s)?.supportsLocationImport??!1,[A,j]=o(!0),M=pe({addonId:s,integrationId:c}).data?.filters,N=M&&M.length>0?M:[mt(p)],[P,F]=o(N.find(e=>e.isDefault)?.id??(N.some(e=>e.id===pt)?pt:N[0].id)),I=P!==pt,L=Ce(),R=ge({addonId:s,integrationId:c,page:1,pageSize:ht,filter:P}),z=R.refetch,B=L.mutate,V=r(()=>{B({addonId:s,integrationId:c},{onSettled:()=>{z()}})},[B,s,c,z]),H=t(null);a(()=>{let e=`${s}::${c}`;H.current===e||R.isLoading||(H.current=e,(R.data?.candidates.length??0)===0&&V())},[s,c,R.isLoading,R.data,V]);let U=L.isPending,W=L.isError?L.error instanceof Error?L.error.message:String(L.error):null,G=typeof L.data?.lastError==`string`&&L.data.lastError.length>0?L.data.lastError:null,ne=R.data?.candidates??[],re=n(()=>ut(ne),[ne]),ie=n(()=>new Map(re.map(e=>[e.candidate.childNativeId,e.depth])),[re]),q=n(()=>new Map(re.map(e=>[e.candidate.childNativeId,e.parentName])),[re]),ae=R.isError?R.error instanceof Error?R.error.message:String(R.error):null,J=_e(),[Y,oe]=o(null),se=r(e=>{e.alreadyAdopted||v(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),X=r(e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ce=r((e,t)=>{E(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})},[]),Q=r(e=>{let t={};for(let n of e){let e=w.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[w]),le=r(async()=>{O(null);let e=[..._];if(e.length!==0)try{let t=Q(e),{jobId:n}=await J.mutateAsync({addonId:s,integrationId:c,filter:P,childNativeIds:e,...t?{perCandidate:t}:{},...k?{importLocations:A}:{}});oe(n),v(new Set),E(new Map)}catch(e){O(e instanceof Error?e.message:String(e))}},[_,Q,J,s,c,P,k,A]),fe=t(null),me=r(()=>{Y===null||fe.current===Y||(fe.current=Y,z(),h.invalidateQueries({queryKey:[[`integrations`]]}),h.invalidateQueries({queryKey:[[`deviceManager`]]}))},[Y,z,h]),he=r(e=>{F(e),v(new Set),x(new Set),E(new Map),O(null)},[]),ve=_.size,ye=Y!==null&&ve===0&&!J.isPending;return e(u,{children:[k&&e(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[i(b,{checked:A,onChange:e=>j(e.target.checked),className:`accent-primary`}),p(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),e(`div`,{className:`flex-1 min-h-0 flex flex-col gap-2 overflow-hidden`,children:[(W??ae??G)&&ne.length===0&&i(`div`,{className:`rounded-lg border border-danger/30 bg-danger/5 px-4 py-3 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(S,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),e(`div`,{className:`min-w-0`,children:[i(`p`,{className:`text-xs font-medium text-danger`,children:p(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),i(`p`,{className:`text-[11px] text-danger/90 mt-0.5`,children:W??ae??G})]})]})}),N.length>1&&i(vt,{filters:N,activeFilter:P,onSelect:he}),i(`div`,{className:`flex-1 min-h-0`,children:i(Me,{mode:`generic`,items:re.map(e=>e.candidate),pageSize:gt,getKey:e=>e.childNativeId,getSearchText:ft,getFilterType:e=>e.type,filterOptions:ue(f),filterLabel:p(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:R.isLoading||U&&ne.length===0,searchPlaceholder:p(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(W??ae??G)&&ne.length===0?``:p(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:e(Z,{variant:`unstyled`,type:`button`,onClick:V,disabled:U,title:p(`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:[i(g,{className:`h-3.5 w-3.5 ${U?`animate-spin`:``}`}),p(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:p(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-full sm:w-[55%]`,cellClassName:`max-w-0`,cell:e=>i(yt,{candidate:e,depth:ie.get(e.childNativeId)??0,...q.get(e.childNativeId)===void 0?{}:{containerName:q.get(e.childNativeId)},expandable:!I,expanded:y.has(e.childNativeId),onToggleExpand:()=>X(e.childNativeId),adoptedLabel:p(`integrations.adoptAlready`,{defaultValue:`Adopted`}),typeLabel:de(e.type,f).label})},{key:`type`,header:p(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:t=>{let n=de(t.type,f),r=n.icon;return e(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[i(r,{className:`h-3.5 w-3.5 shrink-0`}),n.label]})}},{key:`select`,header:``,headerClassName:`w-10 sm:w-[15%] text-right`,cellClassName:`text-right`,cell:e=>i(`div`,{className:`flex items-center justify-end`,children:i(Z,{variant:`unstyled`,onClick:()=>se(e),disabled:e.alreadyAdopted,"aria-label":_.has(e.childNativeId)?p(`integrations.adoptDevicesModal.deselect`,`Deselect`):p(`integrations.adoptDevicesModal.select`,`Select`),className:`inline-flex h-5 w-5 items-center justify-center rounded border ${_.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:_.has(e.childNativeId)&&i(T,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!I&&y.has(e.childNativeId),renderExpanded:I?void 0:e=>i(bt,{candidate:e,hiddenChildIds:w.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>ce(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:_.has(e.childNativeId)?`bg-primary/5`:``})})]}),D&&i(`div`,{className:`border-t border-danger/30 bg-danger/5 px-3 py-2 shrink-0`,children:e(`div`,{className:`flex items-start gap-2`,children:[i(S,{className:`h-3.5 w-3.5 text-danger mt-0.5 shrink-0`}),i(`p`,{className:`text-[11px] text-danger`,children:D})]})}),Y!==null&&i(lt,{addonId:s,integrationId:c,jobId:Y,onFinished:me}),e(K,{children:[i(Z,{variant:`outline`,size:`sm`,onClick:d,children:p(`integrations.cancel`,{defaultValue:`Cancel`})}),e(Z,{variant:`primary`,size:`sm`,onClick:ye?d:le,disabled:!ye&&(ve===0||J.isPending),children:[J.isPending&&i(m,{className:`h-3.5 w-3.5 animate-spin`}),ye?p(`integrations.close`,{defaultValue:`Close`}):p(`integrations.addSelected`,{defaultValue:`Add selected`}),!ye&&ve>0?` (${ve})`:``]})]})]})}function vt({filters:e,activeFilter:t,onSelect:n}){let{t:r}=$();return i(`div`,{role:`tablist`,"aria-label":r(`integrations.adoptDevicesModal.discoveryGranularity`,`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 i(Z,{variant:`unstyled`,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 yt({candidate:t,depth:n,containerName:r,expandable:a,expanded:o,onToggleExpand:s,adoptedLabel:c,typeLabel:l}){let{t:u}=$(),d=(t.children??[]).length,f=dt(t);return e(`div`,{className:`flex items-center gap-2.5 min-w-0 ${n>0?`pl-5`:``}`,children:[a&&d>0?e(Z,{variant:`unstyled`,type:`button`,onClick:s,"aria-label":o?u(`integrations.adoptDevicesModal.collapse`,`Collapse`):u(`integrations.adoptDevicesModal.expand`,`Expand`),"aria-expanded":o,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:[i(o?M:y,{className:`h-3.5 w-3.5`}),d]}):a?i(`span`,{className:`h-5 w-5 flex-shrink-0`,"aria-hidden":`true`}):null,e(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`truncate text-xs font-medium text-foreground`,"data-testid":`candidate-name`,children:t.name}),f.length>0&&i(`div`,{className:`truncate text-[10px] text-foreground-subtle`,"data-testid":`candidate-subtitle`,children:f}),r!==void 0&&i(`div`,{className:`truncate text-[10px] text-foreground-subtle`,"data-testid":`candidate-container`,children:u(`integrations.adoptDevicesModal.inContainer`,`in {{name}}`,{name:r})}),i(`div`,{className:`truncate text-[10px] text-foreground-subtle sm:hidden`,children:l})]}),t.alreadyAdopted&&i(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:c})]})}function bt({candidate:t,hiddenChildIds:n,onToggleChildHidden:r}){let{t:a}=$(),o=t.children??[];return o.length===0?null:i(`div`,{className:`space-y-1 py-1`,children:o.map(t=>{let o=n.has(t.childNativeId),s=t.capabilities??[];return e(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${o?`opacity-50`:``}`,children:[i(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:t.name}),s.length>0&&i(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:s.join(`, `)}),i(Z,{variant:`unstyled`,onClick:()=>r(t.childNativeId),"aria-label":o?a(`integrations.adoptDevicesModal.showChild`,`Show child`):a(`integrations.adoptDevicesModal.hideChild`,`Hide child`),title:o?a(`integrations.adoptDevicesModal.showAfterAdopt`,`Show after adopt`):a(`integrations.adoptDevicesModal.hideAfterAdopt`,`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:i(o?D:O,{className:`h-3 w-3`})})]},t.childNativeId)})})}function xt(e){let t=e.host;return typeof t==`string`&&t.length>0?t.toLowerCase():null}function St(e){return e===null?[]:[`host:${e}`]}function Ct(e){let t=[],n=new Map,r=(e,r)=>{let i=e.map(e=>n.get(e)).find(e=>e!==void 0),a=i??r();i===void 0&&t.push(a);for(let t of e)a.ids.add(t),n.set(t,a);return a},i=(e,t)=>{e.sources.includes(t)||e.sources.push(t)};for(let t of e.adoption){let e=r([t.childNativeId],()=>({key:t.childNativeId,ids:new Set,name:t.name,address:null,sources:[],hit:null,adoptionId:t.childNativeId,proposalId:null,alreadyAdded:!1,addedName:null,needsParams:[],parentId:t.parentStableId??null}));i(e,`adoption`),e.adoptionId=t.childNativeId,t.alreadyAdopted===!0&&(e.alreadyAdded=!0)}let a=(t,n,a)=>{let o=xt(t.prefilledConfig),s=r([t.stableId,...St(o)],()=>({key:t.stableId,ids:new Set,name:t.suggestedName,address:o,sources:[],hit:null,adoptionId:null,proposalId:null,alreadyAdded:!1,addedName:null,needsParams:[],parentId:null}));i(s,n),(s.hit===null||n===`scan`)&&(s.hit=t),s.name=t.suggestedName,s.address=o??s.address,a!==null&&(s.proposalId=a),s.parentId=t.parentStableId??s.parentId,s.needsParams=t.needsParams??s.needsParams,(t.alreadyOnboarded===!0||t.onboardedDeviceId!==void 0||e.existingStableIds.has(t.stableId))&&(s.alreadyAdded=!0,s.addedName=t.onboardedName??s.addedName)};for(let t of e.scan)a(t,`scan`,null);for(let t of e.proposals)a(t.candidate,`proposal`,t.id);for(let n of t)[...n.ids].some(t=>e.existingStableIds.has(t))&&(n.alreadyAdded=!0);return t.map(e=>{let t=e.parentId===null?void 0:n.get(e.parentId);return{key:e.key,name:e.name,address:e.address,sources:e.sources,hit:e.hit,adoptionId:e.adoptionId,proposalId:e.proposalId,alreadyAdded:e.alreadyAdded,addedName:e.addedName,needsParams:e.needsParams,parentKey:t!==void 0&&t!==e?t.key:null}})}c();var wt=500;function Tt(e){return e instanceof Error?e.message:String(e)}function Et(e,t){let n={};for(let t of e?.sections??[])for(let e of t.fields)`key`in e&&e.key&&`default`in e&&e.default!==void 0&&(n[e.key]=e.default);return{...n,...t}}function Dt({addonId:t,integrationId:a,onClose:s,onSetupIntegration:c,alongsideAdoption:d=!1}){let{t:f}=$(),p=l(),h=Q({addonId:t}).data??null,[g,_]=o({}),v=oe(),y=U({}),b=ge({addonId:t,integrationId:a,page:1,pageSize:wt},{retry:!1}),{data:x}=ie({projection:`slim`}),S=Se(),C=_e(),[T,E]=o(new Set),[D,O]=o(new Set),[ee,k]=o(null),[A,j]=o(null),M=n(()=>{let e=(b.data?.candidates??[]).map(e=>({childNativeId:e.childNativeId,name:e.name,alreadyAdopted:e.alreadyAdopted,parentStableId:e.parentStableId})),n=(y.data?.proposals??[]).filter(e=>e.addonId===t).map(e=>({id:e.id,candidate:e.candidate}));return Ct({adoption:e,scan:v.data?.candidates??[],proposals:n,existingStableIds:new Set((x??[]).map(e=>e.stableId))})},[b.data,y.data,v.data,x,t]),N=e=>e.hit!==null&&(e.needsParams.length>0||e.hit.setupIntegration===!0),F=n(()=>d?M.filter(e=>!e.sources.includes(`adoption`)||N(e)):M,[M,d]),te=d?M.filter(e=>e.sources.includes(`adoption`)&&e.hit!==null&&!F.includes(e)).length:0,I=r(e=>{let t=new Map(F.map(e=>[e.key,e])),n=0,r=e;for(;r?.parentKey!=null&&n<8&&(r=t.get(r.parentKey),r!==void 0);)n+=1;return n},[F]),L=r(()=>{k(null),v.mutate({addonId:t,params:g})},[v,t,g]),R=r(async(e,t)=>{E(t=>new Set(t).add(e)),k(null);try{await t(),O(t=>new Set(t).add(e)),p.invalidateQueries({queryKey:[[`deviceManager`]]}),p.invalidateQueries({queryKey:[[`integrations`]]})}catch(e){k(Tt(e))}finally{E(t=>{let n=new Set(t);return n.delete(e),n})}},[p]),z=r(async(e,n)=>{let r=e.hit;if(r!==null){let i=ze(t,r);if(i!==null){c?.(i),s();return}await R(e.key,async()=>{await S.mutateAsync({addonId:t,integrationId:a,candidate:{...r,prefilledConfig:{...r.prefilledConfig,...n}}}),j(null)});return}if(e.adoptionId!==null){let n=e.adoptionId;await R(e.key,async()=>{await C.mutateAsync({addonId:t,integrationId:a,childNativeIds:[n]})})}},[S,C,t,a,s,c,R]),B=r(e=>{if(e.needsParams.length>0&&e.hit!==null){k(null),j(e);return}z(e)},[z]);if(A!==null&&A.hit!==null)return i(At,{addonId:t,integrationId:a,row:A,found:A.hit.prefilledConfig,busy:T.has(A.key),error:ee,embedded:d,onBack:()=>j(null),onSubmit:e=>void z(A,e)});let V=F.length===0,H=e(u,{children:[i(Le,{}),h&&i(Re,{schema:h,values:g,onChange:_}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[e(`p`,{className:`text-xs text-foreground-subtle`,children:[v.isPending?f(`integrations.addDeviceModal.scanning`,`Scanning the local network…`):F.length>0?f(`integrations.addDeviceModal.found`,{defaultValue_one:`{{count}} device found`,defaultValue_other:`{{count}} devices found`,count:F.length}):``,!v.isPending&&te>0?` · ${f(`integrations.addDeviceModal.alsoAdopted`,{defaultValue_one:`{{count}} also in the adoption list`,defaultValue_other:`{{count}} also in the adoption list`,count:te})}`:``]}),e(Z,{variant:`outline`,size:`sm`,onClick:L,disabled:v.isPending,children:[v.isPending?i(m,{className:`h-3.5 w-3.5 animate-spin`}):i(w,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceModal.scanNow`,`Scan now`)]})]}),v.isError&&i(Ot,{text:f(`integrations.addDeviceModal.scanFailed`,`The scan failed. Try again.`)}),ee!==null&&i(Ot,{text:ee}),V&&!v.isPending&&i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:v.data?f(`integrations.addDeviceModal.nothingFound`,`No devices responded to the scan.`):f(`integrations.addDeviceModal.scanHint`,`Scan the network to find devices to add.`)}),i(`div`,{className:d?`max-h-48 space-y-1.5 overflow-y-auto`:`space-y-1.5`,"data-testid":`network-candidates`,children:F.map(e=>i(kt,{row:e,depth:I(e),busy:T.has(e.key),added:D.has(e.key),onPick:B},e.key))})]});return d?i(`div`,{className:`shrink-0 space-y-3 border-b border-border pb-3`,children:H}):e(u,{children:[i(P,{className:`space-y-3`,children:H}),i(K,{children:i(Z,{variant:`outline`,size:`sm`,onClick:s,children:f(`integrations.close`,`Close`)})})]})}function Ot({text:t}){return e(`div`,{className:`flex items-start gap-2 rounded-lg border border-danger/40 bg-danger/10 px-3 py-2`,children:[i(S,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-danger`}),i(`p`,{className:`text-xs text-danger`,children:t})]})}function kt({row:t,depth:n,busy:r,added:a,onPick:o}){let{t:s}=$(),c=t.alreadyAdded||a,l=t.hit!==null&&ze(``,t.hit)!==null,u=t.hit?.selectable!==!1,d=t.needsParams.length>0;return e(`div`,{className:`flex items-center gap-3 rounded-lg border border-border bg-surface px-3 py-2 ${n>0?`ml-4`:``}`,"data-testid":`network-row-${t.key}`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[i(`p`,{className:`truncate text-xs font-medium text-foreground`,children:t.name}),t.address!==null&&i(`p`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,children:t.address}),c&&t.addedName!==null&&i(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.addedName})]}),c?e(`span`,{className:`flex items-center gap-1 text-[11px] text-foreground-subtle`,children:[i(T,{className:`h-3.5 w-3.5`}),t.alreadyAdded?s(`integrations.scanNetworkModal.alreadyAdded`,`Already added`):s(`integrations.scanNetworkModal.added`,`Added`)]}):u?e(Z,{size:`sm`,variant:l||d?`outline`:`primary`,onClick:()=>o(t),disabled:r,children:[r?i(m,{className:`h-3.5 w-3.5 animate-spin`}):l||d?null:i(A,{className:`h-3.5 w-3.5`}),l?s(`integrations.scanNetworkModal.setUp`,`Set up`):d?s(`integrations.addDeviceModal.enterDetails`,`Enter details`):s(`common.add`,`Add`)]}):null]})}function At({addonId:t,integrationId:n,row:r,found:a,busy:s,error:c,onBack:l,onSubmit:d,embedded:p}){let{t:h}=$(),g=X({addonId:t,integrationId:n}),_=g.data?.deviceType??null,v=q({addonId:t,integrationId:n,type:_??j.Camera},{enabled:g.isSuccess&&_!==null}),y=v.data??null,[b,x]=o(null),S=b??Et(y,a),C=g.error??v.error,w=g.isSuccess&&_===null,T=y!==null,E=T?i(Re,{schema:y,values:S,onChange:x}):C?i(Ot,{text:Tt(C)}):w?i(`p`,{className:`text-xs text-foreground-muted`,children:h(`integrations.addDeviceModal.noCreationType`,`This integration cannot create a device from this candidate.`)}):i(m,{className:`mx-auto h-5 w-5 animate-spin text-primary`}),D=e(u,{children:[e(Z,{variant:`ghost`,size:`sm`,onClick:l,children:[i(f,{className:`h-3.5 w-3.5`}),h(`integrations.addDeviceModal.back`,`Back to the list`)]}),i(`p`,{className:`text-xs font-medium text-foreground`,children:r.name}),E,c!==null&&i(Ot,{text:c})]}),O=e(u,{children:[i(Z,{variant:`outline`,size:`sm`,onClick:l,children:h(`integrations.cancel`,`Cancel`)}),e(Z,{variant:`primary`,size:`sm`,onClick:()=>d(S),disabled:s||!T,children:[s&&i(m,{className:`h-3.5 w-3.5 animate-spin`}),h(`common.add`,`Add`)]})]});return p?e(`div`,{className:`shrink-0 space-y-3 border-b border-border pb-3`,children:[D,i(`div`,{className:`flex justify-end gap-2`,children:O})]}):e(u,{children:[i(P,{className:`space-y-3`,children:D}),i(K,{children:O})]})}c();function jt(e){return e===`manual`?`manual`:e===`pairing`?`pairing`:`network`}function Mt({addonId:t,integrationId:n,kind:r,canScan:a,onClose:s,pairing:c,onSetupIntegration:l}){let{t:d}=$(),f=ot(t,n),p=r===`device-adoption`&&a===null,h=r===`device-adoption`||a===!0,g=f===`available`,[_,v]=o(null),y=_??(c===void 0?h?`network`:`manual`:`pairing`),b=[h,g,c!==void 0].filter(Boolean).length,x=p?i(P,{children:i(m,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):r===`device-adoption`?e(u,{children:[a===!0&&i(Dt,{addonId:t,integrationId:n,onClose:s,alongsideAdoption:!0,...l?{onSetupIntegration:l}:{}}),i(_t,{addonId:t,integrationId:n,onClose:s})]}):i(Dt,{addonId:t,integrationId:n,onClose:s,...l?{onSetupIntegration:l}:{}}),S=i(st,{integrationId:n,addonId:t,onClose:s});return i(be,{open:!0,onOpenChange:e=>{e||s()},children:e(ye,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,className:r===`device-adoption`?`md:h-[85vh]`:void 0,children:[i(ae,{children:i(z,{children:d(`integrations.addDevice`,`Add device`)})}),b>1?e(G,{value:y,onValueChange:e=>v(jt(e)),children:[e(W,{children:[h&&i(le,{value:`network`,children:d(`integrations.addDeviceModal.tabNetwork`,`Found on the network`)}),g&&i(le,{value:`manual`,children:d(`integrations.addDeviceModal.tabManual`,`Enter parameters`)}),c!==void 0&&i(le,{value:`pairing`,children:c.label})]}),h&&i(De,{value:`network`,children:x}),g&&i(De,{value:`manual`,children:S}),c!==void 0&&i(`div`,{role:`tabpanel`,id:`tabpanel-pairing`,hidden:y!==`pairing`,className:`pt-3`,children:c.render({onPaired:()=>v(`network`)})})]}):c!==void 0&&!h&&!g?c.render({onPaired:()=>v(`network`)}):h?x:g?S:f===`loading`?i(P,{children:i(m,{className:`mx-auto h-5 w-5 animate-spin text-primary`})}):i(P,{children:i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:d(`integrations.addDeviceModal.nothingToAdd`,`This integration has no way to add a device from here.`)})})]})})}c();var Nt=`matter`,Pt=[`discovering`,`pase`,`commissioning`,`done`];function Ft(e){return!(typeof e!=`object`||!e||!(`phase`in e)||typeof e.phase!=`string`)}function It(e,t){return e===`code-expired`||t?.includes(`matter-commission:code-expired`)?{key:`integrations.addMatter.failure.expired`,defaultValue:`The pairing code expired. Share the device again and paste the new code.`}:e===`device-not-found`||t?.includes(`matter-commission:device-not-found`)?{key:`integrations.addMatter.failure.notFound`,defaultValue:`No Matter device with that code was found on the network.`}:e===`wrong-code`||t?.includes(`matter-commission:wrong-code`)?{key:`integrations.addMatter.failure.wrongCode`,defaultValue:`The pairing code was rejected.`}:e===`invalid-code`||t?.includes(`invalid pairing code`)?{key:`integrations.addMatter.failure.invalid`,defaultValue:`Enter an 11-digit or 21-digit manual code, or a code that starts with MT:.`}:{key:`integrations.addMatter.failure.unknown`,defaultValue:t??`Commissioning failed.`}}function Lt({onClose:t,onCommissioned:n}){let{t:r}=$(),s=ve({kind:Nt}),[c,l]=o(null),d=Oe(s.data??[],c),f=d.length,p=c??d[0]?.id??null,h=H(),[g,_]=o(``),[v,y]=o({phase:`idle`,failure:null,message:null}),b=v.phase===`discovering`||v.phase===`pase`||v.phase===`commissioning`,x=B({brokerId:p??``,key:`commission`},{enabled:p!==null&&b,refetchInterval:b?400:!1});a(()=>{b&&Ft(x.data)&&x.data.phase!==`idle`&&y({phase:x.data.phase,failure:typeof x.data.failure==`string`?x.data.failure:null,message:typeof x.data.message==`string`?x.data.message:null})},[b,x.data]);let S=()=>{p!==null&&(y({phase:`discovering`,failure:null,message:null}),h.mutate({brokerId:p,target:{action:`commissionNode`},payload:{pairingCode:g.trim()}},{onSuccess:()=>y({phase:`done`,failure:null,message:null}),onError:e=>{let t=e instanceof Error?e.message:`Commissioning failed.`;y({phase:`failed`,failure:t.includes(`matter-commission:`)?t.split(`matter-commission:`)[1]?.split(`:`)[0]??`unknown`:t.includes(`invalid pairing code`)?`invalid-code`:`unknown`,message:t})}}))},C=v.phase===`failed`?It(v.failure,v.message):null,w=C===null?null:r(C.key,{defaultValue:C.defaultValue}),T=(s.isSuccess===!0||s.data!==void 0)&&p===null;return e(u,{children:[e(P,{className:`space-y-4`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`integrations.addMatter.help`,{defaultValue:`In Home Assistant, open the device and choose Share device. Paste the numeric code or the MT: code here. The device stays in Home Assistant.`})}),(T||f>1)&&!b&&v.phase!==`done`&&e(`div`,{className:`space-y-1.5`,children:[i(ke,{children:r(`integrations.addMatter.broker`,{defaultValue:`Matter fabric`})}),i(Ue,{kind:Nt,value:p,onChange:l})]}),!T&&e(`div`,{className:`space-y-1.5`,children:[i(ke,{htmlFor:`matter-pairing-code`,children:r(`integrations.addMatter.code`,{defaultValue:`Pairing code`})}),i(J,{id:`matter-pairing-code`,value:g,autoComplete:`off`,spellCheck:!1,placeholder:`34970112332`,disabled:b||v.phase===`done`,onChange:e=>_(e.target.value)})]}),v.phase!==`idle`&&i(`ol`,{className:`space-y-1`,"aria-label":r(`integrations.addMatter.progress`,{defaultValue:`Commissioning progress`}),children:Pt.map(t=>{let n=v.phase===t;return e(`li`,{className:`text-xs ${n?`text-foreground font-medium`:`text-foreground-subtle`}`,children:[n&&b?i(m,{className:`mr-1 inline h-3 w-3 animate-spin`}):null,r(`integrations.addMatter.phase.${t}`,{defaultValue:t===`discovering`?`Discovering`:t===`pase`?`PASE`:t===`commissioning`?`Commissioning`:`Done`})]},t)})}),w!==null&&i(he,{message:w})]}),e(K,{children:[i(Z,{variant:`ghost`,size:`sm`,onClick:t,children:r(`common.close`,{defaultValue:`Close`})}),v.phase===`done`?i(Z,{size:`sm`,onClick:n,children:r(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}):i(Z,{size:`sm`,disabled:b||T||g.trim().length===0,onClick:S,children:b?r(`integrations.addMatter.working`,{defaultValue:`Adding…`}):r(`integrations.addMatter.submit`,{defaultValue:`Add device`})})]})]})}function Rt({addonId:t,integrationId:n,name:r,onClose:a,onSaved:o}){let{t:c}=$(),l=k(),u=s({queryKey:[`integration-instance-describe`,t],queryFn:()=>l.trpcClient.integrationInstances.describe.query({addonId:t})}),d=s({queryKey:[`integration-instance`,t,n],queryFn:()=>l.trpcClient.integrationInstances.getInstance.query({addonId:t,id:n})});if(u.isSuccess&&d.isSuccess&&d.data!==null)return i(We,{addonId:t,providerName:r,description:u.data,instance:d.data,onClose:a,onSaved:()=>o()});let f=u.isError||d.isError||d.isSuccess&&!d.data;return i(be,{open:!0,onOpenChange:e=>!e&&a(),children:e(ye,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(ae,{children:e(z,{children:[c(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,r]})}),i(P,{children:f?i(`p`,{className:`text-[11px] text-danger`,children:c(`integrations.loadFailed`,{defaultValue:`Could not load this integration.`})}):e(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[i(m,{className:`h-3 w-3 animate-spin`}),c(`integrations.loading`,{defaultValue:`Loading…`})]})})]})})}c();function zt(){let{addonId:e=``}=Je();return i(Vt,{addonId:e})}function Bt(){return e(`div`,{className:`p-4`,children:[i(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),i(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]})}function Vt({addonId:t}){let{t:c}=$(),u=l(),g=Xe(),[_,v]=Ge(),y=k(),[b,x]=o(!1),S=r(e=>{x(!1),g(`/integrations`,{state:{integrationSeed:e}})},[g]),[C,w]=o(!1),[T,D]=o(!1),{data:O}=ce(void 0),A=n(()=>(O??[]).filter(e=>e.addonId===t),[O,t]),j=Ze(_.get(`instance`),A)??``,M=r(e=>{v(t=>{let n=new URLSearchParams(t);return n.set(He,e),n},{replace:!0})},[v]),B=n(()=>A.map(e=>({value:e.id,label:e.name})),[A]),{data:H,isLoading:U}=Ie({id:j},{enabled:!!j}),{data:W,isSuccess:G}=te(),K=n(()=>{let e=H?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[W,H?.addonId,G]),{data:q,isPending:J}=L({}),oe=n(()=>J?null:(q?.providers??[]).some(e=>e.addonId===H?.addonId),[J,q,H?.addonId]),X=K!==null,Q=H?.info?.fixed===!0,le=n(()=>{let e=H?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.brokerKind??null},[W,H?.addonId,G])===`matter`,ue=X?c(`integrations.addDevice`,`Add device`):c(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),de=n(()=>{let e=H?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.mode??null},[W,H?.addonId,G]);a(()=>{_.get(`add`)===`1`&&X&&(x(!0),v(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[_,X,v]);let{data:fe}=s({queryKey:[`integration-instance-form`,H?.addonId,H?.id],enabled:!!H?.addonId&&!!H?.id,queryFn:()=>y.trpcClient.integrationInstances.instanceFormSchema.query({addonId:H?.addonId??``,id:H?.id??``})}),pe=fe!=null&&Array.isArray(fe.sections)&&fe.sections.some(e=>e.fields.length>0),{data:he}=ie({projection:`slim`},{refetchInterval:3e4}),ge=[[`integrations`,`get`],{input:{id:j},type:`query`}],_e={onMutate:async e=>{await u.cancelQueries({queryKey:ge});let t=u.getQueryData(ge);return t!=null&&u.setQueryData(ge,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&u.setQueryData(ge,r.previous)},onSettled:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}},ve=R(_e),Se=V(_e),Ce={isPending:ve.isPending||Se.isPending,mutate:e=>Q&&H?.processState!==`running`?Se.mutate({id:e.id,enabled:e.enabled}):ve.mutate(e)},Ee=H?.switchUnknown===!0,De=Ve(H?.processState),Oe=Ee||!Q&&De,ke={onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]}),g(A.length>1?qe(t):`/integrations`)}},Ae=ne(ke),je=Y(ke),Le=H?.processState===`running`,Re={isPending:Ae.isPending||je.isPending,mutateAsync:async e=>{Le?await Ae.mutateAsync(e):await je.mutateAsync({id:e.id})}},ze=we({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Be=Qe(),Ue=Pe({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),We=se({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ke=n(()=>he??[],[he]),Je=n(()=>F(Ke),[Ke]),Ye=r(e=>Je.get(e)??null,[Je]),et=n(()=>Fe(O),[O]),tt=r(e=>g(`/devices/${String(e)}`),[g]),nt=n(()=>Ke.filter(e=>{let t=et(e);return t.kind===`resolved`&&t.integration.id===j}),[Ke,j,et]),rt=n(()=>O===void 0?null:Ne(nt).length,[O,nt])??`…`;if(U||O===void 0)return i(Bt,{});let it=(W??[]).find(e=>e.addonId===t)?.name??H?.name??t,at=Oe&&De?c(`providerInstances.addonNotRunning`,`{{addon}} is not running: start it first`,{addon:it}):null;return H?e(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[i(re,{items:[{label:c(`integrationDetail.integrations`,`Integrations`),onClick:()=>g(`/integrations`)},{label:it}]}),e(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[e(`div`,{className:`flex items-center gap-3 min-w-0`,children:[i(Ht,{addonId:H.addonId}),e(`div`,{className:`min-w-0`,children:[i(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:it}),e(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[rt,` `,c(`integrations.devices`)]})]})]}),e(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[!Q&&e(Z,{variant:`unstyled`,onClick:()=>{x(!0)},disabled:!X,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:ue,children:[i(ee,{className:`h-3.5 w-3.5`}),ue]}),e(`div`,{className:`flex flex-col items-end gap-1`,children:[e(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Ce.isPending?`opacity-60`:``} ${H.enabled&&!Ee?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:at??c(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[i(me,{checked:H.enabled&&!Ee,onCheckedChange:e=>Ce.mutate({id:j,addonId:H?.addonId,enabled:e}),disabled:Ce.isPending||Oe,"aria-label":Ee?c(`integrationDetail.switchUnknown`,`Unknown`):H.enabled?c(`integrationDetail.disableIntegration`,`Disable integration`):c(`integrationDetail.enableIntegration`,`Enable integration`)}),i(`span`,{className:`text-[11px] font-medium ${H.enabled&&!Ee?`text-success`:`text-foreground-subtle`}`,children:Ee?c(`integrationDetail.switchUnknown`,`Unknown`):H.enabled?c(`integrationDetail.enabled`,`Enabled`):c(`integrationDetail.disabled`,`Disabled`)}),Ce.isPending&&i(m,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),at!==null&&i(`span`,{className:`text-[11px] text-foreground-subtle`,children:at})]}),de!==`standalone`&&(pe||K===`device-adoption`)&&e(Z,{variant:`unstyled`,onClick:()=>w(!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:[i(p,{className:`h-3 w-3`}),c(`integrations.config`)]}),e(Z,{variant:`unstyled`,onClick:()=>D(!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:c(`integrations.logs`,{defaultValue:`View logs`}),children:[i(d,{className:`h-3 w-3`}),c(`integrations.logs`,{defaultValue:`Logs`})]}),i(I,{label:c(`integrationDetail.restart`,`Restart`),icon:h,title:c(`integrationDetail.restart2`,`Restart "{{name}}"?`,{name:H.name}),description:c(`integrationDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device backed by it ({{topLevelCountLabel}} active). Streams will reconnect automatically.`,{topLevelCountLabel:rt}),confirmLabel:c(`integrationDetail.restart`,`Restart`),triggerVariant:`outline`,confirmVariant:`danger`,disabled:ze.isPending,action:()=>ze.mutateAsync({addonId:H.addonId})}),!Q&&j&&i(I,{label:c(`integrations.delete`,{defaultValue:`Delete`}),icon:E,title:c(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:c(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:H.name,count:rt}),confirmLabel:c(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Re.isPending,action:()=>Re.mutateAsync({addonId:t,id:j})})]})]}),A.length>1&&i(`div`,{className:`max-w-sm`,children:i(Te,{mode:`single`,singleDisplay:`field`,label:c(`integrationDetail.instances`,`Integration`),options:B,value:j,onChange:M,testId:`integration-instance-picker`,optionTestIdPrefix:`integration-instance`})}),i(Me,{context:`integration-detail`,devices:Ke,trpc:y.trpcClient,integrationOf:et,forceIntegrationId:j,urlScope:`root`,lsKey:`integration-detail:${H.addonId}`,resolveIntegrationIcon:$e,resolveParent:Ye,onNavigate:tt,rowOperation:Be.rowOperation,batchActions:{remove:Be.remove,disable:Ue.mutate,enable:We.mutate},...Q?{}:{onDeleteDevice:e=>Be.remove({deviceId:e.id})}}),b&&j&&K!==null&&i(Mt,{addonId:H.addonId,integrationId:j,kind:K,canScan:oe,onSetupIntegration:S,...le?{pairing:{label:c(`integrations.addMatter.tab`,`Pairing code`),render:({onPaired:e})=>i(Lt,{onClose:()=>x(!1),onCommissioned:e})}}:{},onClose:()=>x(!1)}),C&&j&&i(Rt,{addonId:H.addonId,integrationId:j,name:H.name,onClose:()=>w(!1),onSaved:()=>{u.invalidateQueries()}}),T&&i(be,{open:!0,onOpenChange:e=>!e&&D(!1),children:e(ye,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[i(ae,{className:`mb-0`,children:e(z,{className:`flex items-center gap-2 min-w-0`,children:[i(d,{className:`h-4 w-4 text-primary shrink-0`}),i(`span`,{className:`truncate`,children:H.name}),e(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[H.addonId,j?` · ${j}`:``]})]})}),i(P,{className:`min-h-0 overflow-hidden p-0`,children:i(xe,{addonId:H.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})})]}):e(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[i(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:i(N,{className:`h-6 w-6 text-foreground-subtle`})}),e(`div`,{className:`space-y-1 max-w-sm`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:c(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:c(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:t})})]}),e(Z,{variant:`unstyled`,onClick:()=>g(`/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:[i(f,{className:`h-3 w-3`}),c(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function Ht({addonId:e}){let t=Ye(e),[n,r]=o(!1);return!t||n?null:i(`img`,{src:t,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:()=>r(!0)})}export{zt as IntegrationDetailPage};
@@ -1,3 +0,0 @@
1
- import{C as e,K as t,S as n,V as r,Y as i,et as a,o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Jn as c,O as l,Oa as u,Qi as d,Rr as f,Ua as p,V as m,ct as h,dt as g,en as _,k as v,kr as y,lr as b,rr as x,wt as S,z as C}from"./player-overlays-VrMHBBfa.js";import{Pn as w,gs as T,ms as E}from"./client-CBrsD14Q.js";import{t as D}from"./chevron-down-CBb-F8DT.js";import{$f as O,$s as k,A,Ai as j,Ar as M,Ca as N,Da as P,Fi as F,Js as ee,Ks as te,Ls as ne,Ni as I,Ns as re,Pi as L,Qf as R,Qs as ie,Rs as ae,Tn as z,Vs as oe,Wf as B,Xi as V,Ys as se,as as ce,ba as H,br as le,cs as ue,ec as de,ep as U,is as fe,ji as pe,ki as W,ma as G,ni as me,oa as he,oc as ge,qs as _e,ri as ve,rs as ye,tc as be,vp as xe,xa as K,xr as Se,zs as Ce}from"./src-bJ4Hy4Cl.js";import{t as q}from"./i18n-BFxrpjSx.js";import{t as J}from"./useTranslation-BJr-n0es.js";import{h as we,hi as Te,pi as Ee,ui as Y}from"./index-1bBrNxAK.js";import{t as De}from"./AdminSectionedPage-vnoSnjIu.js";import{c as X,n as Oe,r as ke}from"./linked-devices-model-BbPIMVq4.js";a();function Z(e){return{id:e.id,name:e.name,type:e.type,stableId:e.stableId??``,parentDeviceId:e.parentDeviceId,location:e.location,...e.role!==void 0&&e.role!==null?{role:e.role}:{},...e.primaryChildEntityId!==void 0&&e.primaryChildEntityId!==null?{primaryChildEntityId:e.primaryChildEntityId}:{},...e.primaryChildPreference!==void 0&&e.primaryChildPreference!==null?{primaryChildPreference:e.primaryChildPreference}:{}}}function Q(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function Ae(e,t){let n=Q(t);return n===null?[]:e.filter(e=>Q(e.location)===n)}function je(e,t){let n=Ae(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function Me(e,t){let n=Q(e.location);return n===null||new Set(t.map(e=>Q(e))).has(n)?null:e.location?.trim()??null}function Ne(e,t){let n=Q(e.location);return n!==null&&t.has(n)}function Pe(e,t){let n=new Set(t.map(e=>Q(e))),r=new Set(e.filter(e=>Ne(e,n)).map(e=>e.id));return e.filter(e=>!(Ne(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function Fe(e,t){return Pe(e,t).filter(e=>e.parentDeviceId===null)}function Ie(e,t){let n=new Map;for(let t of e){if(t.parentDeviceId===null)continue;let e=n.get(t.parentDeviceId);e?e.push(t):n.set(t.parentDeviceId,[t])}let r=[],i=new Set([t]),a=[t];for(;a.length>0;){let e=[];for(let t of a)for(let a of n.get(t)??[])i.has(a.id)||(i.add(a.id),r.push(a),e.push(a.id));a=e}return r}function Le(e,t){return Ie(e,t).length}function Re(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function ze(e,t){return t.map(t=>({name:t,members:je(e,t)}))}function $({type:e,role:t,className:r}){return n(xe(e,t),{"aria-hidden":`true`,className:r??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function Be({device:t}){let r=K(Z(t),`compact`);if(t.online)return n(`span`,{"aria-hidden":`true`,className:`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-success`,"data-status":`online`});let i=q.t(`common.offline`);return e(`span`,{className:`flex items-center gap-1.5`,children:[n(`span`,{className:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,"data-status":`offline`,role:`img`,"aria-label":q.t(`locations.deviceGlyphs.aria`,{name:r,state:i}),title:i}),n(`span`,{className:`text-xs text-foreground-muted`,children:i})]})}function Ve({open:t,title:a,items:o,listState:s,lockedIds:c,lockedNote:l,suggestions:u=null,busy:d=!1,onConfirm:f,onClose:p}){let{t:m}=J(),[h,g]=i([]);r(()=>{t||g([])},[t]);let _=new Map(o.map(e=>[e.id,e.name])),v=(u?.ids??[]).filter(e=>_.has(e)&&!c.includes(e)),y=e=>g(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]);return n(W,{open:t,onOpenChange:e=>e?void 0:p(),children:e(pe,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":a,children:[n(L,{children:n(F,{children:a})}),e(j,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[t&&u!==null&&v.length>0&&e(`section`,{"aria-label":u.heading,className:`flex flex-col gap-1`,children:[n(`h3`,{className:`text-[10px] sm:text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:u.heading}),n(`div`,{className:`flex flex-wrap gap-1`,children:v.map(e=>n(`button`,{type:`button`,"aria-pressed":h.includes(e),className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${h.includes(e)?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`}`,onClick:()=>y(e),children:_.get(e)},e))})]}),t&&n(A,{devices:o,listState:s,value:h,onChange:e=>g(e),noun:`device`,emptyLabel:m(`locations.addDialog.nonePicked`),showAll:!0,lockedIds:c,lockedNote:l,testId:`quick-add-picker`})]}),e(I,{children:[n(B,{variant:`ghost`,onClick:p,children:m(`locations.addDialog.cancel`)}),n(B,{disabled:h.length===0||d,onClick:()=>f(h),children:m(`locations.addDialog.confirm`,{count:h.length})})]})]})})}a();function He({room:e,cameras:r,fleet:i}){let{t:a}=J(),o=t(()=>new Map(i.map(e=>[e.id,e])),[i]);return e===null?n(`p`,{className:`text-xs text-foreground-subtle`,children:a(`locations.links.noRoom`)}):n(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-section`,children:r.length===0?n(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`camera-links-empty`,children:a(`locations.links.noCameras`,{room:e})}):r.map(e=>n(We,{camera:e,byId:o},e.id))})}function Ue(e){return{id:e.deviceId,name:e.name,type:e.type,location:e.location}}function We({camera:t,byId:r}){let{t:a}=J(),s=K(Z(t),`full`),c=o(),u=Ee(),[d,p]=i(!1),[m,h]=i(null),g=fe({deviceId:t.id}),_=ke({status:g.status,data:g.data,error:g.error===null||g.error===void 0?null:g.error}),y=ce(),b=_.kind===`present`?_:null,x=ye({deviceId:t.id,slotRef:b?.slot.slotRef??``},{enabled:d&&b!==null}),S=b===null?[]:Oe(b.slot,b.value),C=S.map(e=>e.deviceId),w=(x.data?.candidates??[]).map(Ue),T=new Set(w.map(e=>e.id)),E=C.filter(e=>!T.has(e)).map(e=>{let t=r.get(e);return{id:e,name:t?.name??`#${String(e)}`,...t===void 0?{}:{type:t.type,location:t.location}}}),D=[...w,...E],O=(x.data?.candidates??[]).filter(e=>e.suggested).map(e=>e.deviceId),k=async e=>{if(b!==null){h(null);try{await y.mutateAsync({deviceId:t.id,slotRef:b.slot.slotRef,value:X(b.value,e)}),await g.refetch(),await c.invalidateQueries({queryKey:[[`deviceManager`]]}),p(!1)}catch(e){h(e instanceof Error?e.message:String(e))}}},A=[{key:`device`,header:a(`locations.columns.device`),notSortableReason:a(`locations.columns.noSort`),render:t=>{let i=r.get(t.deviceId),o=t.name??i?.name??`#${String(t.deviceId)}`;return e(`span`,{className:`flex items-center gap-1.5`,children:[i!==void 0&&n($,{type:i.type,role:i.role}),n(Y,{to:`/devices/${String(t.deviceId)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:i===void 0?o:n(V,{device:Z(i),form:`compact`})}),t.implied&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:a(`locations.links.implied`)})]})}},{key:`type`,header:a(`locations.columns.type`),notSortableReason:a(`locations.columns.noSort`),render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:r.get(e.deviceId)?.type??`—`})},{key:`status`,header:a(`locations.columns.status`),notSortableReason:a(`locations.columns.noSort`),render:e=>{let t=r.get(e.deviceId);return t===void 0?n(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):n(Be,{device:t})}}];return e(`section`,{className:`min-w-0 ${l}`,"data-testid":`camera-links-${String(t.id)}`,children:[e(`header`,{className:`${v} flex min-h-9 items-center gap-1.5`,children:[n($,{type:t.type,role:t.role}),n(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:n(V,{device:Z(t),form:`full`})}),e(B,{variant:`ghost`,size:`sm`,onClick:()=>u(we(t.id)),children:[n(f,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),a(`locations.links.edit`)]}),n(B,{variant:`outline`,size:`sm`,disabled:b===null,onClick:()=>p(!0),"aria-label":a(`locations.links.addNamed`,{camera:s}),children:a(`locations.room.add`)})]}),_.kind===`pending`&&n(`p`,{role:`status`,className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.loading`)}),_.kind===`unknown`&&n(`p`,{role:`alert`,className:`px-3 py-3 text-xs text-warning sm:px-4`,children:a(`locations.links.unreadable`,{reason:_.reason})}),_.kind===`absent`&&n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.unsupported`)}),m!==null&&n(`p`,{role:`alert`,className:`px-3 pt-2 text-xs text-danger break-words sm:px-4`,children:m}),b!==null&&(S.length===0?n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:a(`locations.links.none`)}):n(M,{columns:A,rows:S,rowKey:e=>String(e.deviceId),bordered:!1,minWidthPx:360})),n(Ve,{open:d,title:a(`locations.links.pickTitle`,{camera:s}),items:D,listState:x.status===`error`?`failed`:x.data===void 0?`pending`:`answered`,lockedIds:C,lockedNote:a(`locations.links.alreadyLinked`),suggestions:t.location===null?null:{heading:a(`locations.links.suggested`,{room:t.location}),ids:O},busy:y.isPending,onConfirm:e=>void k(e),onClose:()=>p(!1)})]})}a();function Ge({name:t,description:a,busy:o,onSave:s}){let{t:c}=J(),[l,u]=i(a??``);return r(()=>{u(a??``)},[a]),e(`div`,{className:`border-t border-border px-3 py-2 sm:px-4`,children:[n(ve,{htmlFor:`location-description-${t}`,className:`block`,children:c(`locations.locationDescriptionField.whatIsThere`,`What is there`)}),n(me,{id:`location-description-${t}`,value:l,onChange:e=>u(e.target.value),onBlur:()=>{let e=l.trim();e!==(a??``)&&s(e.length===0?null:e)},disabled:o,rows:2,maxLength:400,placeholder:c(`locations.locationDescriptionField.surfacesBoundariesWhatIsNormally`,`Surfaces, boundaries, what is normally parked or stored here.`),className:`mt-1 w-full resize-y rounded-md border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-inset focus:ring-primary disabled:cursor-not-allowed disabled:opacity-50`}),n(`p`,{className:`mt-1 ${C}`,children:c(`locations.locationDescriptionField.givenToTheAiWith`,`Given to the AI with the pictures, so it knows what it is looking at. Describe the PLACE, not what happens in it — events change, the ground does not.`)})]})}function Ke(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0||n.description.length===0?null:n.description}var qe=` none`;function Je({name:t,zones:r,zoneKey:i,busy:a,onChange:o}){let{t:s}=J();if(r.length===0)return null;let c=[{value:qe,label:s(`locations.locationZoneField.none`,`— none —`)},...r.map(e=>({value:e.zoneKey,label:e.label}))];return e(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:[n(ve,{htmlFor:`location-zone-${t}`,children:s(`locations.locationZoneField.zone`,`Zone`)}),n(g,{id:`location-zone-${t}`,value:i??qe,disabled:a,onChange:e=>{let t=e.target.value;if(t===qe){o(null);return}let n=r.find(e=>e.zoneKey===t);n!==void 0&&o(n.label)},options:c})]})}function Ye(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}function Xe({name:e,icon:t,busy:r,onPick:i}){return n(U,{value:t,onPick:i,fallbackGlyph:y,clearGlyph:u,labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`},disabled:r})}function Ze(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:T(n.icon)??`map-pin`}function Qe(e){return`${e.kind}:${String(e.device.id)}`}function $e(e,t,n){return e.flatMap(e=>{let r=Re(t,e.id),i=n.has(e.id),a={kind:`member`,device:e,accessories:r,open:i};return!i||r.length===0?[a]:[a,...r.map(t=>({kind:`accessory`,device:t,parent:e}))]})}a();function et({name:r,members:a,devices:o,busy:u,icon:d,description:f,onRename:p,onDelete:m,onRebuildLinks:h,onAddDevices:g,onPickIcon:y,onSaveDescription:x,zones:C,zoneKey:w,onChangeZone:T}){let{t:E}=J(),[D,k]=i(!1),[A,j]=i(r),N=le(a,t(()=>({searchText:e=>[e.name,...Re(o,e.id).map(e=>e.name)],facetValue:e=>e.type}),[o])),[P,F]=i(()=>new Set),ee=e=>F(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),te=t(()=>$e(N.rows,o,P),[N.rows,o,P]),ne=[{key:`name`,header:E(`locations.columns.device`),notSortableReason:E(`locations.columns.noSort`),render:e=>e.kind===`member`?n(tt,{row:e,onToggle:()=>ee(e.device.id)}):n(nt,{row:e})},{key:`type`,header:E(`locations.columns.type`),notSortableReason:E(`locations.columns.noSort`),render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:e.device.type})},{key:`status`,header:E(`locations.columns.status`),notSortableReason:E(`locations.columns.noSort`),render:e=>n(Be,{device:e.device})}],I=()=>{j(r),k(!1)},re=async()=>{let e=A.trim();if(e.length===0||e===r){I();return}await p(e),k(!1)},L=[{id:`rename`,label:E(`locations.locationCard.rename`,`Rename`),icon:b,disabled:u,onClick:()=>{j(r),k(!0)}},{id:`rebuild-links`,label:E(`locations.locationCard.rebuildLinkedDevices`,`Rebuild linked devices`),icon:c,separatorBefore:!0,disabled:u,onClick:()=>void h()},{id:`delete`,label:E(`common.delete`,`Delete`),icon:_,danger:!0,separatorBefore:!0,disabled:u,onClick:()=>void m()}];return e(`section`,{className:`min-w-0 ${l}`,children:[e(`header`,{className:`${v} flex min-h-9 items-center gap-1.5`,children:[n(Xe,{name:r,icon:d,busy:u,onPick:y}),D?e(s,{children:[n(R,{value:A,onChange:e=>j(e.target.value),onKeyDown:e=>{e.key===`Enter`&&re(),e.key===`Escape`&&I()},"aria-label":E(`locations.locationCard.rename2`,`Rename {{name}}`,{name:r}),className:`min-w-0 flex-1`,autoFocus:!0}),n(B,{type:`button`,size:`sm`,onClick:()=>void re(),children:E(`common.save`,`Save`)}),n(O,{type:`button`,variant:`ghost`,icon:S,onClick:I,"aria-label":E(`locations.locationCard.cancelRename`,`Cancel rename`)})]}):e(s,{children:[n(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:r}),n(B,{type:`button`,variant:`outline`,size:`sm`,disabled:u,onClick:g,"aria-label":E(`locations.room.addTo`,{room:r}),children:E(`locations.room.add`)}),n(z,{items:L,title:E(`locations.locationCard.actionsFor`,`Actions for {{name}}`,{name:r}),triggerClassName:`p-1`})]})]}),n(Je,{name:r,zones:C,zoneKey:w,busy:u,onChange:T}),n(Ge,{name:r,description:f,busy:u,onSave:x}),a.length>0&&n(`div`,{className:`border-b border-border px-3 py-1.5 sm:px-4 sm:py-2`,children:n(Se,{state:N.state,facets:N.facets,labels:{searchPlaceholder:E(`locations.filter.searchPlaceholder`),searchLabel:E(`locations.room.searchLabel`,{room:r}),facetsLabel:E(`locations.filter.typesLabel`),clearLabel:E(`locations.filter.clear`)},onSearch:N.setSearch,onToggleFacet:N.toggleFacet,onClear:N.clear})}),a.length===0?n(`p`,{className:`px-3 py-3 text-xs text-foreground-subtle sm:px-4`,children:E(`locations.locationCard.nothingHereYetAssignA`,`Nothing here yet — assign a device from the table below.`)}):n(M,{columns:ne,rows:te,rowKey:Qe,bordered:!1,minWidthPx:360,emptyMessage:E(`locations.filter.noMatch`)})]})}function tt({row:t,onToggle:r}){let{t:i}=J(),{device:a,accessories:o,open:s}=t,c=K(Z(a),`compact`),l=s?D:d;return e(`span`,{className:`flex items-center gap-1.5`,children:[o.length>0?e(B,{type:`button`,variant:`ghost`,onClick:r,"aria-expanded":s,"aria-label":i(s?`locations.locationCard.collapseAccessories`:`locations.locationCard.expandAccessories`,{count:o.length,name:c}),className:`h-auto shrink-0 gap-0.5 p-0.5 text-foreground-subtle hover:text-foreground`,children:[n(l,{className:`h-3 w-3`}),n(`span`,{className:`text-[10px] tabular-nums`,children:o.length})]}):n(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),n($,{type:a.type,role:a.role}),n(Y,{to:`/devices/${String(a.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:n(V,{device:Z(a),form:`compact`})})]})}function nt({row:t}){let{device:r,parent:i}=t;return e(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[n(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),n($,{type:r.type,role:r.role,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),n(Y,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground-muted hover:underline`,children:n(V,{device:Z(r),form:`nested`,parent:Z(i)})})]})}a();function rt({zones:e,busy:t,onRename:r,onDelete:a,onPickIcon:o}){let{t:s}=J(),[c,l]=i(null),[u,d]=i(``),f=async e=>{let t=u.trim();l(null),!(t.length===0||t===e)&&await r(e,t)};return n(M,{columns:[{key:`icon`,header:s(`locations.siteZonesPanel.icon`,`Icon`),width:`w-12`,notSortableReason:`An icon has no order`,render:e=>n(Xe,{name:e.label,icon:e.icon,busy:t,onPick:t=>o(e.label,t)})},{key:`name`,header:s(`locations.siteZonesPanel.zone`,`Zone`),sortValue:e=>e.label.toLowerCase(),render:e=>c===e.label?n(R,{value:u,onChange:e=>d(e.target.value),onKeyDown:t=>{t.key===`Enter`&&f(e.label),t.key===`Escape`&&l(null)},onBlur:()=>void f(e.label),"aria-label":s(`locations.siteZonesPanel.rename`,`Rename {{label}}`,{label:e.label}),autoFocus:!0}):n(B,{type:`button`,variant:`ghost`,size:`sm`,className:`px-0`,onClick:()=>{d(e.label),l(e.label)},disabled:t,title:s(`locations.siteZonesPanel.renameTheZone`,`Rename the zone`),children:e.label})},{key:`rooms`,header:s(`locations.siteZonesPanel.rooms`,`Rooms`),align:`right`,sortValue:e=>e.locationKeys.length,render:e=>n(`span`,{className:`tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?s(`common.empty`):s(`common.rooms`,{count:e.locationKeys.length})})},{key:`actions`,header:s(`locations.siteZonesPanel.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order`,render:e=>n(B,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void a(e.label),disabled:t,"aria-label":s(`locations.siteZonesPanel.delete`,`Delete {{label}}`,{label:e.label}),title:s(`locations.siteZonesPanel.deleteTheZoneTheRooms`,`Delete the zone — the rooms in it are kept`),children:n(_,{className:`h-3.5 w-3.5`})})}],rows:e,rowKey:e=>e.zoneKey,emptyMessage:s(`locations.siteZonesPanel.noZonesYetAZone`,`No zones yet. A zone groups rooms — “Night zone” for the bedrooms — and shows up before them in the app’s camera filter.`)})}a();function it({busy:t,onCreate:r}){let{t:a}=J(),[o,s]=i(!1),[c,l]=i(``),u=()=>{l(``),s(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await r(e),u())};return o?e(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[n(R,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:a(`locations.newLocationButton.frontDoorHallKitchen`,`Front door, Hall, Kitchen…`),"aria-label":a(`locations.newLocationButton.newLocationName`,`New location name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),e(B,{size:`sm`,type:`submit`,disabled:c.trim().length===0||t,children:[n(x,{className:`h-3.5 w-3.5`}),a(`common.add`,`Add`)]}),n(B,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":a(`locations.newLocationButton.cancelNewLocation`,`Cancel new location`),children:n(S,{className:`h-3.5 w-3.5`})})]}):e(B,{size:`sm`,type:`button`,onClick:()=>s(!0),"data-testid":`new-location-button`,children:[n(x,{className:`h-3.5 w-3.5`}),a(`locations.newLocationButton.newLocation`,`New location`)]})}a();function at({busy:t,onCreate:r}){let{t:a}=J(),[o,s]=i(!1),[c,l]=i(``),u=()=>{l(``),s(!1)},d=async()=>{let e=c.trim();e.length!==0&&(await r(e),u())};return o?e(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),d()},children:[n(R,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&u()},placeholder:a(`locations.newZoneButton.zonaGiornoZonaNotte`,`Zona giorno, Night zone…`),"aria-label":a(`locations.newZoneButton.newZoneName`,`New zone name`),className:`min-w-[12rem] flex-1`,autoFocus:!0}),e(B,{size:`sm`,type:`submit`,disabled:c.trim().length===0||t,children:[n(x,{className:`h-3.5 w-3.5`}),a(`common.add`,`Add`)]}),n(B,{size:`sm`,variant:`ghost`,type:`button`,onClick:u,"aria-label":a(`locations.newZoneButton.cancelNewZone`,`Cancel new zone`),children:n(S,{className:`h-3.5 w-3.5`})})]}):e(B,{size:`sm`,type:`button`,onClick:()=>s(!0),"data-testid":`new-zone-button`,children:[n(x,{className:`h-3.5 w-3.5`}),a(`locations.newZoneButton.newZone`,`New zone`)]})}a();function ot(e,t,n,r){let i=e.map(e=>({value:e.name,label:`${e.name} · ${String(e.count)}`}));return t===void 0?i:[...i,{value:n,label:`${r} · ${String(t)}`}]}function st({rooms:e,unassignedCount:r,value:i,unassignedValue:a,onChange:o}){let{t:s}=J(),c=t(()=>ot(e,r,a,s(`locations.roomPicker.unassigned`)),[e,r,a,s]);return n(`div`,{className:`max-w-sm`,"data-testid":`room-select`,children:n(he,{mode:`single`,singleDisplay:`field`,label:s(`locations.roomPicker.label`),placeholder:s(`locations.roomPicker.placeholder`),options:c,value:i,onChange:o,searchable:!0,testId:`room-select-control`,optionTestIdPrefix:`room-option`})})}a();var ct={searchText:e=>[e.name],facetValue:e=>e.type};function lt({rows:r,fleet:a,locations:o,busy:s,emptyMessage:c,onAssign:l}){let{t:u}=J(),d=P(),f=N(),h=e=>d===null?e.name:H(Z(e),`compact`,d,f),[_,v]=i([]),[y,b]=i(``),x=le(r,ct),S=x.rows,w=t(()=>S.map(e=>e.id),[S]),T=t(()=>_.filter(e=>w.includes(e)),[_,w]),E=S.length>0&&T.length===S.length,D=t(()=>{let e=new Map;for(let t of r)e.set(t.id,Le(a,t.id));return e},[r,a]),O=T.reduce((e,t)=>e+(D.get(t)??0),0),k=e=>v(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),A=()=>v(E?[]:w),j=()=>{y.length===0||T.length===0||(l(T,y),v([]),b(``))},F=o.map(e=>({value:e,label:e})),ee=[{key:`select`,width:`w-8`,headerRender:()=>n(p,{checked:E,onChange:A,"aria-label":E?u(`locations.unassignedTable.clearSelection`,`Clear selection`):u(`locations.unassignedTable.selectAllUnassignedDevices`,`Select all unassigned devices`)}),render:e=>n(p,{checked:T.includes(e.id),onChange:()=>k(e.id),"aria-label":u(`locations.unassignedTable.select`,`Select {{name}}`,{name:h(e)})})},{key:`name`,header:u(`locations.unassignedTable.device`,`Device`),sortValue:e=>e.name.toLowerCase(),render:t=>{let r=Me(t,o);return e(`span`,{className:`flex items-center gap-1.5`,children:[n($,{type:t.type,role:t.role}),n(Y,{to:`/devices/${String(t.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:n(V,{device:Z(t),form:`compact`})}),r!==null&&n(G,{variant:`warning`,children:u(`locations.unassignedTable.unknownRoom`,{room:r})})]})}},{key:`type`,header:u(`locations.unassignedTable.type`,`Type`),sortValue:e=>e.type,render:e=>n(`span`,{className:`text-xs text-foreground-muted`,children:e.type})},{key:`status`,header:u(`locations.unassignedTable.status`,`Status`),sortValue:e=>+!!e.online,render:e=>n(Be,{device:e})},{key:`followers`,header:u(`locations.unassignedTable.accessoriesInTowCount`,`Accessories in tow`),align:`right`,sortValue:e=>D.get(e.id)??0,render:e=>n(`span`,{className:`tabular-nums text-xs text-foreground-muted`,children:D.get(e.id)??0})},{key:`assign`,header:u(`locations.unassignedTable.assignTo`,`Assign to`),align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>n(g,{"aria-label":u(`locations.unassignedTable.locationFor`,`Location for {{name}}`,{name:h(e)}),value:``,disabled:s||o.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&l([e.id],n)},className:`max-w-[11rem]`,options:[{value:``,label:`—`},...F]})}];return e(`section`,{className:`space-y-2`,children:[e(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[n(`h2`,{className:m,children:u(`locations.unassignedTable.notInARoom`,`Not in a room`)}),n(`p`,{className:C,children:u(`locations.unassignedTable.topLevelDevicesOnlyAccessories`,`Top-level devices only — accessories move with their parent.`)})]}),r.length>0&&n(Se,{state:x.state,facets:x.facets,labels:{searchPlaceholder:u(`locations.filter.searchPlaceholder`),searchLabel:u(`locations.unassigned.searchLabel`),facetsLabel:u(`locations.filter.typesLabel`),clearLabel:u(`locations.filter.clear`)},onSearch:x.setSearch,onToggleFacet:x.toggleFacet,onClear:x.clear}),T.length>0&&e(`div`,{role:`group`,"aria-label":u(`locations.unassignedTable.bulkAssignment`,`Bulk assignment`),className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[e(`span`,{className:`text-xs text-foreground`,children:[u(`locations.unassignedTable.selected`,{count:T.length}),O>0&&` · ${u(`locations.unassignedTable.accessoriesInTowCount`,{count:O})}`]}),n(g,{"aria-label":u(`locations.unassignedTable.assignSelectedDevicesTo`,`Assign selected devices to`),value:y,onChange:e=>b(e.target.value),className:`w-auto min-w-[10rem]`,options:[{value:``,label:u(`locations.unassignedTable.assignTo2`,`Assign to…`)},...F]}),n(B,{type:`button`,size:`sm`,onClick:j,disabled:s||y.length===0,children:u(`locations.unassignedTable.assign`,`Assign`)}),n(B,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>v([]),children:u(`locations.unassignedTable.clear`,`Clear`)})]}),n(M,{columns:ee,rows:S,rowKey:e=>e.id,minWidthPx:720,emptyMessage:x.active?u(`locations.filter.noMatch`):c})]})}function ut(e){return{id:e.id,parentDeviceId:e.parentDeviceId,location:e.location,type:e.type,stableId:e.stableId??``,...e.primaryChildEntityId===void 0?{}:{primaryChildEntityId:e.primaryChildEntityId},...e.primaryChildPreference===void 0?{}:{primaryChildPreference:e.primaryChildPreference},...e.role!==void 0&&e.role!==null?{role:e.role}:{},name:e.name}}function dt(e,t){let n=t.map(ut),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:w({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var ft=`device-manager:linked-devices`;function pt(e){return{deviceId:e.deviceId,slotRef:ft,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}a();var mt=`__unassigned__`;function ht(){let{t:r}=J(),a=o(),s=h(),{data:c,isLoading:l}=Ce(),{data:u}=ae(),{data:d}=ne(),{data:f}=oe(),{data:p,isLoading:m}=re({projection:`slim`}),g=()=>{a.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),a.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},_=ue({onSuccess:g}),v=te({onSuccess:g}),b=ie({onSuccess:g}),x=ee({onSuccess:g}),S=de({onSuccess:g}),C=k({onSuccess:g}),w=ge({onSuccess:g}),T=_e({onSuccess:g}),D=se({onSuccess:g}),O=be({onSuccess:g}),A=ce(),j=t(()=>(p??[]).map(e=>({id:e.id,name:e.name,location:e.location??null,type:String(e.type),isCamera:e.isCamera,parentDeviceId:e.parentDeviceId,online:e.online,role:e.role??null,stableId:e.stableId,primaryChildEntityId:e.primaryChildEntityId??null,primaryChildPreference:e.primaryChildPreference??null})),[p]),M=c??[],N=t(()=>ze(j,M),[j,M]),[P,F]=Te(),I=P.get(`tab`),L=I===`zones`||I===`camera-links`?I:`locations`,R=P.get(`room`),z=t(()=>Fe(j,M),[j,M]),B=R===mt,V=B?null:R!==null&&N.some(e=>e.name===R)?R:N[0]?.name??null,H=V===null?null:N.find(e=>e.name===V)??null,le=B?mt:V??`__unassigned__`,U=V??N[0]?.name??null,fe=t(()=>N.map(e=>({name:e.name,count:e.members.length})),[N]),pe=e=>{F(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},W=l||m,G=b.isPending||v.isPending||_.isPending||S.isPending,me=async e=>{await _.mutateAsync({name:e})},he=async(e,t)=>{let n=t.trim();n.length===0||n===e||await x.mutateAsync({from:e,to:n})},ve=async e=>{let t=dt(e,j);if(t.entries.length===0){await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.noCameraIsAssignedTo`,`No camera is assigned to “{{room}}”.`,{room:e}),confirmLabel:`OK`});return}let n=t.entries.map(e=>r(`locations.rebuildEntry`,{name:e.name,count:e.ids.length})).join(`
2
- `);if(!await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.replaceTheLinkedDeviceList`,`Replace the linked-device list of every camera in “{{room}}” with what the room contains? {{lines}} Anything linked by hand that is not in this room is lost.`,{room:e,lines:n}),confirmLabel:r(`locations.rebuild`,`Rebuild`),variant:`danger`}))return;let i=[];for(let e of t.entries)try{await A.mutateAsync(pt(e))}catch(t){i.push(`• ${e.name}: ${t instanceof Error?t.message:String(t)}`)}g(),i.length>0&&await s({title:r(`locations.rebuildLinkedDevices`,`Rebuild linked devices`),message:r(`locations.notRebuilt`,`Not rebuilt: {{value1}}`,{value1:i.join(`
3
- `)}),confirmLabel:`OK`})},ye=async(e,t)=>{let n=t>0?` ${String(t)} device(s) will become unassigned.`:``;await s({title:r(`locations.deleteLocation`,`Delete location`),message:r(`locations.deleteTheLocation`,`Delete the location “{{name}}”?{{extra}}`,{name:e,extra:n}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`})&&await v.mutateAsync({name:e,cascade:!0})},xe=async e=>{await s({title:r(`locations.deleteZone`,`Delete zone`),message:r(`locations.deleteTheZoneTheRooms`,`Delete the zone “{{name}}”? The rooms in it are kept.`,{name:e}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`})&&await T.mutateAsync({name:e})},K=async(e,t)=>{await S.mutateAsync({location:e,icon:t})},Se=async(e,t)=>{await C.mutateAsync({location:e,description:t})},q=f??[],we=async(e,t)=>{await O.mutateAsync({location:e,zone:t})},Ee=(e,t)=>{for(let n of e)b.mutate({deviceId:n,location:t})},[Y,X]=i(null),Oe=t(()=>j.filter(e=>e.parentDeviceId===null).map(e=>({id:e.id,name:e.name,type:e.type,location:e.location})),[j]),ke=n(st,{rooms:fe,...L===`locations`?{unassignedCount:z.length}:{},value:L===`locations`?le:U??``,unassignedValue:mt,onChange:pe}),Z=e(`div`,{className:`flex flex-col gap-3`,"data-testid":`locations-section`,children:[W&&n(`p`,{className:`text-xs text-foreground-subtle`,children:r(`locations.loadingLocationsAndDevices`,`Loading locations and devices…`)}),ke,B||H===null?n(lt,{rows:z,fleet:j,locations:M,busy:G,emptyMessage:W?r(`common.loading`,`Loading…`):r(`locations.everyTopLevelDeviceHas`,`Every top-level device has a room.`),onAssign:Ee}):n(et,{name:H.name,members:H.members,devices:j,busy:G,icon:Ze(u,E(H.name)),onPickIcon:e=>K(H.name,e),description:Ke(d,E(H.name)),onSaveDescription:e=>Se(H.name,e),zones:q,zoneKey:Ye(q,E(H.name)),onChangeZone:e=>we(H.name,e),onRename:e=>he(H.name,e),onDelete:()=>ye(H.name,Ae(j,H.name).length),onRebuildLinks:()=>ve(H.name),onAddDevices:()=>X(H.name)},H.name),M.length===0&&!W&&n(`p`,{className:`text-xs text-foreground-subtle`,children:r(`locations.noLocationsYetAddFrontDoor`,`No locations yet. Add Front door, Hall, Kitchen…`)}),n(Ve,{open:Y!==null,title:r(`locations.room.addDialogTitle`,{room:Y??``}),items:Oe,listState:m?`pending`:`answered`,lockedIds:Y===null?[]:(N.find(e=>e.name===Y)?.members??[]).map(e=>e.id),lockedNote:r(`locations.room.alreadyHere`),suggestions:{heading:r(`locations.room.suggestedUnassigned`),ids:z.map(e=>e.id)},busy:b.isPending,onConfirm:e=>{Y!==null&&Ee(e,Y),X(null)},onClose:()=>X(null)})]}),Q=e(`div`,{className:`flex flex-col gap-3`,"data-testid":`camera-links-tab`,children:[ke,n(He,{room:U,cameras:U===null?[]:Ae(j,U).filter(e=>e.isCamera),fleet:j})]});return n(De,{icon:y,title:r(`locations.locations`,`Locations`),subtitle:r(`locations.roomsAndAreasOfThe`,`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`),defaultSection:`locations`,sectionsLabel:`Locations sections`,actions:L===`zones`?n(at,{busy:w.isPending,onCreate:e=>w.mutateAsync({name:e})}):n(it,{busy:_.isPending,onCreate:me}),sections:[{id:`locations`,label:r(`locations.locations`,`Locations`),content:Z},{id:`camera-links`,label:r(`locations.cameraLinks`,`Camera links`),content:Q},{id:`zones`,label:r(`locations.zones`,`Zones`),content:n(rt,{zones:q,busy:G,onRename:(e,t)=>D.mutateAsync({from:e,to:t}),onDelete:xe,onPickIcon:(e,t)=>w.mutateAsync({name:e,icon:t})})}]})}export{ht as LocationsPage};
@@ -1 +0,0 @@
1
- import{C as e,K as t,R as n,S as r,V as i,Y as a,et as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Bn as s,Fr as c,Ha as l,Ua as u,aa as d,dt as f,ea as p,pi as m,pn as h}from"./player-overlays-VrMHBBfa.js";import{Xs as g,js as _}from"./client-CBrsD14Q.js";import{t as v}from"./layers-BH9u1mrE.js";import{t as y}from"./timer-reset-5221y6Jb.js";import{Cp as b,Li as x,Or as S,Qf as C,Ri as w,Wf as T,la as E,lf as D,lr as O,of as k,rf as A}from"./src-bJ4Hy4Cl.js";import{t as j}from"./useTranslation-BJr-n0es.js";import{b as M,o as N,s as P}from"./index-1bBrNxAK.js";import{t as F}from"./AdminSectionedPage-vnoSnjIu.js";import{t as I}from"./AdminPage-bLxyruUe.js";import{t as L}from"./InstancesTable-Cn1INVUs.js";function R(){let{t:e}=j();return r(L,{functionCap:`log-destination`,icon:s,title:e(`system.logging.destinations`,`Destinations`),subtitle:e(`system.logging.everyRegisteredLogDestinationEntries`,`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another.`),emptyTitle:e(`system.logging.noLogDestinationsRegistered`,`No log destinations registered`),emptyDescription:e(`system.logging.thisShouldNotHappenThe`,`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`),addLabel:e(`system.logging.addDestination`,`Add destination`),install:{capability:`log-destination`,label:e(`system.logging.installDestination`,`Install a destination`)}})}o();var z=[12e4,3e5,6e5,18e5],B={"request-census":`Counts every tRPC call by TRANSPORT PLANE — http, ws, mesh — and by procedure, caller, address and user-agent. Subscriptions are counted apart from calls, so a long-lived stream cannot pass for a storm. Arm it, then restart: the deadline is persisted, so the window is still running when clients reconnect.`};function V(){let{t}=j(),n=k({},{refetchInterval:5e3}),i=D(),[o,s]=a(null),u=(e,t)=>{s(e),i.mutate({patch:{diagnostics:[{id:e,armMs:t}]}},{onSettled:()=>{s(null),n.refetch()}})},d=n.data?.activeWindows??[],f=(n.data?.channels??[]).filter(e=>e.kind!==`debug`),p=n.data?.activeChannels??[],m=(e,t,r)=>{s(e),i.mutate({patch:{channels:[{channel:e,armMs:t,deviceIds:r}]}},{onSettled:()=>{s(null),n.refetch()}})};return e(I,{embedded:!0,icon:l,title:t(`logging.diagnostics.title`,`Diagnostics`),subtitle:t(`logging.diagnostics.subtitle`,`Diagnostics are armed for a window, never switched on. Each carries a deadline and expires by itself — one left running is an incident of its own.`),children:[n.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(c,{className:`h-3.5 w-3.5 animate-spin`}),t(`common.loading`,`Loading…`)]}):r(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:d.map(e=>r(U,{window:e,busy:o===e.id,onArm:t=>u(e.id,t)},e.id))}),r(`h3`,{className:`mt-6 text-sm font-medium text-foreground`,children:t(`logging.diagnostics.channels`,`Component channels`)}),r(`p`,{className:`mb-2 max-w-3xl text-[11px] text-foreground-subtle`,children:t(`logging.diagnostics.channelsSubtitle`,`Declared by the addons that own them — this list is not maintained by hand. Arming a channel opens a window with a deadline; it closes by itself.`)}),f.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`logging.diagnostics.noChannels`,`No addon on this cluster declares a log channel, or none could be reached right now.`)}):r(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:f.map(e=>r(H,{channel:e,state:p.find(t=>t.channel===e.name),busy:o===e.name,onArm:(t,n)=>m(e.name,t,n)},e.name))})]})}function H({channel:t,state:n,busy:i,onArm:o}){let{t:s}=j(),[c,l]=a(``),u=n?.armed===!0,f=()=>{let e=c.split(/[\s,+]+/).filter(e=>/^\d+$/.test(e)).map(e=>Number(e));return e.length>0?e:null};return e(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),u?e(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[r(y,{className:`h-3 w-3`}),s(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:W(n?.remainingMs??0)})]}):r(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:s(`logging.diagnostics.disarmed`,`disarmed`)}),u&&n?.deviceIds!==null&&n?.deviceIds!==void 0&&e(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[r(d,{className:`h-3 w-3`}),n.deviceIds.join(`, `)]}),!t.perDevice&&r(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:s(`logging.diagnostics.notPerCamera`,`not filterable per camera`)})]}),r(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:t.description})]}),e(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[t.perDevice&&r(C,{type:`text`,inputMode:`numeric`,value:c,disabled:i,onChange:e=>l(e.target.value),placeholder:s(`logging.diagnostics.camerasPlaceholder`,`all cameras`),className:`w-28 rounded border border-border bg-surface px-2 py-1 text-[11px] text-foreground`}),z.map(e=>r(T,{variant:`unstyled`,type:`button`,disabled:i,onClick:()=>o(e,f()),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:W(e)},e)),r(T,{variant:`unstyled`,type:`button`,disabled:i||!u,onClick:()=>o(0,null),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:s(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function U({window:t,busy:n,onArm:i}){let{t:a}=j();return e(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`flex items-center gap-2`,children:[r(`span`,{className:`text-sm font-medium text-foreground`,children:t.id}),t.armed?e(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[r(y,{className:`h-3 w-3`}),a(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:W(t.remainingMs)})]}):r(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:a(`logging.diagnostics.disarmed`,`disarmed`)}),t.armed&&!t.persisted&&r(`span`,{className:`text-[10px] text-warning`,children:a(`logging.diagnostics.notPersisted`,`not persisted — will not survive a restart`)})]}),r(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:B[t.id]??``})]}),e(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[z.map(e=>r(T,{variant:`unstyled`,type:`button`,disabled:n,onClick:()=>i(e),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:W(e)},e)),r(T,{variant:`unstyled`,type:`button`,disabled:n||!t.armed,onClick:()=>i(0),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:a(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function W(e){let t=Math.max(0,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n===0?`${r}s`:r===0?`${n}m`:`${n}m ${r}s`}o();var G=[`debug`,`info`,`warn`,`error`],K=``,q=``;function J(){let{t:n}=j(),[i,o]=a(K),[s,l]=a(q),{nodes:u}=b(),d=t(()=>u.map(e=>({id:e.id,label:e.name||e.id})),[u]),p=k({...i===K?{}:{scopeNodeId:i},...s===q?{}:{scopeComponent:s}},{refetchInterval:15e3}),m=D(),h=p.data,g=m.isPending||p.isFetching,_=(h?.channels??[]).filter(e=>e.kind!==`debug`),y=(e,t)=>{m.mutate({...e.nodeId===null?{}:{scopeNodeId:e.nodeId},...e.component===null?{}:{scopeComponent:e.component},patch:{level:t}},{onSuccess:()=>void p.refetch()})};return r(I,{embedded:!0,icon:v,title:n(`logging.levels.title`,`Levels`),subtitle:n(`logging.levels.subtitle`,`Cluster → node, most specific wins. The floor gates what reaches the log destinations; the in-memory viewer keeps every line either way.`),actions:e(`div`,{className:`flex flex-wrap items-center gap-3`,children:[e(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[n(`logging.levels.scope`,`Scope`),e(f,{wrapperClassName:`inline-block w-auto`,value:i,disabled:s!==q,onChange:e=>o(e.target.value),children:[r(`option`,{value:K,children:n(`logging.levels.cluster`,`Cluster`)}),d.map(e=>r(`option`,{value:e.id,children:e.label},e.id))]})]}),e(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[n(`logging.levels.component`,`Component`),e(f,{wrapperClassName:`inline-block w-auto`,value:s,onChange:e=>l(e.target.value),children:[r(`option`,{value:q,children:n(`logging.levels.noComponent`,`None`)}),_.map(e=>r(`option`,{value:e.name,children:e.name},e.name))]})]})]}),children:p.isLoading||h===void 0?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(c,{className:`h-3.5 w-3.5 animate-spin`}),n(`common.loading`,`Loading…`)]}):e(`div`,{className:`space-y-3`,children:[r(X,{level:h.effective.level,source:h.effective.levelSource,persisted:h.persisted}),r(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:h.explicit.layers.map(e=>r(Z,{layer:e,inForce:e.scope===h.effective.levelSource,busy:g,onSet:t=>y(e,t),onClear:()=>y(e,null)},`${e.scope}:${e.nodeId??e.component??`cluster`}`))}),s!==q&&r(`p`,{className:`text-[11px] text-foreground-subtle`,children:_.find(e=>e.name===s)?.description??``}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`logging.levels.componentNote`,`A component is a log channel an addon declared. Its level is cluster-wide and beats both the node and the cluster layer.`)}),r(Y,{days:h.opsLogRetentionDays,busy:g,onSet:e=>m.mutate({patch:{opsLogRetentionDays:e}},{onSuccess:()=>void p.refetch()})})]})})}function Y({days:t,busy:n,onSet:i}){let{t:a}=j();return e(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-1`,children:[e(`label`,{className:`flex items-center justify-between gap-3`,children:[r(`span`,{className:`text-xs font-medium`,children:a(`logging.levels.opsLogRetention`,`Retention audit trail`)}),e(`span`,{className:`flex items-center gap-1.5`,children:[r(C,{type:`number`,min:0,max:3650,step:1,defaultValue:t,disabled:n,onBlur:e=>{let n=Number.parseInt(e.target.value,10);Number.isFinite(n)&&n!==t&&i(n)},className:`w-20 rounded border border-border bg-surface px-2 py-1 text-xs`}),r(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`common.days`,`days`)})]})]}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`logging.levels.opsLogRetentionNote`,`How long the record of what retention deleted is kept. Cluster-wide, and deliberately longer than any camera window — it is the history of the sweep, not of the camera, and it is what makes a storage leak explainable after the fact. 0 keeps it forever.`)})]})}function X({level:t,source:n,persisted:i}){let{t:a}=j();return e(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[e(`div`,{className:`flex items-center gap-2`,children:[r(`span`,{className:`text-xs text-foreground-subtle`,children:a(`logging.levels.effective`,`In force here`)}),r(`span`,{className:`rounded bg-primary/10 px-2 py-0.5 text-xs font-semibold text-primary`,children:t}),r(`span`,{className:`text-[11px] text-foreground-subtle`,children:n==="default"?a(`logging.levels.fromDefault`,`nothing is set anywhere — this is the default`):a(`logging.levels.fromLayer`,`decided by the {{source}} layer`,{source:n})})]}),!i&&r(`p`,{className:`mt-1 text-[11px] text-warning`,children:a(`logging.levels.notPersisted`,`The settings store could not be read or written — what you see is live, but it would not survive a restart.`)})]})}function Z({layer:t,inForce:n,busy:i,onSet:a,onClear:o}){let{t:s}=j();return e(`div`,{className:`flex flex-col gap-2 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`flex items-center gap-2`,children:[r(`span`,{className:`text-sm font-medium text-foreground`,children:t.scope===`cluster`?s(`logging.levels.cluster`,`Cluster`):t.scope===`component`?t.component??``:t.nodeId??``}),n&&e(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-semibold text-primary`,children:[r(p,{className:`h-3 w-3`}),s(`logging.levels.inForce`,`in force`)]})]}),r(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:t.level===null?s(`logging.levels.inherits`,`inherits — nothing set at this layer`):s(`logging.levels.setHere`,`set here: {{level}}`,{level:t.level})})]}),e(`div`,{className:`flex shrink-0 items-center gap-1`,children:[G.map(e=>r(T,{variant:`unstyled`,type:`button`,disabled:i,onClick:()=>a(e),className:`rounded px-2 py-1 text-[11px] font-medium transition-colors disabled:opacity-50 ${t.level===e?`bg-primary text-primary-foreground`:`border border-border text-foreground-subtle hover:text-foreground`}`,children:e},e)),r(T,{variant:`unstyled`,type:`button`,disabled:i||t.level===null,onClick:o,className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-40`,children:s(`logging.levels.clear`,`Clear`)})]})]})}function Q(e){let t=Math.max(0,Math.round(e/1e3)),n=Math.floor(t/60),r=t%60;return n===0?`${r}s`:`${n}m ${String(r).padStart(2,`0`)}s`}function $(e,t){return{windowMs:Math.max(0,e.untilMs-t),capMs:Math.max(0,e.capAtMs-t)}}function ee(e,t){let n=new Set(e.map(e=>e.channel));return t.filter(e=>n.has(e))}o();var te=[_.Camera],ne=8,re=1e3,ie=15e3;function ae(){let{t:o}=j(),s=k({},{refetchInterval:15e3}),l=A(),[d,f]=a([]),[p,_]=a([]),[v,b]=a([]),[C,D]=a(()=>Date.now()),[M,N]=a([]),P=t(()=>(s.data?.channels??[]).filter(e=>e.kind===`debug`),[s.data]),F=n((e,t,n)=>{l.mutate({action:e,channels:t,deviceIds:n},{onSuccess:e=>{f(e.watches),N(e.lapsed)}})},[]);i(()=>{let e=setInterval(()=>D(Date.now()),re);return()=>clearInterval(e)},[]),i(()=>{F(`list`,[],[]);let e=setInterval(()=>F(`list`,[],[]),ie);return()=>clearInterval(e)},[F]);let L=ee(d,p).join(`|`);i(()=>{if(L===``)return;let e=setInterval(()=>F(`rearm`,L.split(`|`),[]),g);return()=>clearInterval(e)},[L,F]);let R=p.length>0&&v.length>0&&!l.isPending,z=[...new Set(d.flatMap(e=>e.deviceIds))],B=(e,t)=>_(n=>t?[...n,e]:n.filter(t=>t!==e));return e(I,{embedded:!0,icon:m,title:o(`logging.watch.title`,`Watch`),subtitle:o(`logging.watch.subtitle`,`Switch a debug channel on for chosen devices and read it live. A watch lasts 10 minutes, is renewed while this page stays open, and ends by itself after 60 minutes at most.`),children:[r(S,{headingId:`log-watch-setup`,title:o(`logging.watch.setup`,`Channels and devices`),children:s.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[r(c,{className:`h-3.5 w-3.5 animate-spin`}),o(`common.loading`,`Loading…`)]}):P.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`logging.watch.noChannels`,`No addon on this cluster offers a debug channel, or none could be reached right now.`)}):e(`div`,{className:`space-y-3 p-3`,children:[r(`div`,{className:`space-y-2`,children:P.map(t=>e(`label`,{className:`flex items-start gap-2`,children:[r(u,{checked:p.includes(t.name),onChange:e=>B(t.name,e.target.checked)}),e(`span`,{className:`min-w-0`,children:[r(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),r(`span`,{className:`block text-[11px] text-foreground-subtle`,children:t.description})]})]},t.name))}),e(`div`,{className:`flex flex-col gap-1`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:o(`logging.watch.devices`,`Devices`)}),r(E,{multiple:!0,pick:`device`,noun:`camera`,fixedTypes:te,maxItems:ne,recentKey:`log-watch-devices`,testId:`log-watch-devices`,value:w(v),onChange:e=>b(x(e))})]}),e(`div`,{className:`flex flex-wrap gap-2`,children:[r(T,{type:`button`,disabled:!R,onClick:()=>F(`start`,p,v),children:o(`logging.watch.start`,`Start watching`)}),e(T,{type:`button`,variant:`secondary`,disabled:d.length===0||l.isPending,onClick:()=>F(`stop`,d.map(e=>e.channel),[]),children:[r(h,{className:`mr-1 h-3.5 w-3.5`}),o(`logging.watch.stop`,`Stop`)]})]}),l.isError&&r(`p`,{className:`text-[11px] text-destructive`,children:l.error.message}),M.length>0&&r(`p`,{className:`text-[11px] text-warning`,children:o(`logging.watch.lapsed`,`Already ended, not renewed: {{names}}. Start again to continue.`,{names:M.join(`, `)})})]})}),d.length>0&&e(S,{headingId:`log-watch-live`,title:o(`logging.watch.live`,`Live`),children:[r(`div`,{className:`divide-y divide-border`,children:d.map(t=>{let n=$(t,C);return e(`div`,{className:`flex flex-wrap items-center gap-2 p-3`,children:[r(`span`,{className:`text-sm font-medium text-foreground`,children:t.channel}),e(`span`,{className:`inline-flex items-center gap-1 rounded bg-warning/10 px-1.5 py-0.5 text-[10px] font-semibold text-warning`,children:[r(y,{className:`h-3 w-3`}),o(`logging.watch.endsIn`,`ends in {{left}}`,{left:Q(n.windowMs)})]}),r(`span`,{className:`text-[11px] text-foreground-subtle`,children:o(`logging.watch.capIn`,`hard stop in {{left}}`,{left:Q(n.capMs)})}),e(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`#`,t.deviceIds.join(`, #`)]})]},t.channel)})}),z.map(e=>r(`div`,{className:`border-t border-border`,children:r(O,{deviceId:e,limit:200,maxHeight:`max-h-80`,showScope:!0,showFilters:!1})},e))]})]})}function oe(){return r(I,{embedded:!0,children:r(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:r(O,{limit:500,maxHeight:`max-h-[calc(100vh-310px)]`,showScope:!0,showFilters:!0,showOriginFilter:!0})})})}function se(){let{t:e}=j(),t=M(`/system/logs`,{t:e,isAdmin:!0})??{icon:s,title:e(`system.logs`,`Logs`)};return r(F,{icon:t.icon,title:t.title,defaultSection:`viewer`,sectionsLabel:`${t.title} sections`,sections:[{id:`viewer`,label:e(`admin.system.logs.viewer`,`Viewer`),content:r(oe,{})},{id:P.logging.tab,label:e(`admin.system.logs.destinations`,`Destinations`),content:r(R,{}),ownedParams:N},{id:`levels`,label:e(`admin.system.logs.levels`,`Levels`),content:r(J,{})},{id:`watch`,label:e(`admin.system.logs.watch`,`Watch`),content:r(ae,{})},{id:`diagnostics`,label:e(`admin.system.logs.diagnostics`,`Diagnostics`),content:r(V,{})}]})}export{se as LogsPage};