@camstack/addon-admin-ui 1.2.372 → 1.2.373

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 (68) hide show
  1. package/dist/assets/{AddonAssetIcon-Bvlbs-we.js → AddonAssetIcon-DzDR4RgH.js} +1 -1
  2. package/dist/assets/{AddonIntegrationBody-CLBlTXCr.js → AddonIntegrationBody-WZ-GmbiU.js} +1 -1
  3. package/dist/assets/{Addons-BHYRFNw1.js → Addons-DYnLpXZv.js} +1 -1
  4. package/dist/assets/{AdminTabs-2smlNAE_.js → AdminTabs-C1o_WGDw.js} +1 -1
  5. package/dist/assets/{AiProfiles-BwlI-5bY.js → AiProfiles-BaPBs0qt.js} +1 -1
  6. package/dist/assets/{BrokerForm-B0-lyNPR.js → BrokerForm-CUEA6_x3.js} +1 -1
  7. package/dist/assets/{Build-MbSINb6K.js → Build-IvUCLdig.js} +1 -1
  8. package/dist/assets/{Calendars-C379ZdmG.js → Calendars-I6TCXQIG.js} +1 -1
  9. package/dist/assets/Cluster-Ct_1WPkP.js +1 -0
  10. package/dist/assets/ClusterStepModel-BKEy6uc_.js +1 -0
  11. package/dist/assets/{CompositionEditor-B8IeJs7c.js → CompositionEditor-CUJz5zIO.js} +1 -1
  12. package/dist/assets/{CompositionEditorPage-BTw1h9ZH.js → CompositionEditorPage-ggzQcHQq.js} +1 -1
  13. package/dist/assets/{Data-BbVK94E9.js → Data-X0oYW_Rh.js} +1 -1
  14. package/dist/assets/{DetectionIntelligence-hzaazWUY.js → DetectionIntelligence-CzuLuRps.js} +1 -1
  15. package/dist/assets/{DeviceDetail-BejYs7N7.js → DeviceDetail-ByFN1i10.js} +1 -1
  16. package/dist/assets/{DeviceDoActionFields-Do6M2l_j.js → DeviceDoActionFields-DirqSmTT.js} +1 -1
  17. package/dist/assets/{Devices-D9Pc88Qo.js → Devices-D_N3dsDP.js} +1 -1
  18. package/dist/assets/{EmbedPlayerPage-Cq-C31nE.js → EmbedPlayerPage-BwnkfDUy.js} +1 -1
  19. package/dist/assets/{Events-Ct5izUvZ.js → Events-CR7guuuS.js} +1 -1
  20. package/dist/assets/{Identity-FGkTFfhf.js → Identity-DIGRfdjI.js} +1 -1
  21. package/dist/assets/{IntegrationDetail-BpA3QO-E.js → IntegrationDetail-6BYWzrle.js} +1 -1
  22. package/dist/assets/{Integrations-DhrSWf1p.js → Integrations-Dtep2eUt.js} +1 -1
  23. package/dist/assets/{Integrations-BRiFwXi8.js → Integrations-DxgCSKYL.js} +1 -1
  24. package/dist/assets/{Locations-D0REDYo5.js → Locations-PBa5sZr9.js} +1 -1
  25. package/dist/assets/{Logs-B46x0jJR.js → Logs-CqrKzl8c.js} +1 -1
  26. package/dist/assets/{MyAccess-CghKYIxJ.js → MyAccess-2HFGVdy3.js} +1 -1
  27. package/dist/assets/{Network-q_b0sLVC.js → Network-lmWW7YF8.js} +1 -1
  28. package/dist/assets/{NodeAddonsSettingsPanel-Ci0PhhCq.js → NodeAddonsSettingsPanel-VjOJE4Mg.js} +1 -1
  29. package/dist/assets/{Notifications-BriWzxUb.js → Notifications-C95KlkmG.js} +1 -1
  30. package/dist/assets/{Plates-CZ3RQk3R.js → Plates-CYU7XcQC.js} +1 -1
  31. package/dist/assets/{Recordings-AQiIOomS.js → Recordings-CZnERdvC.js} +1 -1
  32. package/dist/assets/{ScanNetworkModal-DXODoRu9.js → ScanNetworkModal-BcwSCus9.js} +1 -1
  33. package/dist/assets/{Scenes-xNrpPskA.js → Scenes-Cf37C7N3.js} +1 -1
  34. package/dist/assets/{SessionsList-CFIFn9Bc.js → SessionsList-DW5tspI_.js} +1 -1
  35. package/dist/assets/{Showroom-UJJ5VRWX.js → Showroom-BCHYtMRz.js} +1 -1
  36. package/dist/assets/{System-DQS8iVd0.js → System-DoO-0QYY.js} +1 -1
  37. package/dist/assets/{Terminal-BzbZmqDx.js → Terminal-Cl6odY2y.js} +1 -1
  38. package/dist/assets/{Viewer-DDEk3JEc.js → Viewer-BeiK1WJq.js} +1 -1
  39. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C8DdBVOU.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-itrNHhFH.js} +1 -1
  40. package/dist/assets/{authed-media-Br9lZGdM.js → authed-media-hm_YC5GG.js} +1 -1
  41. package/dist/assets/{debounced-invalidate-aLTpVZnL.js → debounced-invalidate-Dy7qLdW1.js} +1 -1
  42. package/dist/assets/{device-integration-icon-ByZPIc_Q.js → device-integration-icon-C6TnIOOf.js} +1 -1
  43. package/dist/assets/device-picker-model-PKbAt0O0.js +1 -0
  44. package/dist/assets/{face-bbox-x3rH65-o.js → face-bbox-CNmj5VUt.js} +1 -1
  45. package/dist/assets/{hostInit-BUJ0U0UP.js → hostInit-44uecb4-.js} +1 -1
  46. package/dist/assets/{index-BlaisiEj.js → index-Wd9AuQ7z.js} +3 -3
  47. package/dist/assets/{location-owned-usage-QVsNqX7g.js → location-owned-usage-ByCAX4XJ.js} +1 -1
  48. package/dist/assets/{mf-entry-bootstrap-0-8330eb86.js → mf-entry-bootstrap-0-894be14f.js} +2 -2
  49. package/dist/assets/mount-PKbAt0O0.js +1 -0
  50. package/dist/assets/node-color-map-ChrpDB9I.js +1 -0
  51. package/dist/assets/{notification-schedule-field-CNwv7_6o.js → notification-schedule-field-DtmwnNDm.js} +1 -1
  52. package/dist/assets/remoteEntry-CGNtQhcK.js +1 -0
  53. package/dist/assets/{src-BTQcUQJz.js → src-QOexoM_4.js} +1 -1
  54. package/dist/assets/{use-scenes-feed-DcNDaTD0.js → use-scenes-feed-BkLm9Irc.js} +1 -1
  55. package/dist/assets/{use-stationary-objects-C6uSntPO.js → use-stationary-objects-C_J8GfJs.js} +1 -1
  56. package/dist/assets/useEventInvalidation-PKbAt0O0.js +1 -0
  57. package/dist/assets/{useNodeUrlSelection-DwKt8fEX.js → useNodeUrlSelection-BUjxvnuG.js} +1 -1
  58. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-C0f8TSRz.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CYQBrudz.js} +2 -2
  59. package/dist/index.html +5 -5
  60. package/dist/server/addon.js +1 -1
  61. package/package.json +1 -1
  62. package/dist/assets/Cluster-CIwtiuWP.js +0 -1
  63. package/dist/assets/ClusterStepModel-C7lERZS9.js +0 -1
  64. package/dist/assets/board-model-Bmts6hrg.js +0 -1
  65. package/dist/assets/device-picker-model-BZYpYRsM.js +0 -1
  66. package/dist/assets/mount-BZYpYRsM.js +0 -1
  67. package/dist/assets/remoteEntry-CEno4jo3.js +0 -1
  68. package/dist/assets/useEventInvalidation-BZYpYRsM.js +0 -1
@@ -1 +1 @@
1
- import{I as e,K as t,Q as n,S as r,W as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as l,gt as u,ht as d,mt as f,st as p,vt as m}from"./player-overlays-B7T46vDu.js";import{$a as h,Bu as g,Cn as _,Dn as v,En as y,Fa as b,Fd as x,Gi as S,Hi as C,J as w,Ji as T,Ju as E,Ki as D,Kl as O,Or as k,Sn as A,Ui as j,Uu as ee,Wi as M,X as N,Xi as P,Yi as F,Yl as I,Yu as L,Zd as R,Zu as z,bf as B,dr as V,ea as te,en as ne,eo as H,ga as U,gd as W,hn as G,ia as K,io as re,iu as q,kt as ie,la as ae,nf as oe,no as se,oo as ce,q as le,qd as ue,ro as de,su as fe,ta as pe,td as J,to as me,ur as Y,va as he,vt as ge,xn as _e,yu as X,zt as ve}from"./src-BTQcUQJz.js";import{Er as ye}from"./client-BBcQuaON.js";import{t as Z}from"./useTranslation-Bc5yH9V9.js";import{$ as be,I as xe,Q as Se,Z as Ce,q as we}from"./index-BlaisiEj.js";import{t as Te}from"./NodeAddonsSettingsPanel-Ci0PhhCq.js";import{t as Ee}from"./device-integration-icon-ByZPIc_Q.js";import{n as De,r as Oe,t as ke}from"./ScanNetworkModal-DXODoRu9.js";var Ae=m(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);n();function Q(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Q(n.fields));return t}function je(t,n,r){let[a,s]=o(`idle`),[c,l]=o({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...Q(n.fields));return e},[t]),d=u.length>0&&r!==void 0,f=e(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:e(async()=>{if(!r)return;let e=u.filter(e=>{let t=n[e];return t!=null&&String(t).trim()!==``});if(e.length===0)return;s(`testing`);let t={};for(let n of e)t[n]={status:`probing`};l(t);let i=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await r(e,n[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of i)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`)},[r,u,n]),clearProbeResult:f}}n();function Me(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(...Me(n.fields));return t}function Ne(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Pe(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Pe(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Fe(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Ie({open:t,integrationId:n,addonId:l,onClose:d}){let{t:f}=Z(),p=a(),[m,h]=o({}),[g,_]=o(!1),[v,y]=o(null),[x,S]=o(Fe),C=U({addonId:l},{enabled:t}),w=C.data?.deviceType??null,T=K({addonId:l,type:w??ye.Camera},{enabled:t&&C.isSuccess&&w!==null}),E=T.data??null;c(()=>{t&&(h(E?Pe(E.sections.flatMap(e=>e.fields)):{}),S(Fe()),_(!1),y(null))},[t,n,E]);let D=i(()=>({...m,_probeRequestId:x}),[m,x]),O=F({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),k=b(),A=e(async(e,t)=>{_(!0);let n=await k.mutateAsync({addonId:l,type:w??ye.Camera,key:e,value:t,formValues:D});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Ne(e[i])&&!Ne(a)&&(r[i]=a,t=!0);return t?r:e}),n},[k,l,D,w]),{testAllStatus:j,hasProbeFields:M,probeResults:N,handleTestAll:P,clearProbeResult:I}=je(E??{sections:[]},m,A);async function L(e){y(null);try{await O.mutateAsync({addonId:l,type:w??ye.Camera,config:m,integrationId:n}),e?h(E?Pe(E.sections.flatMap(e=>e.fields)):{}):d()}catch(e){y(e instanceof Error?e.message:String(e))}}if(!t)return null;let R=Me((E?.sections??[]).flatMap(e=>e.fields)).filter(e=>Ne(m[e])),z=R.length===0,B=C.isLoading||w!==null&&T.isLoading,V=C.isError||C.isSuccess&&w===null||T.isError||T.isSuccess&&E===null;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:d}),r(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:f(`integrations.addDevice`)}),s(`button`,{onClick:d,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:s(q,{className:`h-4 w-4`})})]}),s(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:B?s(`div`,{className:`flex items-center justify-center py-8`,children:s(W,{className:`h-5 w-5 animate-spin text-primary`})}):V?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[s(X,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`space-y-1`,children:[s(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,s(`span`,{className:`font-mono`,children:l}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):s(xe,{schema:E,values:m,onChange:h,onTestField:A,probeResults:N,onClearProbe:I})}),!V&&!B&&r(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[r(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[r(`span`,{className:`flex items-center gap-2`,children:[s(ee,{className:`h-3.5 w-3.5`}),`Test logs`,s(`span`,{className:`font-mono text-[9px] opacity-60`,children:x.slice(0,14)})]}),s(u,{className:`h-3.5 w-3.5 transition-transform ${g?`rotate-180`:``}`})]}),g&&s(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:s(ge,{addonId:l,requestId:x,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!V&&!B&&(v||R.length>0)&&s(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(X,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-[11px] text-destructive`,children:v||`Required: ${R.join(`, `)}`})]})}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:d,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`)}),!V&&M&&r(`button`,{type:`button`,onClick:P,disabled:j===`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:[j===`testing`?s(W,{className:`h-3.5 w-3.5 animate-spin`}):s(fe,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:()=>L(!0),disabled:V||!z||O.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`)}),s(`button`,{onClick:()=>L(!1),disabled:V||!z||O.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:O.isPending?f(`integrations.saving`):f(`integrations.save`)})]})]})]})]})}var Le=1500;function $({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=Z(),o=C(),c=(S({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Le:!1}).data??[]).find(e=>e.jobId===n);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&&i();let f=[`${u}/${c.total} ${a(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&f.push(`${c.adopted} ${a(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&f.push(`${c.alreadyAdopted} ${a(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&f.push(`${c.failed} ${a(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return r(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2`,children:[l?s(W,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?s(X,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?s(ue,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):s(R,{className:`h-3.5 w-3.5 text-primary shrink-0`}),s(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&s(`button`,{onClick:()=>o.mutate({jobId:n}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),s(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:s(`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(e=>r(`p`,{className:`text-[11px] text-destructive`,children:[e.childNativeId,`: `,e.error]},e.childNativeId))]})}function Re(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(` `)}n();var ze=`devices`,Be={id:ze,label:`Devices`,isDefault:!0},Ve=2e4,He=100;function Ue({addonId:n,integrationId:i,onClose:l}){let{t:u}=Z(),d=a(),[f,p]=o(new Set),[m,h]=o(new Set),[g,_]=o(new Map),[v,y]=o(null),{data:b}=me(),x=(b??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[S,C]=o(!0),w=j({addonId:n,integrationId:i}).data?.filters,k=w&&w.length>0?w:[Be],[A,ee]=o(k.find(e=>e.isDefault)?.id??(k.some(e=>e.id===ze)?ze:k[0].id)),N=A!==ze,P=D(),F=M({addonId:n,integrationId:i,page:1,pageSize:Ve,filter:A}),L=F.refetch,R=P.mutate,z=e(()=>{R({addonId:n,integrationId:i},{onSettled:()=>{L()}})},[R,n,i,L]),B=t(null);c(()=>{let e=`${n}::${i}`;B.current===e||F.isLoading||(B.current=e,(F.data?.candidates.length??0)===0&&z())},[n,i,F.isLoading,F.data,z]);let V=P.isPending,te=P.isError?P.error instanceof Error?P.error.message:String(P.error):null,ne=typeof P.data?.lastError==`string`&&P.data.lastError.length>0?P.data.lastError:null,H=F.data?.candidates??[],U=F.isError?F.error instanceof Error?F.error.message:String(F.error):null,G=T(),[K,re]=o(null),ie=e(e=>{e.alreadyAdopted||p(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),ae=e(e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),se=e((e,t)=>{_(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})},[]),ce=e(e=>{let t={};for(let n of e){let e=g.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[g]),ue=e(async()=>{y(null);let e=[...f];if(e.length!==0)try{let t=ce(e),{jobId:r}=await G.mutateAsync({addonId:n,integrationId:i,filter:A,childNativeIds:e,...t?{perCandidate:t}:{},...x?{importLocations:S}:{}});re(r),p(new Set),_(new Map)}catch(e){y(e instanceof Error?e.message:String(e))}},[f,ce,G,n,i,A,x,S]),de=t(null),fe=e(()=>{K===null||de.current===K||(de.current=K,L(),d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}))},[K,L,d]),pe=e(e=>{ee(e),p(new Set),h(new Set),_(new Map),y(null)},[]),J=f.size,Y=K!==null&&J===0&&!G.isPending;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:l}),r(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[r(`div`,{className:`min-w-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:u(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),s(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:u(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),r(`div`,{className:`flex items-center gap-3 shrink-0`,children:[x&&r(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[s(`input`,{type:`checkbox`,checked:S,onChange:e=>C(e.target.checked),className:`accent-primary`}),u(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),s(`button`,{onClick:l,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:s(q,{className:`h-4 w-4`})})]})]}),r(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(te??U??ne)&&H.length===0&&s(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(X,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`min-w-0`,children:[s(`p`,{className:`text-xs font-medium text-destructive`,children:u(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),s(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:te??U??ne})]})]})}),k.length>1&&s(We,{filters:k,activeFilter:A,onSelect:pe}),s(`div`,{className:`flex-1 min-h-0`,children:s(le,{mode:`generic`,items:H,pageSize:He,getKey:e=>e.childNativeId,getSearchText:Re,getFilterType:e=>e.type,filterOptions:O(),filterLabel:u(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:F.isLoading||V&&H.length===0,searchPlaceholder:u(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(te??U??ne)&&H.length===0?``:u(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:z,disabled:V,title:u(`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:[s(E,{className:`h-3.5 w-3.5 ${V?`animate-spin`:``}`}),u(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:u(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>s(Ge,{candidate:e,expandable:!N,expanded:m.has(e.childNativeId),onToggleExpand:()=>ae(e.childNativeId),adoptedLabel:u(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:u(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=I(e.type),n=t.icon;return r(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[s(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>s(`div`,{className:`flex items-center justify-end`,children:s(`button`,{onClick:()=>ie(e),disabled:e.alreadyAdopted,"aria-label":f.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${f.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:f.has(e.childNativeId)&&s(oe,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!N&&m.has(e.childNativeId),renderExpanded:N?void 0:e=>s(Ke,{candidate:e,hiddenChildIds:g.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>se(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:f.has(e.childNativeId)?`bg-primary/5`:``})})]}),v&&s(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(X,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-[11px] text-destructive`,children:v})]})}),K!==null&&s($,{addonId:n,integrationId:i,jobId:K,onFinished:fe}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[s(`div`,{}),r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:l,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:u(`integrations.cancel`,{defaultValue:`Cancel`})}),r(`button`,{onClick:Y?l:ue,disabled:!Y&&(J===0||G.isPending),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[G.isPending&&s(W,{className:`h-3.5 w-3.5 animate-spin`}),Y?u(`integrations.close`,{defaultValue:`Close`}):u(`integrations.addSelected`,{defaultValue:`Add selected`}),!Y&&J>0?` (${J})`:``]})]})]})]})]})}function We({filters:e,activeFilter:t,onSelect:n}){return s(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return s(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function Ge({candidate:e,expandable:t,expanded:n,onToggleExpand:i,adoptedLabel:a}){let o=(e.children??[]).length;return r(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&o>0?r(`button`,{type:`button`,onClick:i,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[s(n?u:d,{className:`h-3.5 w-3.5`}),o]}):s(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),s(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&s(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:a})]})}function Ke({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let i=e.children??[];return i.length===0?null:s(`div`,{className:`space-y-1 py-1`,children:i.map(e=>{let i=t.has(e.childNativeId),a=e.capabilities??[];return r(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${i?`opacity-50`:``}`,children:[s(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),a.length>0&&s(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:a.join(`, `)}),s(`button`,{onClick:()=>n(e.childNativeId),"aria-label":i?`Show child`:`Hide child`,title:i?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:s(i?f:x,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function qe(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...qe(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function Je(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>qe(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Ye(e){return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(`value`in e){let{value:t,...n}=e;return n}return e})}))}}function Xe({integrationId:e,addonId:t,name:n,kind:o,mode:c,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=Z(),m=a(),{data:h,isLoading:g}=se({id:e},{enabled:c===`account`||c===`broker`}),b=i(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:x,isLoading:S}=Y({addonId:t,nodeId:`hub`},{enabled:c===`account`}),C=i(()=>x?Ye(x):null,[x]),w=re(),T=(t,n)=>{w.mutate({id:e,settings:t,...n?{secretKeys:[...n]}:{}},{onSuccess:()=>{m.invalidateQueries(),f()}})};return s(_e,{open:!0,onOpenChange:e=>!e&&f(),children:r(_,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[s(y,{children:r(v,{children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]})}),s(A,{children:c===`broker`?l?r(`div`,{className:`space-y-3`,children:[s(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),b&&r(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,s(`span`,{className:`font-mono text-foreground-subtle`,children:b})]}),w.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[s(W,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):s(Oe,{kind:l,onResolved:e=>{T({brokerId:e})},onBack:f}),w.isError&&s(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):s(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):c===`account`?g||S?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[s(W,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):s(De,{addonId:t,configSchema:C,canTest:u,initialName:n,initialConfig:Je(C,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e,secretKeys:t})=>T(e,t),onBack:f}):s(G,{trpc:d,addonId:t,nodeId:`hub`,title:n})})]})})}function Ze(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}n();function Qe(){let{t}=Z(),{integrationId:n}=Se(),u=a(),d=Ce(),[f,m]=be(),b=l(),[x,S]=o(!1),[C,T]=o(!1),[E,D]=o(!1),[O,j]=o(!1),{data:M,isLoading:F}=H({id:n??``},{enabled:!!n}),{data:I}=Y({addonId:M?.addonId??``,nodeId:`hub`},{enabled:!!M?.addonId}),{data:R,isSuccess:U}=me(),G=i(()=>{let e=M?.addonId;return!e||!U?null:(R??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[R,M?.addonId,U]),{data:K}=te({}),re=i(()=>(K?.providers??[]).some(e=>e.addonId===M?.addonId),[K,M?.addonId]),q=G!==null,oe=M?.info?.fixed===!0,se=q?G===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),ue=i(()=>{let e=M?.addonId;return!e||!U?null:(R??[]).find(t=>t.addonId===e)?.brokerKind??null},[R,M?.addonId,U]),fe=i(()=>{let e=M?.addonId;return!e||!U?!1:(R??[]).find(t=>t.addonId===e)?.canTest===!0},[R,M?.addonId,U]),X=i(()=>{let e=M?.addonId;return!e||!U?null:(R??[]).find(t=>t.addonId===e)?.mode??null},[R,M?.addonId,U]);c(()=>{f.get(`add`)===`1`&&q&&(S(!0),m(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[f,q,m]);let ye=I!=null&&Array.isArray(I.sections)&&I.sections.some(e=>e.fields.length>0),{data:xe}=V({addonId:M?.addonId??``,nodeId:`hub`},{enabled:!!M?.addonId&&X!==`account`}),we=X!==null&&X!==`account`&&Ze(xe),De=i(()=>M?.addonId?[M.addonId]:[],[M?.addonId]),{data:Oe}=ae({projection:`slim`},{refetchInterval:3e4}),Q=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],je=ce({onMutate:async e=>{await u.cancelQueries({queryKey:Q});let t=u.getQueryData(Q);return t!=null&&u.setQueryData(Q,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&u.setQueryData(Q,r.previous)},onSettled:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Me=h({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]}),d(`/integrations`)}}),Ne=k({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Pe=he({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=P({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=pe({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=i(()=>Oe??[],[Oe]),Re=i(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),ze=e(e=>Re.get(e)??null,[Re]),{data:Be}=de(void 0),Ve=i(()=>w(Be),[Be]),He=e(e=>d(`/devices/${String(e)}`),[d]),We=i(()=>{let e=M?.id;return e?$.filter(t=>{let n=Ve(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[$,M?.id,Ve]),Ge=i(()=>Be===void 0?null:N(We).length,[Be,We])??`…`;return F?r(`div`,{className:`p-4`,children:[s(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),s(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):M?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[s(ve,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},{label:M.name}]}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-3 min-w-0`,children:[s($e,{addonId:M.addonId}),r(`div`,{className:`min-w-0`,children:[s(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:M.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[M.addonId,` · `,Ge,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[re&&r(`button`,{onClick:()=>T(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the network for devices (incl. a different subnet)`,children:[s(z,{className:`h-3.5 w-3.5`}),`Scan network`]}),!oe&&r(`button`,{onClick:()=>S(!0),disabled:!q,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:se,children:[s(J,{className:`h-3.5 w-3.5`}),se]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${je.isPending?`opacity-60`:``} ${M.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[s(ne,{checked:M.enabled,onCheckedChange:e=>je.mutate({id:n,enabled:e}),disabled:je.isPending,"aria-label":M.enabled?`Disable integration`:`Enable integration`}),s(`span`,{className:`text-[11px] font-medium ${M.enabled?`text-success`:`text-foreground-subtle`}`,children:M.enabled?`Enabled`:`Disabled`}),je.isPending&&s(W,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),X!==`standalone`&&(ye||G===`device-adoption`)&&r(`button`,{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`,children:[s(g,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>j(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.logs`,{defaultValue:`View logs`}),children:[s(ee,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),s(ie,{label:`Restart`,icon:L,title:`Restart "${M.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ge} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Ne.isPending,action:()=>Ne.mutateAsync({addonId:M.addonId})}),!oe&&n&&s(ie,{label:t(`integrations.delete`,{defaultValue:`Delete`}),icon:p,title:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:M.name,count:Ge}),confirmLabel:t(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Me.isPending,action:()=>Me.mutateAsync({id:n})})]})]}),we&&s(Te,{nodeId:null,addonIds:De,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),s(le,{context:`integration-detail`,devices:$,trpc:b.trpcClient,integrationOf:Ve,forceIntegrationId:M.id,urlScope:`root`,lsKey:`integration-detail:${M.addonId}`,resolveIntegrationIcon:Ee,resolveParent:ze,onNavigate:He,batchActions:{remove:Pe.mutate,disable:Fe.mutate,enable:Le.mutate},...oe?{}:{onDeleteDevice:e=>Pe.mutate({deviceId:e.id})}}),x&&n&&G===`device-adoption`&&s(Ue,{addonId:M.addonId,integrationId:n,onClose:()=>S(!1)}),x&&n&&G===`device-provider`&&s(Ie,{open:x,integrationId:n,addonId:M.addonId,onClose:()=>S(!1)}),C&&M&&s(ke,{open:C,scope:{addonId:M.addonId,label:M.name},onClose:()=>T(!1)}),E&&n&&G!==null&&X!==null&&s(Xe,{integrationId:n,addonId:M.addonId,name:M.name,kind:G,mode:X,brokerKind:ue,canTest:fe,trpc:b.trpcClient,onClose:()=>D(!1)}),O&&s(_e,{open:!0,onOpenChange:e=>!e&&j(!1),children:r(_,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[s(y,{className:`mb-0`,children:r(v,{className:`flex items-center gap-2 min-w-0`,children:[s(ee,{className:`h-4 w-4 text-primary shrink-0`}),s(`span`,{className:`truncate`,children:M.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[M.addonId,n?` · ${n}`:``]})]})}),s(A,{className:`min-h-0 overflow-hidden p-0`,children:s(ge,{addonId:M.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})})]}):r(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[s(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:s(Ae,{className:`h-6 w-6 text-foreground-subtle`})}),r(`div`,{className:`space-y-1 max-w-sm`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),s(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),r(`button`,{onClick:()=>d(`/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:[s(B,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function $e({addonId:e}){let t=we(e),[n,r]=o(!1);return!t||n?null:s(`img`,{src:t,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:()=>r(!0)})}export{Qe as IntegrationDetailPage};
1
+ import{I as e,K as t,Q as n,S as r,W as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as l,gt as u,ht as d,mt as f,st as p,vt as m}from"./player-overlays-B7T46vDu.js";import{$a as h,Bu as g,Cn as _,Dn as v,En as y,Fa as b,Fd as x,Gi as S,Hi as C,J as w,Ji as T,Ju as E,Ki as D,Kl as O,Or as k,Sn as A,Ui as j,Uu as ee,Wi as M,X as N,Xi as P,Yi as F,Yl as I,Yu as L,Zd as R,Zu as z,bf as B,dr as V,ea as te,en as ne,eo as H,ga as U,gd as W,hn as G,ia as K,io as re,iu as q,kt as ie,la as ae,nf as oe,no as se,oo as ce,q as le,qd as ue,ro as de,su as fe,ta as pe,td as J,to as me,ur as Y,va as he,vt as ge,xn as _e,yu as X,zt as ve}from"./src-QOexoM_4.js";import{Er as ye}from"./client-BBcQuaON.js";import{t as Z}from"./useTranslation-Bc5yH9V9.js";import{$ as be,I as xe,Q as Se,Z as Ce,q as we}from"./index-Wd9AuQ7z.js";import{t as Te}from"./NodeAddonsSettingsPanel-VjOJE4Mg.js";import{t as Ee}from"./device-integration-icon-C6TnIOOf.js";import{n as De,r as Oe,t as ke}from"./ScanNetworkModal-BcwSCus9.js";var Ae=m(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);n();function Q(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Q(n.fields));return t}function je(t,n,r){let[a,s]=o(`idle`),[c,l]=o({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...Q(n.fields));return e},[t]),d=u.length>0&&r!==void 0,f=e(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:e(async()=>{if(!r)return;let e=u.filter(e=>{let t=n[e];return t!=null&&String(t).trim()!==``});if(e.length===0)return;s(`testing`);let t={};for(let n of e)t[n]={status:`probing`};l(t);let i=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await r(e,n[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of i)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`)},[r,u,n]),clearProbeResult:f}}n();function Me(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(...Me(n.fields));return t}function Ne(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Pe(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Pe(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Fe(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Ie({open:t,integrationId:n,addonId:l,onClose:d}){let{t:f}=Z(),p=a(),[m,h]=o({}),[g,_]=o(!1),[v,y]=o(null),[x,S]=o(Fe),C=U({addonId:l},{enabled:t}),w=C.data?.deviceType??null,T=K({addonId:l,type:w??ye.Camera},{enabled:t&&C.isSuccess&&w!==null}),E=T.data??null;c(()=>{t&&(h(E?Pe(E.sections.flatMap(e=>e.fields)):{}),S(Fe()),_(!1),y(null))},[t,n,E]);let D=i(()=>({...m,_probeRequestId:x}),[m,x]),O=F({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),k=b(),A=e(async(e,t)=>{_(!0);let n=await k.mutateAsync({addonId:l,type:w??ye.Camera,key:e,value:t,formValues:D});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Ne(e[i])&&!Ne(a)&&(r[i]=a,t=!0);return t?r:e}),n},[k,l,D,w]),{testAllStatus:j,hasProbeFields:M,probeResults:N,handleTestAll:P,clearProbeResult:I}=je(E??{sections:[]},m,A);async function L(e){y(null);try{await O.mutateAsync({addonId:l,type:w??ye.Camera,config:m,integrationId:n}),e?h(E?Pe(E.sections.flatMap(e=>e.fields)):{}):d()}catch(e){y(e instanceof Error?e.message:String(e))}}if(!t)return null;let R=Me((E?.sections??[]).flatMap(e=>e.fields)).filter(e=>Ne(m[e])),z=R.length===0,B=C.isLoading||w!==null&&T.isLoading,V=C.isError||C.isSuccess&&w===null||T.isError||T.isSuccess&&E===null;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:d}),r(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:f(`integrations.addDevice`)}),s(`button`,{onClick:d,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:s(q,{className:`h-4 w-4`})})]}),s(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:B?s(`div`,{className:`flex items-center justify-center py-8`,children:s(W,{className:`h-5 w-5 animate-spin text-primary`})}):V?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[s(X,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`space-y-1`,children:[s(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,s(`span`,{className:`font-mono`,children:l}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):s(xe,{schema:E,values:m,onChange:h,onTestField:A,probeResults:N,onClearProbe:I})}),!V&&!B&&r(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[r(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[r(`span`,{className:`flex items-center gap-2`,children:[s(ee,{className:`h-3.5 w-3.5`}),`Test logs`,s(`span`,{className:`font-mono text-[9px] opacity-60`,children:x.slice(0,14)})]}),s(u,{className:`h-3.5 w-3.5 transition-transform ${g?`rotate-180`:``}`})]}),g&&s(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:s(ge,{addonId:l,requestId:x,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!V&&!B&&(v||R.length>0)&&s(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(X,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-[11px] text-destructive`,children:v||`Required: ${R.join(`, `)}`})]})}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:d,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`)}),!V&&M&&r(`button`,{type:`button`,onClick:P,disabled:j===`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:[j===`testing`?s(W,{className:`h-3.5 w-3.5 animate-spin`}):s(fe,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:()=>L(!0),disabled:V||!z||O.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`)}),s(`button`,{onClick:()=>L(!1),disabled:V||!z||O.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:O.isPending?f(`integrations.saving`):f(`integrations.save`)})]})]})]})]})}var Le=1500;function $({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=Z(),o=C(),c=(S({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Le:!1}).data??[]).find(e=>e.jobId===n);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&&i();let f=[`${u}/${c.total} ${a(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&f.push(`${c.adopted} ${a(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&f.push(`${c.alreadyAdopted} ${a(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&f.push(`${c.failed} ${a(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return r(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2`,children:[l?s(W,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?s(X,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?s(ue,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):s(R,{className:`h-3.5 w-3.5 text-primary shrink-0`}),s(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&s(`button`,{onClick:()=>o.mutate({jobId:n}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),s(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:s(`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(e=>r(`p`,{className:`text-[11px] text-destructive`,children:[e.childNativeId,`: `,e.error]},e.childNativeId))]})}function Re(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(` `)}n();var ze=`devices`,Be={id:ze,label:`Devices`,isDefault:!0},Ve=2e4,He=100;function Ue({addonId:n,integrationId:i,onClose:l}){let{t:u}=Z(),d=a(),[f,p]=o(new Set),[m,h]=o(new Set),[g,_]=o(new Map),[v,y]=o(null),{data:b}=me(),x=(b??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[S,C]=o(!0),w=j({addonId:n,integrationId:i}).data?.filters,k=w&&w.length>0?w:[Be],[A,ee]=o(k.find(e=>e.isDefault)?.id??(k.some(e=>e.id===ze)?ze:k[0].id)),N=A!==ze,P=D(),F=M({addonId:n,integrationId:i,page:1,pageSize:Ve,filter:A}),L=F.refetch,R=P.mutate,z=e(()=>{R({addonId:n,integrationId:i},{onSettled:()=>{L()}})},[R,n,i,L]),B=t(null);c(()=>{let e=`${n}::${i}`;B.current===e||F.isLoading||(B.current=e,(F.data?.candidates.length??0)===0&&z())},[n,i,F.isLoading,F.data,z]);let V=P.isPending,te=P.isError?P.error instanceof Error?P.error.message:String(P.error):null,ne=typeof P.data?.lastError==`string`&&P.data.lastError.length>0?P.data.lastError:null,H=F.data?.candidates??[],U=F.isError?F.error instanceof Error?F.error.message:String(F.error):null,G=T(),[K,re]=o(null),ie=e(e=>{e.alreadyAdopted||p(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),ae=e(e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),se=e((e,t)=>{_(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})},[]),ce=e(e=>{let t={};for(let n of e){let e=g.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[g]),ue=e(async()=>{y(null);let e=[...f];if(e.length!==0)try{let t=ce(e),{jobId:r}=await G.mutateAsync({addonId:n,integrationId:i,filter:A,childNativeIds:e,...t?{perCandidate:t}:{},...x?{importLocations:S}:{}});re(r),p(new Set),_(new Map)}catch(e){y(e instanceof Error?e.message:String(e))}},[f,ce,G,n,i,A,x,S]),de=t(null),fe=e(()=>{K===null||de.current===K||(de.current=K,L(),d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}))},[K,L,d]),pe=e(e=>{ee(e),p(new Set),h(new Set),_(new Map),y(null)},[]),J=f.size,Y=K!==null&&J===0&&!G.isPending;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:l}),r(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[r(`div`,{className:`min-w-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:u(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),s(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:u(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),r(`div`,{className:`flex items-center gap-3 shrink-0`,children:[x&&r(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[s(`input`,{type:`checkbox`,checked:S,onChange:e=>C(e.target.checked),className:`accent-primary`}),u(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),s(`button`,{onClick:l,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:s(q,{className:`h-4 w-4`})})]})]}),r(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(te??U??ne)&&H.length===0&&s(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(X,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`min-w-0`,children:[s(`p`,{className:`text-xs font-medium text-destructive`,children:u(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),s(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:te??U??ne})]})]})}),k.length>1&&s(We,{filters:k,activeFilter:A,onSelect:pe}),s(`div`,{className:`flex-1 min-h-0`,children:s(le,{mode:`generic`,items:H,pageSize:He,getKey:e=>e.childNativeId,getSearchText:Re,getFilterType:e=>e.type,filterOptions:O(),filterLabel:u(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:F.isLoading||V&&H.length===0,searchPlaceholder:u(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(te??U??ne)&&H.length===0?``:u(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:z,disabled:V,title:u(`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:[s(E,{className:`h-3.5 w-3.5 ${V?`animate-spin`:``}`}),u(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:u(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>s(Ge,{candidate:e,expandable:!N,expanded:m.has(e.childNativeId),onToggleExpand:()=>ae(e.childNativeId),adoptedLabel:u(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:u(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=I(e.type),n=t.icon;return r(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[s(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>s(`div`,{className:`flex items-center justify-end`,children:s(`button`,{onClick:()=>ie(e),disabled:e.alreadyAdopted,"aria-label":f.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${f.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:f.has(e.childNativeId)&&s(oe,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!N&&m.has(e.childNativeId),renderExpanded:N?void 0:e=>s(Ke,{candidate:e,hiddenChildIds:g.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>se(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:f.has(e.childNativeId)?`bg-primary/5`:``})})]}),v&&s(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(X,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-[11px] text-destructive`,children:v})]})}),K!==null&&s($,{addonId:n,integrationId:i,jobId:K,onFinished:fe}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[s(`div`,{}),r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:l,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:u(`integrations.cancel`,{defaultValue:`Cancel`})}),r(`button`,{onClick:Y?l:ue,disabled:!Y&&(J===0||G.isPending),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[G.isPending&&s(W,{className:`h-3.5 w-3.5 animate-spin`}),Y?u(`integrations.close`,{defaultValue:`Close`}):u(`integrations.addSelected`,{defaultValue:`Add selected`}),!Y&&J>0?` (${J})`:``]})]})]})]})]})}function We({filters:e,activeFilter:t,onSelect:n}){return s(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return s(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function Ge({candidate:e,expandable:t,expanded:n,onToggleExpand:i,adoptedLabel:a}){let o=(e.children??[]).length;return r(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&o>0?r(`button`,{type:`button`,onClick:i,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[s(n?u:d,{className:`h-3.5 w-3.5`}),o]}):s(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),s(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&s(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:a})]})}function Ke({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let i=e.children??[];return i.length===0?null:s(`div`,{className:`space-y-1 py-1`,children:i.map(e=>{let i=t.has(e.childNativeId),a=e.capabilities??[];return r(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${i?`opacity-50`:``}`,children:[s(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),a.length>0&&s(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:a.join(`, `)}),s(`button`,{onClick:()=>n(e.childNativeId),"aria-label":i?`Show child`:`Hide child`,title:i?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:s(i?f:x,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function qe(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...qe(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function Je(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>qe(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Ye(e){return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(`value`in e){let{value:t,...n}=e;return n}return e})}))}}function Xe({integrationId:e,addonId:t,name:n,kind:o,mode:c,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=Z(),m=a(),{data:h,isLoading:g}=se({id:e},{enabled:c===`account`||c===`broker`}),b=i(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:x,isLoading:S}=Y({addonId:t,nodeId:`hub`},{enabled:c===`account`}),C=i(()=>x?Ye(x):null,[x]),w=re(),T=(t,n)=>{w.mutate({id:e,settings:t,...n?{secretKeys:[...n]}:{}},{onSuccess:()=>{m.invalidateQueries(),f()}})};return s(_e,{open:!0,onOpenChange:e=>!e&&f(),children:r(_,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[s(y,{children:r(v,{children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]})}),s(A,{children:c===`broker`?l?r(`div`,{className:`space-y-3`,children:[s(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),b&&r(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,s(`span`,{className:`font-mono text-foreground-subtle`,children:b})]}),w.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[s(W,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):s(Oe,{kind:l,onResolved:e=>{T({brokerId:e})},onBack:f}),w.isError&&s(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):s(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):c===`account`?g||S?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[s(W,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):s(De,{addonId:t,configSchema:C,canTest:u,initialName:n,initialConfig:Je(C,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e,secretKeys:t})=>T(e,t),onBack:f}):s(G,{trpc:d,addonId:t,nodeId:`hub`,title:n})})]})})}function Ze(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}n();function Qe(){let{t}=Z(),{integrationId:n}=Se(),u=a(),d=Ce(),[f,m]=be(),b=l(),[x,S]=o(!1),[C,T]=o(!1),[E,D]=o(!1),[O,j]=o(!1),{data:M,isLoading:F}=H({id:n??``},{enabled:!!n}),{data:I}=Y({addonId:M?.addonId??``,nodeId:`hub`},{enabled:!!M?.addonId}),{data:R,isSuccess:U}=me(),G=i(()=>{let e=M?.addonId;return!e||!U?null:(R??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[R,M?.addonId,U]),{data:K}=te({}),re=i(()=>(K?.providers??[]).some(e=>e.addonId===M?.addonId),[K,M?.addonId]),q=G!==null,oe=M?.info?.fixed===!0,se=q?G===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),ue=i(()=>{let e=M?.addonId;return!e||!U?null:(R??[]).find(t=>t.addonId===e)?.brokerKind??null},[R,M?.addonId,U]),fe=i(()=>{let e=M?.addonId;return!e||!U?!1:(R??[]).find(t=>t.addonId===e)?.canTest===!0},[R,M?.addonId,U]),X=i(()=>{let e=M?.addonId;return!e||!U?null:(R??[]).find(t=>t.addonId===e)?.mode??null},[R,M?.addonId,U]);c(()=>{f.get(`add`)===`1`&&q&&(S(!0),m(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[f,q,m]);let ye=I!=null&&Array.isArray(I.sections)&&I.sections.some(e=>e.fields.length>0),{data:xe}=V({addonId:M?.addonId??``,nodeId:`hub`},{enabled:!!M?.addonId&&X!==`account`}),we=X!==null&&X!==`account`&&Ze(xe),De=i(()=>M?.addonId?[M.addonId]:[],[M?.addonId]),{data:Oe}=ae({projection:`slim`},{refetchInterval:3e4}),Q=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],je=ce({onMutate:async e=>{await u.cancelQueries({queryKey:Q});let t=u.getQueryData(Q);return t!=null&&u.setQueryData(Q,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&u.setQueryData(Q,r.previous)},onSettled:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Me=h({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]}),d(`/integrations`)}}),Ne=k({onSuccess:()=>{u.invalidateQueries({queryKey:[[`integrations`]]}),u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Pe=he({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=P({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=pe({onSuccess:()=>{u.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=i(()=>Oe??[],[Oe]),Re=i(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),ze=e(e=>Re.get(e)??null,[Re]),{data:Be}=de(void 0),Ve=i(()=>w(Be),[Be]),He=e(e=>d(`/devices/${String(e)}`),[d]),We=i(()=>{let e=M?.id;return e?$.filter(t=>{let n=Ve(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[$,M?.id,Ve]),Ge=i(()=>Be===void 0?null:N(We).length,[Be,We])??`…`;return F?r(`div`,{className:`p-4`,children:[s(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),s(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):M?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[s(ve,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},{label:M.name}]}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-3 min-w-0`,children:[s($e,{addonId:M.addonId}),r(`div`,{className:`min-w-0`,children:[s(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:M.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[M.addonId,` · `,Ge,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[re&&r(`button`,{onClick:()=>T(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the network for devices (incl. a different subnet)`,children:[s(z,{className:`h-3.5 w-3.5`}),`Scan network`]}),!oe&&r(`button`,{onClick:()=>S(!0),disabled:!q,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:se,children:[s(J,{className:`h-3.5 w-3.5`}),se]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${je.isPending?`opacity-60`:``} ${M.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[s(ne,{checked:M.enabled,onCheckedChange:e=>je.mutate({id:n,enabled:e}),disabled:je.isPending,"aria-label":M.enabled?`Disable integration`:`Enable integration`}),s(`span`,{className:`text-[11px] font-medium ${M.enabled?`text-success`:`text-foreground-subtle`}`,children:M.enabled?`Enabled`:`Disabled`}),je.isPending&&s(W,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),X!==`standalone`&&(ye||G===`device-adoption`)&&r(`button`,{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`,children:[s(g,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>j(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.logs`,{defaultValue:`View logs`}),children:[s(ee,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),s(ie,{label:`Restart`,icon:L,title:`Restart "${M.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ge} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Ne.isPending,action:()=>Ne.mutateAsync({addonId:M.addonId})}),!oe&&n&&s(ie,{label:t(`integrations.delete`,{defaultValue:`Delete`}),icon:p,title:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:M.name,count:Ge}),confirmLabel:t(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Me.isPending,action:()=>Me.mutateAsync({id:n})})]})]}),we&&s(Te,{nodeId:null,addonIds:De,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),s(le,{context:`integration-detail`,devices:$,trpc:b.trpcClient,integrationOf:Ve,forceIntegrationId:M.id,urlScope:`root`,lsKey:`integration-detail:${M.addonId}`,resolveIntegrationIcon:Ee,resolveParent:ze,onNavigate:He,batchActions:{remove:Pe.mutate,disable:Fe.mutate,enable:Le.mutate},...oe?{}:{onDeleteDevice:e=>Pe.mutate({deviceId:e.id})}}),x&&n&&G===`device-adoption`&&s(Ue,{addonId:M.addonId,integrationId:n,onClose:()=>S(!1)}),x&&n&&G===`device-provider`&&s(Ie,{open:x,integrationId:n,addonId:M.addonId,onClose:()=>S(!1)}),C&&M&&s(ke,{open:C,scope:{addonId:M.addonId,label:M.name},onClose:()=>T(!1)}),E&&n&&G!==null&&X!==null&&s(Xe,{integrationId:n,addonId:M.addonId,name:M.name,kind:G,mode:X,brokerKind:ue,canTest:fe,trpc:b.trpcClient,onClose:()=>D(!1)}),O&&s(_e,{open:!0,onOpenChange:e=>!e&&j(!1),children:r(_,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[s(y,{className:`mb-0`,children:r(v,{className:`flex items-center gap-2 min-w-0`,children:[s(ee,{className:`h-4 w-4 text-primary shrink-0`}),s(`span`,{className:`truncate`,children:M.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[M.addonId,n?` · ${n}`:``]})]})}),s(A,{className:`min-h-0 overflow-hidden p-0`,children:s(ge,{addonId:M.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})})]}):r(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[s(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:s(Ae,{className:`h-6 w-6 text-foreground-subtle`})}),r(`div`,{className:`space-y-1 max-w-sm`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),s(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),r(`button`,{onClick:()=>d(`/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:[s(B,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function $e({addonId:e}){let t=we(e),[n,r]=o(!1);return!t||n?null:s(`img`,{src:t,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:()=>r(!0)})}export{Qe as IntegrationDetailPage};
@@ -1 +1 @@
1
- import{Q as e,S as t,W as n,b as r,o as i,q 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-DhP-Lgiq.js";import{st as s}from"./player-overlays-B7T46vDu.js";import{Cn as c,Dn as l,En as u,G as d,Ii as f,In as p,K as m,Nn as h,Sn as g,Sr as _,Xu as v,di as y,ed as b,fi as ee,gd as x,id as S,li as C,mi as w,oi as T,pd as E,pi as te,qn as ne,si as re,su as ie,td as ae,tr as D,ui as O,wn as k,xn as A,zu as j}from"./src-BTQcUQJz.js";import{t as M}from"./monitor-smartphone-CiL6wFjy.js";import{Cr as N,Nt as P,tr as F}from"./client-BBcQuaON.js";import{I,Z as L}from"./index-BlaisiEj.js";import{t as R}from"./BrokerForm-B0-lyNPR.js";import{n as z,r as B,t as V}from"./AddonIntegrationBody-CLBlTXCr.js";e();var H=`kind`,U=`name`,W=`restore`,G=`restoreId`;function K(e){return{sections:[{id:`broker-identity`,title:`Broker`,columns:1,fields:[{type:`select`,key:H,label:`Kind`,options:e.map(e=>({value:e.key,label:e.label})),disabled:e.length<=1},{type:`text`,key:U,label:`Name`,placeholder:`My Home Assistant`,required:!0},{type:`boolean`,key:W,label:`Restore a broker that was removed, under its original id`,description:`Devices remember the broker id they were discovered under, so restoring the original id reconnects them instead of needing re-discovery. An id that is still in use is refused.`},{type:`text`,key:G,label:`Original broker id`,placeholder:`ha_004`,required:!0,showWhen:{field:W,equals:!0}}]}]}}function q(e){let t=t=>{let n=e[t];return typeof n==`string`?n.trim():``},n=t(H);if(n===``)return{ok:!1,problem:`Pick a kind.`};let r=t(U);if(r===``)return{ok:!1,problem:`Enter a name before saving.`};if(e.restore!==!0)return{ok:!0,identity:{kindKey:n,name:r,restoreId:null}};let i=t(G);return i===``?{ok:!1,problem:`Enter the original id, or turn restore off to create a new broker.`}:{ok:!0,identity:{kindKey:n,name:r,restoreId:i}}}var oe={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function J(e){return oe[e]??e}function se(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var ce={connected:`success`,connecting:`warning`,disconnected:`default`,"auth-failed":`danger`,unreachable:`danger`,error:`danger`};function le({status:e}){return o(D,{variant:ce[e],className:`text-[10px]`,children:e})}function ue(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function Y({title:e,subtitle:n,onClose:r,children:i}){return o(A,{open:!0,onOpenChange:e=>!e&&r(),children:t(c,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[t(u,{children:[o(l,{children:e}),n&&o(k,{children:n})]}),o(g,{className:`space-y-3 pr-1`,children:i})]})})}function de({kinds:e,onClose:r,onDone:s}){let c=i(),l=n(()=>K(e.map(e=>({key:X(e),label:e.label}))),[e]),[u,d]=a(()=>({[H]:X(e[0]),[U]:``,[W]:!1,[G]:``})),[f,p]=a(null),m=e.find(e=>X(e)===u.kind)??e[0],g=m?.kind??``,_=m?.addonId,v=T({onSuccess:()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]}),s()}}),y=e=>{let t=q(u);if(!t.ok){p(t.problem);return}p(null);let{name:n,restoreId:r}=t.identity;v.mutate({kind:g,name:n,settings:e,...r===null?{}:{id:r},..._===void 0?{}:{addonId:_}})};return t(Y,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:v.isPending?()=>{}:r,children:[o(I,{schema:l,values:u,onChange:d}),f!==null&&o(h,{message:f}),v.isError&&o(h,{message:v.error instanceof Error?v.error.message:String(v.error)}),g&&o(R,{kind:g,..._===void 0?{}:{addonId:_},onSubmit:y,onCancel:r,submitLabel:v.isPending?`Adding…`:`Add broker`,disabled:v.isPending},X(m))]})}function X(e){return e===void 0?``:`${e.addonId??``}::${e.kind}`}function fe({broker:e,onClose:r,onDone:a}){let s=i(),c=re({id:e.id,addonId:e.addonId}),l=te({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]}),s.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),a()}}),u=n(()=>{let e=c.data;return e&&typeof e==`object`?{...e}:{}},[c.data]);return o(Y,{title:`Edit ${e.name}`,subtitle:`${J(e.kind)} · ${e.id}`,onClose:l.isPending?()=>{}:r,children:c.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(x,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):c.isError?t(`div`,{className:`space-y-3`,children:[o(h,{message:`Failed to load settings: ${c.error instanceof Error?c.error.message:`Unknown error`}`}),o(`div`,{className:`flex justify-end`,children:o(p,{variant:`outline`,size:`sm`,onClick:r,children:`Close`})})]}):t(`div`,{className:`space-y-3`,children:[l.isError&&o(h,{message:l.error instanceof Error?l.error.message:String(l.error)}),o(R,{kind:e.kind,addonId:e.addonId,initialValues:u,onSubmit:t=>{l.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:r,submitLabel:l.isPending?`Saving…`:`Save`,disabled:l.isPending})]})})}function pe({broker:e,onEdit:n}){let r=i(),c=ne(),[l,u]=a(null),d=w({onSuccess:e=>u(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>u({ok:!1,error:e instanceof Error?e.message:String(e)})}),f=ee({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),m=async()=>{await c({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&f.mutate({id:e.id,addonId:e.addonId})};return t(`tr`,{className:`border-b border-border last:border-0`,children:[o(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),o(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:J(e.kind)}),t(`td`,{className:`px-3 py-2`,children:[o(le,{status:e.status}),l&&o(`span`,{className:`ml-2 text-[10px] ${l.ok?`text-success`:`text-danger`}`,children:l.ok?`OK`:l.error??`failed`})]}),o(`td`,{className:`px-3 py-2`,children:t(`div`,{className:`flex items-center justify-end gap-1.5`,children:[t(p,{variant:`outline`,size:`sm`,onClick:()=>d.mutate({id:e.id,addonId:e.addonId}),disabled:d.isPending,title:`Test connection`,children:[d.isPending?o(x,{className:`h-3 w-3 animate-spin`}):o(ie,{className:`h-3 w-3`}),`Test`]}),t(p,{variant:`outline`,size:`sm`,onClick:()=>n(e),title:`Edit`,children:[o(S,{className:`h-3 w-3`}),` Edit`]}),t(p,{variant:`outline`,size:`sm`,className:`border-danger/40 text-danger hover:bg-danger/10`,onClick:()=>{m()},disabled:f.isPending,title:`Delete`,children:[f.isPending?o(x,{className:`h-3 w-3 animate-spin`}):o(s,{className:`h-3 w-3`}),`Delete`]})]})})]})}function me({addonId:e}={}){let r=O({}),i=y(),s=n(()=>ue(r.data).filter(t=>e===void 0||t.addonId===e),[r.data,e]),[c,l]=a(!1),[u,d]=a(null),f=n(()=>{let t=new Map;for(let n of se(i.data))if(!(e!==void 0&&n.addonId!==e))for(let e of n.kinds)t.set(`${n.addonId}::${e.kind}`,{addonId:n.addonId,kind:e.kind,label:e.label});for(let e of s)[...t.values()].some(t=>t.kind===e.kind)||t.set(`::${e.kind}`,{kind:e.kind,label:J(e.kind)});return[...t.values()]},[s,i.data,e]);return t(`div`,{className:`space-y-3`,children:[o(`div`,{className:`flex items-center justify-end`,children:t(p,{variant:`primary`,size:`sm`,onClick:()=>l(!0),disabled:f.length===0,title:f.length===0?`No broker providers available`:void 0,children:[o(ae,{className:`h-3.5 w-3.5`}),` Add broker`]})}),o(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[o(`thead`,{children:t(`tr`,{className:`border-b border-border bg-background/50`,children:[o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),o(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),t(`tbody`,{children:[r.isLoading&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[o(x,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),r.isError&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,r.error instanceof Error?r.error.message:`Unknown error`]})}),!r.isLoading&&!r.isError&&s.length===0&&o(`tr`,{children:o(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`No brokers registered yet. Add one to publish device events for downstream automations.`})}),s.map(e=>o(pe,{broker:e,onEdit:d},e.id))]})]})}),c&&o(de,{kinds:f,onClose:()=>l(!1),onDone:()=>l(!1)}),u&&o(fe,{broker:u,onClose:()=>d(null),onDone:()=>d(null)})]})}function he(e){if(typeof e==`string`)return e;if(typeof e==`object`&&e){let t=e.name;if(typeof t==`string`)return t}return null}function Z(e){let t=e,n=t?.manifest;if(n?.id===void 0)return null;let r=(n.capabilities??[]).map(he).filter(e=>e!==null);return{addonId:n.id,displayName:n.packageDisplayName??n.name??n.id,capNames:r,processState:t?.process?.state??null}}function ge(e,t){return Object.entries(e).filter(([,e])=>e===t).map(([e])=>e)}function _e(e,t){return t.find(t=>e.capNames.includes(t))??null}function Q(e){switch(e){case`running`:return{state:`ok`,label:`running`};case`crashed`:case`failed`:return{state:`error`,label:e};case`stopped`:case`disabled`:return{state:`off`,label:`stopped`};default:return{state:`unknown`,label:e??`unknown`}}}e();var $=1e4,ve=[{kind:`device-export`,label:`Device export`,icon:j,installLabel:`Add export`},{kind:`email`,label:`Email`,icon:E,installLabel:`Add email provider`},{kind:`broker`,label:`Message brokers`,icon:v,installLabel:`Add broker addon`}];function ye(){let e=_(void 0,{refetchInterval:$}),i=L();return o(B,{icon:b,title:`Connectivity`,subtitle:`External systems this hub talks to — device exporters, email relays and message brokers.`,groups:n(()=>{let n=(e.data??[]).map(Z).filter(e=>e!==null);return ve.map(e=>{let a=ge(P,e.kind),s=n.flatMap(n=>{let s=_e(n,a);if(s===null)return[];let c=Q(n.processState);return[{id:n.addonId,name:n.displayName,fallbackIcon:e.icon,state:c.state,stateLabel:c.label,render:()=>o(V,{addonId:n.addonId,displayName:n.displayName,capName:s,isActive:n.processState===`running`,badges:t(r,{children:[o(xe,{processState:n.processState}),o(Se,{kind:e.kind,addonId:n.addonId})]}),lead:e.kind===`device-export`?o(m,{addonId:n.addonId}):void 0,panels:be(e.kind,n.addonId,e=>i(`/devices/${e}`))})}]});return{id:e.kind,label:e.label,entries:s,install:{capability:a[0]??e.kind,label:e.installLabel}}})},[e.data,i]),isLoading:e.isLoading,emptyTitle:`No external systems installed`,emptyDescription:`Install an export, email or broker addon to connect this hub to another system.`,legacyGroupParam:`tab`})}function be(e,t,n){return e===`device-export`?[{id:`devices`,title:`Devices`,icon:M,placement:`end`,content:o(d,{addonId:t,onOpenDevice:n,showSetup:!1})}]:e===`broker`?[{id:`connections`,title:`Connections`,icon:v,content:o(me,{addonId:t})}]:[]}function xe({processState:e}){let{state:t,label:n}=Q(e);return o(D,{variant:t===`ok`?`success`:t===`error`?`danger`:`default`,className:`${z} capitalize`,children:n})}function Se({kind:e,addonId:t}){return e===`broker`?o(Ce,{addonId:t}):e===`device-export`?o(we,{addonId:t}):null}function Ce({addonId:e}){let{data:t}=C({addonId:e},{refetchInterval:$,retry:!1}),n=N.safeParse(t);if(!n.success)return null;let{brokerCount:r,connectedCount:i}=n.data;return o(D,{variant:`info`,className:z,children:`${r} connection${r===1?``:`s`}${i>0?` · ${i} connected`:``}`})}function we({addonId:e}){let{data:t}=f({addonId:e},{refetchInterval:$,retry:!1}),n=F.safeParse(t);if(!n.success)return null;let{linkState:r,exposedDeviceCount:i}=n.data;return o(D,{variant:r===`linked`?`success`:r===`error`?`danger`:`default`,className:z,children:`${r} · ${i} exposed`})}export{ye as IntegrationsPage};
1
+ import{Q as e,S as t,W as n,b as r,o as i,q 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-DhP-Lgiq.js";import{st as s}from"./player-overlays-B7T46vDu.js";import{Cn as c,Dn as l,En as u,G as d,Ii as f,In as p,K as m,Nn as h,Sn as g,Sr as _,Xu as v,di as y,ed as b,fi as ee,gd as x,id as S,li as C,mi as w,oi as T,pd as E,pi as te,qn as ne,si as re,su as ie,td as ae,tr as D,ui as O,wn as k,xn as A,zu as j}from"./src-QOexoM_4.js";import{t as M}from"./monitor-smartphone-CiL6wFjy.js";import{Cr as N,Nt as P,tr as F}from"./client-BBcQuaON.js";import{I,Z as L}from"./index-Wd9AuQ7z.js";import{t as R}from"./BrokerForm-CUEA6_x3.js";import{n as z,r as B,t as V}from"./AddonIntegrationBody-WZ-GmbiU.js";e();var H=`kind`,U=`name`,W=`restore`,G=`restoreId`;function K(e){return{sections:[{id:`broker-identity`,title:`Broker`,columns:1,fields:[{type:`select`,key:H,label:`Kind`,options:e.map(e=>({value:e.key,label:e.label})),disabled:e.length<=1},{type:`text`,key:U,label:`Name`,placeholder:`My Home Assistant`,required:!0},{type:`boolean`,key:W,label:`Restore a broker that was removed, under its original id`,description:`Devices remember the broker id they were discovered under, so restoring the original id reconnects them instead of needing re-discovery. An id that is still in use is refused.`},{type:`text`,key:G,label:`Original broker id`,placeholder:`ha_004`,required:!0,showWhen:{field:W,equals:!0}}]}]}}function q(e){let t=t=>{let n=e[t];return typeof n==`string`?n.trim():``},n=t(H);if(n===``)return{ok:!1,problem:`Pick a kind.`};let r=t(U);if(r===``)return{ok:!1,problem:`Enter a name before saving.`};if(e.restore!==!0)return{ok:!0,identity:{kindKey:n,name:r,restoreId:null}};let i=t(G);return i===``?{ok:!1,problem:`Enter the original id, or turn restore off to create a new broker.`}:{ok:!0,identity:{kindKey:n,name:r,restoreId:i}}}var oe={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function J(e){return oe[e]??e}function se(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var ce={connected:`success`,connecting:`warning`,disconnected:`default`,"auth-failed":`danger`,unreachable:`danger`,error:`danger`};function le({status:e}){return o(D,{variant:ce[e],className:`text-[10px]`,children:e})}function ue(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function Y({title:e,subtitle:n,onClose:r,children:i}){return o(A,{open:!0,onOpenChange:e=>!e&&r(),children:t(c,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[t(u,{children:[o(l,{children:e}),n&&o(k,{children:n})]}),o(g,{className:`space-y-3 pr-1`,children:i})]})})}function de({kinds:e,onClose:r,onDone:s}){let c=i(),l=n(()=>K(e.map(e=>({key:X(e),label:e.label}))),[e]),[u,d]=a(()=>({[H]:X(e[0]),[U]:``,[W]:!1,[G]:``})),[f,p]=a(null),m=e.find(e=>X(e)===u.kind)??e[0],g=m?.kind??``,_=m?.addonId,v=T({onSuccess:()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]}),s()}}),y=e=>{let t=q(u);if(!t.ok){p(t.problem);return}p(null);let{name:n,restoreId:r}=t.identity;v.mutate({kind:g,name:n,settings:e,...r===null?{}:{id:r},..._===void 0?{}:{addonId:_}})};return t(Y,{title:`Add broker`,subtitle:`Register a message broker for exporters and automations.`,onClose:v.isPending?()=>{}:r,children:[o(I,{schema:l,values:u,onChange:d}),f!==null&&o(h,{message:f}),v.isError&&o(h,{message:v.error instanceof Error?v.error.message:String(v.error)}),g&&o(R,{kind:g,..._===void 0?{}:{addonId:_},onSubmit:y,onCancel:r,submitLabel:v.isPending?`Adding…`:`Add broker`,disabled:v.isPending},X(m))]})}function X(e){return e===void 0?``:`${e.addonId??``}::${e.kind}`}function fe({broker:e,onClose:r,onDone:a}){let s=i(),c=re({id:e.id,addonId:e.addonId}),l=te({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]}),s.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:e.id,addonId:e.addonId}}]}),a()}}),u=n(()=>{let e=c.data;return e&&typeof e==`object`?{...e}:{}},[c.data]);return o(Y,{title:`Edit ${e.name}`,subtitle:`${J(e.kind)} · ${e.id}`,onClose:l.isPending?()=>{}:r,children:c.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(x,{className:`h-3.5 w-3.5 animate-spin`}),` Loading settings…`]}):c.isError?t(`div`,{className:`space-y-3`,children:[o(h,{message:`Failed to load settings: ${c.error instanceof Error?c.error.message:`Unknown error`}`}),o(`div`,{className:`flex justify-end`,children:o(p,{variant:`outline`,size:`sm`,onClick:r,children:`Close`})})]}):t(`div`,{className:`space-y-3`,children:[l.isError&&o(h,{message:l.error instanceof Error?l.error.message:String(l.error)}),o(R,{kind:e.kind,addonId:e.addonId,initialValues:u,onSubmit:t=>{l.mutate({id:e.id,settings:t,addonId:e.addonId})},onCancel:r,submitLabel:l.isPending?`Saving…`:`Save`,disabled:l.isPending})]})})}function pe({broker:e,onEdit:n}){let r=i(),c=ne(),[l,u]=a(null),d=w({onSuccess:e=>u(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>u({ok:!1,error:e instanceof Error?e.message:String(e)})}),f=ee({onSuccess:()=>{r.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),m=async()=>{await c({title:`Delete broker`,message:`Delete broker "${e.name}"? Integrations that depend on it will stop working.`,confirmLabel:`Delete`,variant:`danger`})&&f.mutate({id:e.id,addonId:e.addonId})};return t(`tr`,{className:`border-b border-border last:border-0`,children:[o(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:e.name}),o(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:J(e.kind)}),t(`td`,{className:`px-3 py-2`,children:[o(le,{status:e.status}),l&&o(`span`,{className:`ml-2 text-[10px] ${l.ok?`text-success`:`text-danger`}`,children:l.ok?`OK`:l.error??`failed`})]}),o(`td`,{className:`px-3 py-2`,children:t(`div`,{className:`flex items-center justify-end gap-1.5`,children:[t(p,{variant:`outline`,size:`sm`,onClick:()=>d.mutate({id:e.id,addonId:e.addonId}),disabled:d.isPending,title:`Test connection`,children:[d.isPending?o(x,{className:`h-3 w-3 animate-spin`}):o(ie,{className:`h-3 w-3`}),`Test`]}),t(p,{variant:`outline`,size:`sm`,onClick:()=>n(e),title:`Edit`,children:[o(S,{className:`h-3 w-3`}),` Edit`]}),t(p,{variant:`outline`,size:`sm`,className:`border-danger/40 text-danger hover:bg-danger/10`,onClick:()=>{m()},disabled:f.isPending,title:`Delete`,children:[f.isPending?o(x,{className:`h-3 w-3 animate-spin`}):o(s,{className:`h-3 w-3`}),`Delete`]})]})})]})}function me({addonId:e}={}){let r=O({}),i=y(),s=n(()=>ue(r.data).filter(t=>e===void 0||t.addonId===e),[r.data,e]),[c,l]=a(!1),[u,d]=a(null),f=n(()=>{let t=new Map;for(let n of se(i.data))if(!(e!==void 0&&n.addonId!==e))for(let e of n.kinds)t.set(`${n.addonId}::${e.kind}`,{addonId:n.addonId,kind:e.kind,label:e.label});for(let e of s)[...t.values()].some(t=>t.kind===e.kind)||t.set(`::${e.kind}`,{kind:e.kind,label:J(e.kind)});return[...t.values()]},[s,i.data,e]);return t(`div`,{className:`space-y-3`,children:[o(`div`,{className:`flex items-center justify-end`,children:t(p,{variant:`primary`,size:`sm`,onClick:()=>l(!0),disabled:f.length===0,title:f.length===0?`No broker providers available`:void 0,children:[o(ae,{className:`h-3.5 w-3.5`}),` Add broker`]})}),o(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[o(`thead`,{children:t(`tr`,{className:`border-b border-border bg-background/50`,children:[o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Name`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Kind`}),o(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Status`}),o(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:`Actions`})]})}),t(`tbody`,{children:[r.isLoading&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[o(x,{className:`inline h-4 w-4 animate-spin`}),` Loading brokers…`]})}),r.isError&&o(`tr`,{children:t(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[`Failed to load brokers:`,` `,r.error instanceof Error?r.error.message:`Unknown error`]})}),!r.isLoading&&!r.isError&&s.length===0&&o(`tr`,{children:o(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`No brokers registered yet. Add one to publish device events for downstream automations.`})}),s.map(e=>o(pe,{broker:e,onEdit:d},e.id))]})]})}),c&&o(de,{kinds:f,onClose:()=>l(!1),onDone:()=>l(!1)}),u&&o(fe,{broker:u,onClose:()=>d(null),onDone:()=>d(null)})]})}function he(e){if(typeof e==`string`)return e;if(typeof e==`object`&&e){let t=e.name;if(typeof t==`string`)return t}return null}function Z(e){let t=e,n=t?.manifest;if(n?.id===void 0)return null;let r=(n.capabilities??[]).map(he).filter(e=>e!==null);return{addonId:n.id,displayName:n.packageDisplayName??n.name??n.id,capNames:r,processState:t?.process?.state??null}}function ge(e,t){return Object.entries(e).filter(([,e])=>e===t).map(([e])=>e)}function _e(e,t){return t.find(t=>e.capNames.includes(t))??null}function Q(e){switch(e){case`running`:return{state:`ok`,label:`running`};case`crashed`:case`failed`:return{state:`error`,label:e};case`stopped`:case`disabled`:return{state:`off`,label:`stopped`};default:return{state:`unknown`,label:e??`unknown`}}}e();var $=1e4,ve=[{kind:`device-export`,label:`Device export`,icon:j,installLabel:`Add export`},{kind:`email`,label:`Email`,icon:E,installLabel:`Add email provider`},{kind:`broker`,label:`Message brokers`,icon:v,installLabel:`Add broker addon`}];function ye(){let e=_(void 0,{refetchInterval:$}),i=L();return o(B,{icon:b,title:`Connectivity`,subtitle:`External systems this hub talks to — device exporters, email relays and message brokers.`,groups:n(()=>{let n=(e.data??[]).map(Z).filter(e=>e!==null);return ve.map(e=>{let a=ge(P,e.kind),s=n.flatMap(n=>{let s=_e(n,a);if(s===null)return[];let c=Q(n.processState);return[{id:n.addonId,name:n.displayName,fallbackIcon:e.icon,state:c.state,stateLabel:c.label,render:()=>o(V,{addonId:n.addonId,displayName:n.displayName,capName:s,isActive:n.processState===`running`,badges:t(r,{children:[o(xe,{processState:n.processState}),o(Se,{kind:e.kind,addonId:n.addonId})]}),lead:e.kind===`device-export`?o(m,{addonId:n.addonId}):void 0,panels:be(e.kind,n.addonId,e=>i(`/devices/${e}`))})}]});return{id:e.kind,label:e.label,entries:s,install:{capability:a[0]??e.kind,label:e.installLabel}}})},[e.data,i]),isLoading:e.isLoading,emptyTitle:`No external systems installed`,emptyDescription:`Install an export, email or broker addon to connect this hub to another system.`,legacyGroupParam:`tab`})}function be(e,t,n){return e===`device-export`?[{id:`devices`,title:`Devices`,icon:M,placement:`end`,content:o(d,{addonId:t,onOpenDevice:n,showSetup:!1})}]:e===`broker`?[{id:`connections`,title:`Connections`,icon:v,content:o(me,{addonId:t})}]:[]}function xe({processState:e}){let{state:t,label:n}=Q(e);return o(D,{variant:t===`ok`?`success`:t===`error`?`danger`:`default`,className:`${z} capitalize`,children:n})}function Se({kind:e,addonId:t}){return e===`broker`?o(Ce,{addonId:t}):e===`device-export`?o(we,{addonId:t}):null}function Ce({addonId:e}){let{data:t}=C({addonId:e},{refetchInterval:$,retry:!1}),n=N.safeParse(t);if(!n.success)return null;let{brokerCount:r,connectedCount:i}=n.data;return o(D,{variant:`info`,className:z,children:`${r} connection${r===1?``:`s`}${i>0?` · ${i} connected`:``}`})}function we({addonId:e}){let{data:t}=f({addonId:e},{refetchInterval:$,retry:!1}),n=F.safeParse(t);if(!n.success)return null;let{linkState:r,exposedDeviceCount:i}=n.data;return o(D,{variant:r===`linked`?`success`:r===`error`?`danger`:`default`,className:z,children:`${r} · ${i} exposed`})}export{ye as IntegrationsPage};
@@ -1 +1 @@
1
- import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as l,at as u,gt as d,ht as f}from"./player-overlays-B7T46vDu.js";import{Bu as p,J as m,M as h,Qa as ee,Qi as g,Vi as te,Wl as _,X as v,Yu as y,Zu as b,ed as x,gd as ne,iu as S,la as re,nf as C,q as w,r as T,ro as E,td as D,to as O,ur as k}from"./src-BTQcUQJz.js";import{t as A}from"./useTranslation-Bc5yH9V9.js";import{$ as ie,K as j,Z as M}from"./index-BlaisiEj.js";import{t as N}from"./AdminPage-BSFohA3i.js";import"./useEventInvalidation-BZYpYRsM.js";import{t as ae}from"./device-integration-icon-ByZPIc_Q.js";import{n as P,r as F,t as I}from"./ScanNetworkModal-DXODoRu9.js";t();function L(e=!0){c(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}t();function R(e,t){let[n,r]=o(!1);return c(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}t();function z({providerId:e,onImport:t,onSkip:r}){let{t:i}=A(),[a,u]=o(new Set),d=g(),f=d.data,p=d.isPending||!d.data&&!d.isError;c(()=>{e&&(d.isPending||d.data||d.mutate({addonId:e}))},[e,d]);function m(e){u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(p)return n(`div`,{className:`flex flex-col items-center py-12`,children:[s(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:i(`integrations.searchingDevices`)})]});let h=f??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:h.length>0?i(`integrations.foundDevices`,{count:h.length}):i(`integrations.noDevicesFound`)}),h.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:h.map(e=>{let t=e.stableId,r=e.suggestedName??t,o=a.has(t),c=e.alreadyOnboarded===!0;return n(`button`,{onClick:()=>{c||m(t)},disabled:c,title:c?i(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??r}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${c?`border-border bg-surface opacity-60 cursor-not-allowed`:o?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[s(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${o&&!c?`border-primary bg-primary`:`border-border`}`,children:o&&!c&&s(C,{className:`h-3 w-3 text-primary-foreground`})}),s(l,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),s(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r}),c&&s(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:i(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},t)})}),n(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.skip`)}),h.length>0&&n(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[i(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}function B({onSelect:e,onClose:t,pendingAddonId:r=null}){let{t:i}=A(),a=M(),{data:o,isLoading:c}=O();if(c)return s(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let l=r!==null;return n(`div`,{className:`space-y-2`,children:[(o??[]).map(o=>{let c=o.instanceMode===`unique`&&o.existingInstances.length>0,u=r===o.addonId,d=l;return n(`button`,{disabled:d,onClick:()=>{if(!d)if(c){let e=o.existingInstances[0].id;t(),a(`/integrations/${e}`)}else e(o.addonId,o.instanceMode,o.discoveryMode,o.name,o.kind,o.brokerKind,o.mode,o.canTest)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[o.iconUrl?s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`img`,{src:o.iconUrl,alt:``,className:`h-5 w-5`})}):s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`span`,{className:`text-sm`,style:{color:o.color},children:`◉`})}),n(`div`,{className:`flex-1 min-w-0`,children:[s(`p`,{className:`text-xs font-semibold text-foreground`,children:o.name}),o.description&&s(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:o.description})]}),u?s(ne,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):c?n(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[s(p,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(f,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},o.addonId)}),(o??[]).length===0&&s(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:i(`integrations.noProviders`)})]})}t();function oe(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var V=2e4;function H({open:e,onClose:t}){let{t:l}=A(),u=M(),d=a(),[f,p]=o(`picker`),[m,h]=o(null),[_,v]=o(null),[y,b]=o(`manual`),[x,re]=o(null),[C,w]=o(``),[T,E]=o(null),[D,O]=o(null),[ie,j]=o(!1),{data:N}=k({addonId:m??``,nodeId:`hub`},{enabled:m!=null}),ae=r(()=>N?oe(N):null,[N]),I=ee({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),H=g(),U=H.data;c(()=>{f!==`discovery`||!_||!m||H.isPending||H.data||H.mutate({addonId:m})},[f,_,m,H]);let se=te({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function ce(e,t,n,r,i,a,o,s){if(!I.isPending){if(h(e),j(s),b(n),w(r),O(null),o===`broker`){if(!a){O(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}re(a),p(`broker`);return}if(o===`account`){p(`config`);return}W(e,r)}}async function W(e,n){try{let r=await I.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),u(`/integrations/${r.id}?add=1`)}catch{}}async function G(e){if(m)try{let t=await I.mutateAsync({addonId:m,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});v(t.id),y===`auto`||y===`both`?p(`discovery`):q(t.id)}catch{}}async function K(e){if(m)try{let t=await I.mutateAsync({addonId:m,name:C,settings:{brokerId:e}});E(t.id),v(t.id),q(t.id)}catch{}}async function le(e){if(m){for(let t of e){let e=U?.find(e=>e.stableId===t);e&&await se.mutateAsync({addonId:m,candidate:e,...T===null?{}:{integrationId:T}})}q()}}function q(e){let n=e??_??m;t(),J(),n&&u(`/integrations/${n}`)}function J(){p(`picker`),h(null),v(null),b(`manual`),re(null),w(``),E(null),O(null),j(!1)}function Y(){t(),J()}L(e);let X=I.isPending,Z=R(X,V);if(!e)return null;let ue={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Q=X?m:null,$=I.error,de=X&&!Z;return n(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),n(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:ue[f]}),s(`button`,{onClick:Y,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:s(S,{className:`h-4 w-4`})})]}),n(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),f===`picker`&&n(i,{children:[D&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:D}),s(B,{onSelect:ce,onClose:Y,pendingAddonId:Q})]}),f===`config`&&m&&s(P,{addonId:m,configSchema:ae??null,canTest:ie,onSave:G,onBack:()=>p(`picker`)}),f===`broker`&&x&&s(F,{kind:x,onResolved:e=>{K(e)},onBack:()=>p(`picker`)}),f===`discovery`&&_&&s(z,{providerId:_,onImport:le,onSkip:q})]}),X&&n(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[s(ne,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&n(i,{children:[s(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),s(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function U({integration:e,expanded:t,onToggleExpand:r}){return n(`div`,{className:`flex items-center gap-2.5`,children:[s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:s(t?d:f,{className:`h-3.5 w-3.5`})}),s(j,{type:e.addonId,size:`sm`}),n(`div`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function se(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>s(U,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>s(h,{status:e.status})}]}t();function ce(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var W=`expand`;function G(){let{t}=A(),a=M(),c=u(),[l]=ie(),[d,f]=o(!1),p=e(()=>f(!0),[]),h=e(()=>f(!1),[]),[ee,g]=o(!1),te=e(()=>g(!0),[]),ne=e(()=>g(!1),[]);T([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),T([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:S,isLoading:C,refetch:O}=E(void 0),{data:k,isLoading:j,refetch:P}=re({projection:`slim`}),F=r(()=>k??[],[k]),L=r(()=>S??[],[S]),R=r(()=>{let e=new Map;for(let t of F)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[F]),z=r(()=>m(S),[S]),B=r(()=>{let e=new Map;for(let t of v(F)){let n=z(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[F,z]),oe=r(()=>L.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:ce(e),deviceCount:B.get(e.id)??0})),[L,B]),V=l.get(W),U=e(e=>{let t=new URLSearchParams(window.location.search);t.get(W)===e?t.delete(W):t.set(W,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),G=e(e=>a(`/integrations/${e.id}`),[a]),K=e(e=>R.get(e)??null,[R]),le=e(e=>a(`/devices/${String(e)}`),[a]),q=e(e=>s(w,{context:`integration-detail`,devices:F,trpc:c.trpcClient,integrationOf:z,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:ae,resolveParent:K,onNavigate:le}),[F,c.trpcClient,z,K,le]),J=e(e=>V===e.addonId,[V]),Y=r(()=>se({isExpanded:J,onToggleExpand:U}),[J,U]),X=e(e=>`${e.name} ${e.addonId}`,[]),Z=e(e=>e.addonId,[]),ue=e(()=>{O(),P()},[O,P]),Q=C||j,$=L.length>0;return n(N,{icon:x,title:t(`nav.integrations`,`Integrations`),actions:n(i,{children:[s(`button`,{onClick:ue,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:s(y,{className:_(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:te,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[s(b,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:p,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[s(D,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&s(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&n(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[s(`p`,{className:`text-sm`,children:`No integrations configured.`}),s(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&$&&s(w,{mode:`generic`,items:oe,getKey:Z,getSearchText:X,columns:Y,onRowClick:G,isExpanded:J,renderExpanded:q,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(H,{open:d,onClose:h}),s(I,{open:ee,onClose:ne})]})}export{G as IntegrationsPage};
1
+ import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as l,at as u,gt as d,ht as f}from"./player-overlays-B7T46vDu.js";import{Bu as p,J as m,M as h,Qa as ee,Qi as g,Vi as te,Wl as _,X as v,Yu as y,Zu as b,ed as x,gd as ne,iu as S,la as re,nf as C,q as w,r as T,ro as E,td as D,to as O,ur as k}from"./src-QOexoM_4.js";import{t as A}from"./useTranslation-Bc5yH9V9.js";import{$ as ie,K as j,Z as M}from"./index-Wd9AuQ7z.js";import{t as N}from"./AdminPage-BSFohA3i.js";import"./useEventInvalidation-PKbAt0O0.js";import{t as ae}from"./device-integration-icon-C6TnIOOf.js";import{n as P,r as F,t as I}from"./ScanNetworkModal-BcwSCus9.js";t();function L(e=!0){c(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}t();function R(e,t){let[n,r]=o(!1);return c(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}t();function z({providerId:e,onImport:t,onSkip:r}){let{t:i}=A(),[a,u]=o(new Set),d=g(),f=d.data,p=d.isPending||!d.data&&!d.isError;c(()=>{e&&(d.isPending||d.data||d.mutate({addonId:e}))},[e,d]);function m(e){u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(p)return n(`div`,{className:`flex flex-col items-center py-12`,children:[s(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:i(`integrations.searchingDevices`)})]});let h=f??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:h.length>0?i(`integrations.foundDevices`,{count:h.length}):i(`integrations.noDevicesFound`)}),h.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:h.map(e=>{let t=e.stableId,r=e.suggestedName??t,o=a.has(t),c=e.alreadyOnboarded===!0;return n(`button`,{onClick:()=>{c||m(t)},disabled:c,title:c?i(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??r}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${c?`border-border bg-surface opacity-60 cursor-not-allowed`:o?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[s(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${o&&!c?`border-primary bg-primary`:`border-border`}`,children:o&&!c&&s(C,{className:`h-3 w-3 text-primary-foreground`})}),s(l,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),s(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r}),c&&s(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:i(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},t)})}),n(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.skip`)}),h.length>0&&n(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[i(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}function B({onSelect:e,onClose:t,pendingAddonId:r=null}){let{t:i}=A(),a=M(),{data:o,isLoading:c}=O();if(c)return s(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let l=r!==null;return n(`div`,{className:`space-y-2`,children:[(o??[]).map(o=>{let c=o.instanceMode===`unique`&&o.existingInstances.length>0,u=r===o.addonId,d=l;return n(`button`,{disabled:d,onClick:()=>{if(!d)if(c){let e=o.existingInstances[0].id;t(),a(`/integrations/${e}`)}else e(o.addonId,o.instanceMode,o.discoveryMode,o.name,o.kind,o.brokerKind,o.mode,o.canTest)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[o.iconUrl?s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`img`,{src:o.iconUrl,alt:``,className:`h-5 w-5`})}):s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`span`,{className:`text-sm`,style:{color:o.color},children:`◉`})}),n(`div`,{className:`flex-1 min-w-0`,children:[s(`p`,{className:`text-xs font-semibold text-foreground`,children:o.name}),o.description&&s(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:o.description})]}),u?s(ne,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):c?n(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[s(p,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(f,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},o.addonId)}),(o??[]).length===0&&s(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:i(`integrations.noProviders`)})]})}t();function oe(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var V=2e4;function H({open:e,onClose:t}){let{t:l}=A(),u=M(),d=a(),[f,p]=o(`picker`),[m,h]=o(null),[_,v]=o(null),[y,b]=o(`manual`),[x,re]=o(null),[C,w]=o(``),[T,E]=o(null),[D,O]=o(null),[ie,j]=o(!1),{data:N}=k({addonId:m??``,nodeId:`hub`},{enabled:m!=null}),ae=r(()=>N?oe(N):null,[N]),I=ee({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),H=g(),U=H.data;c(()=>{f!==`discovery`||!_||!m||H.isPending||H.data||H.mutate({addonId:m})},[f,_,m,H]);let se=te({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function ce(e,t,n,r,i,a,o,s){if(!I.isPending){if(h(e),j(s),b(n),w(r),O(null),o===`broker`){if(!a){O(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}re(a),p(`broker`);return}if(o===`account`){p(`config`);return}W(e,r)}}async function W(e,n){try{let r=await I.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),u(`/integrations/${r.id}?add=1`)}catch{}}async function G(e){if(m)try{let t=await I.mutateAsync({addonId:m,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});v(t.id),y===`auto`||y===`both`?p(`discovery`):q(t.id)}catch{}}async function K(e){if(m)try{let t=await I.mutateAsync({addonId:m,name:C,settings:{brokerId:e}});E(t.id),v(t.id),q(t.id)}catch{}}async function le(e){if(m){for(let t of e){let e=U?.find(e=>e.stableId===t);e&&await se.mutateAsync({addonId:m,candidate:e,...T===null?{}:{integrationId:T}})}q()}}function q(e){let n=e??_??m;t(),J(),n&&u(`/integrations/${n}`)}function J(){p(`picker`),h(null),v(null),b(`manual`),re(null),w(``),E(null),O(null),j(!1)}function Y(){t(),J()}L(e);let X=I.isPending,Z=R(X,V);if(!e)return null;let ue={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Q=X?m:null,$=I.error,de=X&&!Z;return n(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),n(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:ue[f]}),s(`button`,{onClick:Y,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:s(S,{className:`h-4 w-4`})})]}),n(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),f===`picker`&&n(i,{children:[D&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:D}),s(B,{onSelect:ce,onClose:Y,pendingAddonId:Q})]}),f===`config`&&m&&s(P,{addonId:m,configSchema:ae??null,canTest:ie,onSave:G,onBack:()=>p(`picker`)}),f===`broker`&&x&&s(F,{kind:x,onResolved:e=>{K(e)},onBack:()=>p(`picker`)}),f===`discovery`&&_&&s(z,{providerId:_,onImport:le,onSkip:q})]}),X&&n(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[s(ne,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&n(i,{children:[s(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),s(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function U({integration:e,expanded:t,onToggleExpand:r}){return n(`div`,{className:`flex items-center gap-2.5`,children:[s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:s(t?d:f,{className:`h-3.5 w-3.5`})}),s(j,{type:e.addonId,size:`sm`}),n(`div`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function se(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>s(U,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>s(h,{status:e.status})}]}t();function ce(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var W=`expand`;function G(){let{t}=A(),a=M(),c=u(),[l]=ie(),[d,f]=o(!1),p=e(()=>f(!0),[]),h=e(()=>f(!1),[]),[ee,g]=o(!1),te=e(()=>g(!0),[]),ne=e(()=>g(!1),[]);T([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),T([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:S,isLoading:C,refetch:O}=E(void 0),{data:k,isLoading:j,refetch:P}=re({projection:`slim`}),F=r(()=>k??[],[k]),L=r(()=>S??[],[S]),R=r(()=>{let e=new Map;for(let t of F)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[F]),z=r(()=>m(S),[S]),B=r(()=>{let e=new Map;for(let t of v(F)){let n=z(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[F,z]),oe=r(()=>L.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:ce(e),deviceCount:B.get(e.id)??0})),[L,B]),V=l.get(W),U=e(e=>{let t=new URLSearchParams(window.location.search);t.get(W)===e?t.delete(W):t.set(W,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),G=e(e=>a(`/integrations/${e.id}`),[a]),K=e(e=>R.get(e)??null,[R]),le=e(e=>a(`/devices/${String(e)}`),[a]),q=e(e=>s(w,{context:`integration-detail`,devices:F,trpc:c.trpcClient,integrationOf:z,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:ae,resolveParent:K,onNavigate:le}),[F,c.trpcClient,z,K,le]),J=e(e=>V===e.addonId,[V]),Y=r(()=>se({isExpanded:J,onToggleExpand:U}),[J,U]),X=e(e=>`${e.name} ${e.addonId}`,[]),Z=e(e=>e.addonId,[]),ue=e(()=>{O(),P()},[O,P]),Q=C||j,$=L.length>0;return n(N,{icon:x,title:t(`nav.integrations`,`Integrations`),actions:n(i,{children:[s(`button`,{onClick:ue,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:s(y,{className:_(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:te,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[s(b,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:p,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[s(D,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&s(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&n(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[s(`p`,{className:`text-sm`,children:`No integrations configured.`}),s(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&$&&s(w,{mode:`generic`,items:oe,getKey:Z,getSearchText:X,columns:Y,onRowClick:G,isExpanded:J,renderExpanded:q,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(H,{open:d,onClose:h}),s(I,{open:ee,onClose:ne})]})}export{G as IntegrationsPage};
@@ -1,3 +1,3 @@
1
- import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o,z as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as c,gt as l,ht as u,st as d,vt as f}from"./player-overlays-B7T46vDu.js";import{Au as p,Bd as m,Bi as h,Cd as g,Cf as _,Cu as v,Da as y,Dt as b,Ea as x,Et as S,Eu as C,Ft as w,Gd as T,Gl as E,Ku as D,L as O,Ld as k,Mu as A,Na as j,Nd as M,Oa as ee,Pd as N,Pu as P,Rd as F,Ru as I,Sa as te,Su as ne,Ta as re,Tf as L,Tu as R,Uu as z,Xd as B,Yd as ie,Yu as ae,Zu as V,_f as oe,ad as se,ba as ce,bu as H,cf as le,da as ue,df as de,fa as fe,fd as U,gf as pe,id as me,iu as W,jd as he,ku as ge,la as _e,lf as ve,lu as ye,ma as be,md as xe,of as Se,ou as Ce,pa as we,pf as Te,pu as Ee,qn as De,qu as Oe,rf as ke,ru as Ae,td as G,tn as K,uu as je,vu as Me,wd as Ne,wf as Pe,xa as Fe,xu as Ie,ya as Le,yd as Re,zi as ze}from"./src-BTQcUQJz.js";import{t as Be}from"./boxes-CBxcgWPC.js";import{t as Ve}from"./user-round-9bUOIzu8.js";import{$n as q,$t as He,Qn as J,er as Y}from"./client-BBcQuaON.js";import{t as Ue}from"./useTranslation-Bc5yH9V9.js";import{$ as We,Y as X}from"./index-BlaisiEj.js";import{t as Ge}from"./AdminPage-BSFohA3i.js";var Ke=f(`circle-arrow-up`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 12-4-4-4 4`,key:`177agl`}],[`path`,{d:`M12 16V8`,key:`1sbj14`}]]);e();var qe={camera:c,hub:D,container:Be,light:Re,siren:P,switch:ne,sensor:L,thermostat:v,climate:Pe,button:B,"event-emitter":Ae,update:Ke,notifier:de,script:z,automation:Ce,lock:xe,cover:ve,valve:F,humidifier:k,"water-heater":he,fan:N,"media-player":ge,"alarm-panel":I,control:A,presence:Ve,weather:T,vacuum:le,"lawn-mower":Ie,image:g,smoke:_};function Z({type:e,className:t}){return o(qe[e]??B,{"aria-hidden":`true`,className:t??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function Je({online:e,deviceName:t}){return o(`span`,{className:e?`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-emerald-500`:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,role:`img`,"aria-label":`${t}: ${e?`online`:`offline`}`,title:e?`online`:`offline`})}function Ye({name:e,description:n,busy:r,onSave:i}){let[c,l]=a(n??``);return s(()=>{l(n??``)},[n]),t(`div`,{className:`border-t border-border px-3 py-2`,children:[o(`label`,{htmlFor:`location-description-${e}`,className:`block text-[10px] font-medium uppercase tracking-wide text-foreground-subtle`,children:`What is there`}),o(`textarea`,{id:`location-description-${e}`,value:c,onChange:e=>l(e.target.value),onBlur:()=>{let e=c.trim();e!==(n??``)&&i(e.length===0?null:e)},disabled:r,rows:2,maxLength:400,placeholder:`Surfaces, boundaries, what is normally parked or stored here.`,className:`mt-1 w-full resize-y rounded border border-border bg-background px-1.5 py-1 text-[11px] text-foreground placeholder:text-foreground-subtle disabled:opacity-50`}),o(`p`,{className:`mt-0.5 text-[10px] text-foreground-subtle`,children:`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 Xe(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0||n.description.length===0?null:n.description}var Q=` none`;function Ze({name:e,zones:n,zoneKey:r,busy:i,onChange:a}){return n.length===0?null:t(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5`,children:[o(`label`,{htmlFor:`location-zone-${e}`,className:`text-[10px] font-medium uppercase tracking-wide text-foreground-subtle`,children:`Zone`}),t(`select`,{id:`location-zone-${e}`,value:r??Q,disabled:i,onChange:e=>{let t=e.target.value;if(t===Q){a(null);return}let r=n.find(e=>e.zoneKey===t);r!==void 0&&a(r.label)},className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground disabled:opacity-50`,children:[o(`option`,{value:Q,children:`— none —`}),n.map(e=>o(`option`,{value:e.zoneKey,children:e.label},e.zoneKey))]})]})}function Qe(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}var $e={"map-pin":{icon:U,label:`Pin`},house:{icon:Ne,label:`Home`},"door-open":{icon:m,label:`Entrance`},sofa:{icon:p,label:`Living room`},utensils:{icon:Ee,label:`Kitchen`},"bed-double":{icon:Te,label:`Bedroom`},bath:{icon:pe,label:`Bathroom`},briefcase:{icon:Se,label:`Office`},car:{icon:ke,label:`Garage`},"circle-parking":{icon:ie,label:`Parking`},route:{icon:Oe,label:`Street`},trees:{icon:H,label:`Garden`},umbrella:{icon:Me,label:`Terrace`},"waves-ladder":{icon:ye,label:`Pool`},fence:{icon:M,label:`Gate`},package:{icon:se,label:`Storage`},warehouse:{icon:je,label:`Warehouse`},store:{icon:C,label:`Shop`},sun:{icon:R,label:`Outdoor`},radar:{icon:V,label:`Perimeter`}},et=J.map(e=>({id:e,...$e[e]}));function tt(e){return $e[Y(e)].icon}var nt=new Map(et.map(e=>[e.id,[e.label]])),rt=new Map(et.map(e=>[e.id,e.label])),it=new Set(J);function at(e){return it.has(e)?tt(e):void 0}function ot({name:e,icon:t,busy:n,onPick:r}){return o(E,{value:t,onPick:e=>r(e===null?null:Y(e)),resolveGlyph:at,fallbackGlyph:U,clearGlyph:oe,labelFor:e=>rt.get(e),labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,close:`Close icon picker`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`,groups:{device:`Devices`,lighting:`Lights and climate`,sensing:`Sensors and weather`,place:`Rooms and places`,life:`Vehicles, animals and people`}},only:J,extraWords:nt,disabled:n})}function st(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:Y(n.icon)}function $(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function ct(e,t){let n=$(t);return n===null?[]:e.filter(e=>$(e.location)===n)}function lt(e,t){let n=ct(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function ut(e,t){let n=$(e.location);return n===null||new Set(t.map(e=>$(e))).has(n)?null:e.location?.trim()??null}function dt(e,t){let n=$(e.location);return n!==null&&t.has(n)}function ft(e,t){let n=new Set(t.map(e=>$(e))),r=new Set(e.filter(e=>dt(e,n)).map(e=>e.id));return e.filter(e=>!(dt(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function pt(e,t){return ft(e,t).filter(e=>e.parentDeviceId===null)}function mt(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 ht(e,t){return mt(e,t).length}function gt(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function _t(e,t){return t.map(t=>({name:t,members:lt(e,t)}))}function vt(e){return`${e.kind}:${String(e.device.id)}`}function yt(e,t,n){return e.flatMap(e=>{let r=gt(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}))]})}e();function bt({name:e,members:i,devices:s,busy:c,icon:l,description:u,onRename:f,onDelete:p,onRebuildLinks:m,onPickIcon:h,onSaveDescription:g,zones:_,zoneKey:v,onChangeZone:y}){let{t:x}=Ue(),[C,T]=a(!1),[E,D]=a(e),k=S(i,n(()=>({searchText:e=>[e.name,...gt(s,e.id).map(e=>e.name)],facetValue:e=>e.type}),[s])),[A,j]=a(()=>new Set),M=e=>j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),ee=n(()=>yt(k.rows,s,A),[k.rows,s,A]),N=[{key:`name`,header:x(`locations.columns.device`),notSortableReason:x(`locations.columns.noSort`),render:e=>e.kind===`member`?o(xt,{row:e,onToggle:()=>M(e.device.id)}):o(St,{row:e})},{key:`type`,header:x(`locations.columns.type`),notSortableReason:x(`locations.columns.noSort`),render:e=>o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.device.type})},{key:`status`,header:x(`locations.columns.status`),notSortableReason:x(`locations.columns.noSort`),render:e=>t(`span`,{className:`flex items-center gap-1.5`,children:[o(Je,{online:e.device.online,deviceName:e.device.name}),o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.device.online?`online`:`offline`})]})}],P=()=>{D(e),T(!1)},F=async()=>{let t=E.trim();if(t.length===0||t===e){P();return}await f(t),T(!1)};return t(`section`,{className:`min-w-0 rounded-md border border-border bg-surface`,children:[t(`header`,{className:`flex items-center gap-1.5 border-b border-border px-3 py-1.5`,children:[o(ot,{name:e,icon:l,busy:c,onPick:h}),C?t(r,{children:[o(`input`,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&F(),e.key===`Escape`&&P()},"aria-label":`Rename ${e}`,className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-sm font-semibold text-foreground`,autoFocus:!0}),o(`button`,{type:`button`,onClick:()=>void F(),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Save`}),o(`button`,{type:`button`,onClick:P,"aria-label":`Cancel rename`,className:`p-0.5 text-foreground-subtle hover:text-foreground`,children:o(W,{className:`h-3.5 w-3.5`})})]}):t(r,{children:[o(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e}),o(O,{items:[{id:`rename`,label:`Rename`,icon:me,disabled:c,onClick:()=>{D(e),T(!0)}},{id:`rebuild-links`,label:`Rebuild linked devices`,icon:ae,separatorBefore:!0,disabled:c,onClick:()=>void m()},{id:`delete`,label:`Delete`,icon:d,danger:!0,separatorBefore:!0,disabled:c,onClick:()=>void p()}],title:`Actions for ${e}`,triggerClassName:`p-1`})]})]}),o(Ze,{name:e,zones:_,zoneKey:v,busy:c,onChange:y}),o(Ye,{name:e,description:u,busy:c,onSave:g}),i.length>0&&o(`div`,{className:`border-b border-border px-3 py-1.5`,children:o(b,{state:k.state,facets:k.facets,labels:{searchPlaceholder:x(`locations.filter.searchPlaceholder`),searchLabel:x(`locations.room.searchLabel`,{room:e}),facetsLabel:x(`locations.filter.typesLabel`),clearLabel:x(`locations.filter.clear`)},onSearch:k.setSearch,onToggleFacet:k.toggleFacet,onClear:k.clear})}),i.length===0?o(`p`,{className:`px-3 py-3 text-[11px] text-foreground-subtle`,children:`Nothing here yet — assign a device from the table below.`}):o(w,{columns:N,rows:ee,rowKey:vt,bordered:!1,minWidthPx:360,mobileMode:`scroll`,emptyMessage:x(`locations.filter.noMatch`)})]})}function xt({row:e,onToggle:n}){let{device:r,accessories:i,open:a}=e,s=a?l:u;return t(`span`,{className:`flex items-center gap-1.5`,children:[i.length>0?t(`button`,{type:`button`,onClick:n,"aria-expanded":a,"aria-label":`${a?`Collapse`:`Expand`} ${String(i.length)} companion device(s) of ${r.name}`,className:`flex shrink-0 items-center gap-0.5 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:[o(s,{className:`h-3 w-3`}),o(`span`,{className:`text-[10px] tabular-nums`,children:i.length})]}):o(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),o(Z,{type:r.type}),o(X,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:r.name})]})}function St({row:e}){let{device:n}=e;return t(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[o(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),o(Z,{type:n.type,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),o(X,{to:`/devices/${String(n.id)}`,className:`min-w-0 truncate text-[11px] text-foreground-muted hover:underline`,children:n.name})]})}e();function Ct({zones:e,busy:n,onCreate:r,onRename:i,onDelete:s,onPickIcon:c}){let[l,u]=a(!1),[f,p]=a(``),[m,h]=a(null),[g,_]=a(``),v=async()=>{let e=f.trim();e.length!==0&&(await r(e),p(``),u(!1))},y=async e=>{let t=g.trim();h(null),!(t.length===0||t===e)&&await i(e,t)};return t(`section`,{className:`rounded-md border border-border bg-surface`,children:[t(`header`,{className:`flex items-center gap-2 border-b border-border px-3 py-1.5`,children:[o(`h2`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Zones`}),l?null:t(`button`,{type:`button`,onClick:()=>u(!0),disabled:n,className:`flex items-center gap-1 text-[11px] text-foreground-muted hover:text-foreground disabled:opacity-50`,children:[o(G,{className:`h-3 w-3`}),` New zone`]})]}),l&&t(`div`,{className:`flex items-center gap-1.5 border-b border-border px-3 py-1.5`,children:[o(`input`,{value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&v(),e.key===`Escape`&&(p(``),u(!1))},placeholder:`Zona notte`,"aria-label":`New zone name`,autoFocus:!0,className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`}),o(`button`,{type:`button`,onClick:()=>void v(),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Add`}),o(`button`,{type:`button`,onClick:()=>{p(``),u(!1)},"aria-label":`Cancel new zone`,className:`p-0.5 text-foreground-subtle hover:text-foreground`,children:o(W,{className:`h-3.5 w-3.5`})})]}),e.length===0?o(`p`,{className:`px-3 py-2 text-[11px] text-foreground-subtle`,children:`No zones yet. A zone groups rooms — “Zona notte” for the bedrooms — and shows up before them in the app’s camera filter.`}):o(`ul`,{className:`py-0.5`,children:e.map(e=>t(`li`,{className:`flex items-center gap-1.5 px-3 py-1`,children:[o(ot,{name:e.label,icon:e.icon,busy:n,onPick:t=>c(e.label,t)}),m===e.label?o(`input`,{value:g,onChange:e=>_(e.target.value),onKeyDown:t=>{t.key===`Enter`&&y(e.label),t.key===`Escape`&&h(null)},onBlur:()=>void y(e.label),"aria-label":`Rename ${e.label}`,autoFocus:!0,className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`}):o(`button`,{type:`button`,onClick:()=>{_(e.label),h(e.label)},disabled:n,className:`min-w-0 flex-1 truncate text-left text-xs text-foreground hover:underline disabled:opacity-50`,children:e.label}),o(`span`,{className:`shrink-0 text-[10px] tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?`empty`:`${String(e.locationKeys.length)} rooms`}),o(`button`,{type:`button`,onClick:()=>void s(e.label),disabled:n,"aria-label":`Delete ${e.label}`,title:`Delete the zone — the rooms in it are kept`,className:`shrink-0 p-0.5 text-foreground-subtle hover:text-danger disabled:opacity-50`,children:o(d,{className:`h-3.5 w-3.5`})})]},e.zoneKey))})]})}e();function wt({busy:e,onCreate:n}){let[r,i]=a(!1),[s,c]=a(``),l=()=>{c(``),i(!1)},u=async()=>{let e=s.trim();e.length!==0&&(await n(e),l())};return r?t(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),u()},children:[o(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Escape`&&l()},placeholder:`Ingresso, Salone, Cucina…`,"aria-label":`New location name`,className:`min-w-[16rem] flex-1 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,autoFocus:!0}),t(`button`,{type:`submit`,disabled:s.trim().length===0||e,className:`inline-flex items-center gap-1 rounded border border-border bg-surface px-2 py-1.5 text-xs font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[o(G,{className:`h-3.5 w-3.5`}),`Add`]}),o(`button`,{type:`button`,onClick:l,"aria-label":`Cancel new location`,className:`p-1 text-foreground-subtle hover:text-foreground`,children:o(W,{className:`h-3.5 w-3.5`})})]}):t(`button`,{type:`button`,onClick:()=>i(!0),className:`inline-flex w-fit items-center gap-1 rounded border border-border bg-surface px-2 py-1.5 text-xs font-medium text-foreground hover:bg-surface-hover`,children:[o(G,{className:`h-3.5 w-3.5`}),`New location`]})}e();var Tt={searchText:e=>[e.name],facetValue:e=>e.type};function Et({rows:e,fleet:r,locations:i,busy:s,emptyMessage:c,onAssign:l}){let{t:u}=Ue(),[d,f]=a([]),[p,m]=a(``),h=S(e,Tt),g=h.rows,_=n(()=>g.map(e=>e.id),[g]),v=n(()=>d.filter(e=>_.includes(e)),[d,_]),y=g.length>0&&v.length===g.length,x=n(()=>{let t=new Map;for(let n of e)t.set(n.id,ht(r,n.id));return t},[e,r]),C=v.reduce((e,t)=>e+(x.get(t)??0),0),T=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),E=()=>f(y?[]:_);return t(`section`,{className:`space-y-2`,children:[t(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Not in a room`}),o(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Top-level devices only — accessories move with their parent.`})]}),e.length>0&&o(b,{state:h.state,facets:h.facets,labels:{searchPlaceholder:u(`locations.filter.searchPlaceholder`),searchLabel:u(`locations.unassigned.searchLabel`),facetsLabel:u(`locations.filter.typesLabel`),clearLabel:u(`locations.filter.clear`)},onSearch:h.setSearch,onToggleFacet:h.toggleFacet,onClear:h.clear}),v.length>0&&t(`div`,{role:`group`,"aria-label":`Bulk assignment`,className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[t(`span`,{className:`text-[11px] text-foreground`,children:[v.length,` selected`,C>0&&` · ${String(C)} accessories in tow`]}),t(`select`,{"aria-label":`Assign selected devices to`,value:p,onChange:e=>m(e.target.value),className:`rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground`,children:[o(`option`,{value:``,children:`Assign to…`}),i.map(e=>o(`option`,{value:e,children:e},e))]}),o(`button`,{type:`button`,onClick:()=>{p.length===0||v.length===0||(l(v,p),f([]),m(``))},disabled:s||p.length===0,className:`rounded border border-border bg-surface px-2 py-0.5 text-[11px] font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:`Assign`}),o(`button`,{type:`button`,onClick:()=>f([]),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),o(w,{columns:[{key:`select`,width:`w-8`,headerRender:()=>o(K,{checked:y,onChange:E,"aria-label":y?`Clear selection`:`Select all unassigned devices`}),render:e=>o(K,{checked:v.includes(e.id),onChange:()=>T(e.id),"aria-label":`Select ${e.name}`})},{key:`name`,header:`Device`,sortValue:e=>e.name.toLowerCase(),render:e=>{let n=ut(e,i);return t(`span`,{className:`flex items-center gap-1.5`,children:[o(Z,{type:e.type}),o(X,{to:`/devices/${String(e.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:e.name}),n!==null&&t(`span`,{className:`rounded-full border border-warning/40 px-1.5 py-px text-[10px] text-warning`,children:[`unknown room “`,n,`”`]})]})}},{key:`type`,header:`Type`,sortValue:e=>e.type,render:e=>o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.type})},{key:`status`,header:`Status`,sortValue:e=>+!!e.online,render:e=>t(`span`,{className:`flex items-center gap-1.5`,children:[o(Je,{online:e.online,deviceName:e.name}),o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.online?`online`:`offline`})]})},{key:`followers`,header:`Accessories in tow`,align:`right`,sortValue:e=>x.get(e.id)??0,render:e=>o(`span`,{className:`tabular-nums text-[11px] text-foreground-muted`,children:x.get(e.id)??0})},{key:`assign`,header:`Assign to`,align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>t(`select`,{"aria-label":`Location for ${e.name}`,value:``,disabled:s||i.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&l([e.id],n)},className:`max-w-[11rem] rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground disabled:opacity-50`,children:[o(`option`,{value:``,children:`—`}),i.map(e=>o(`option`,{value:e,children:e},e))]})}],rows:g,rowKey:e=>e.id,minWidthPx:720,mobileMode:`scroll`,emptyMessage:h.active?u(`locations.filter.noMatch`):c})]})}function Dt(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.role!==void 0&&e.role!==null?{role:e.role}:{},name:e.name}}function Ot(e,t){let n=t.map(Dt),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:He({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var kt=`device-manager:linked-devices`;function At(e){return{deviceId:e.deviceId,slotRef:kt,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}e();function jt(){let e=i(),r=De(),{data:a,isLoading:s}=we(),{data:c}=fe(),{data:l}=ue(),{data:u}=be(),{data:d,isLoading:f}=_e({projection:`slim`}),p=()=>{e.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},m=h({onSuccess:p}),g=Le({onSuccess:p}),_=re({onSuccess:p}),v=Fe({onSuccess:p}),b=y({onSuccess:p}),S=x({onSuccess:p}),C=j({onSuccess:p}),w=ce({onSuccess:p}),T=te({onSuccess:p}),E=ee({onSuccess:p}),D=ze(),O=n(()=>(d??[]).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})),[d]),k=a??[],A=n(()=>_t(O,k),[O,k]),[M,N]=We(),P=M.get(`room`),F=P!==null&&A.some(e=>e.name===P)?P:A[0]?.name??null,I=A.find(e=>e.name===F)??null,ne=e=>{N(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},L=n(()=>pt(O,k),[O,k]),R=s||f,z=_.isPending||g.isPending||m.isPending||b.isPending,B=async e=>{await m.mutateAsync({name:e})},ie=async(e,t)=>{let n=t.trim();n.length===0||n===e||await v.mutateAsync({from:e,to:n})},ae=async e=>{let t=Ot(e,O);if(t.entries.length===0){await r({title:`Rebuild linked devices`,message:`No camera is assigned to “${e}”.`,confirmLabel:`OK`});return}if(!await r({title:`Rebuild linked devices`,message:`Replace the linked-device list of every camera in “${e}” with what the room contains?\n\n${t.entries.map(e=>`• ${e.name}: ${String(e.ids.length)} device(s)`).join(`
1
+ import{Q as e,S as t,W as n,b as r,o as i,q as a,x as o,z as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as c,gt as l,ht as u,st as d,vt as f}from"./player-overlays-B7T46vDu.js";import{Au as p,Bd as m,Bi as h,Cd as g,Cf as _,Cu as v,Da as y,Dt as b,Ea as x,Et as S,Eu as C,Ft as w,Gd as T,Gl as E,Ku as D,L as O,Ld as k,Mu as A,Na as j,Nd as M,Oa as ee,Pd as N,Pu as P,Rd as F,Ru as I,Sa as te,Su as ne,Ta as re,Tf as L,Tu as R,Uu as z,Xd as B,Yd as ie,Yu as ae,Zu as V,_f as oe,ad as se,ba as ce,bu as H,cf as le,da as ue,df as de,fa as fe,fd as U,gf as pe,id as me,iu as W,jd as he,ku as ge,la as _e,lf as ve,lu as ye,ma as be,md as xe,of as Se,ou as Ce,pa as we,pf as Te,pu as Ee,qn as De,qu as Oe,rf as ke,ru as Ae,td as G,tn as K,uu as je,vu as Me,wd as Ne,wf as Pe,xa as Fe,xu as Ie,ya as Le,yd as Re,zi as ze}from"./src-QOexoM_4.js";import{t as Be}from"./boxes-CBxcgWPC.js";import{t as Ve}from"./user-round-9bUOIzu8.js";import{$n as q,$t as He,Qn as J,er as Y}from"./client-BBcQuaON.js";import{t as Ue}from"./useTranslation-Bc5yH9V9.js";import{$ as We,Y as X}from"./index-Wd9AuQ7z.js";import{t as Ge}from"./AdminPage-BSFohA3i.js";var Ke=f(`circle-arrow-up`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 12-4-4-4 4`,key:`177agl`}],[`path`,{d:`M12 16V8`,key:`1sbj14`}]]);e();var qe={camera:c,hub:D,container:Be,light:Re,siren:P,switch:ne,sensor:L,thermostat:v,climate:Pe,button:B,"event-emitter":Ae,update:Ke,notifier:de,script:z,automation:Ce,lock:xe,cover:ve,valve:F,humidifier:k,"water-heater":he,fan:N,"media-player":ge,"alarm-panel":I,control:A,presence:Ve,weather:T,vacuum:le,"lawn-mower":Ie,image:g,smoke:_};function Z({type:e,className:t}){return o(qe[e]??B,{"aria-hidden":`true`,className:t??`h-3.5 w-3.5 shrink-0 text-foreground-subtle`})}function Je({online:e,deviceName:t}){return o(`span`,{className:e?`inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-emerald-500`:`inline-block h-1.5 w-1.5 shrink-0 rounded-full border border-foreground-subtle`,role:`img`,"aria-label":`${t}: ${e?`online`:`offline`}`,title:e?`online`:`offline`})}function Ye({name:e,description:n,busy:r,onSave:i}){let[c,l]=a(n??``);return s(()=>{l(n??``)},[n]),t(`div`,{className:`border-t border-border px-3 py-2`,children:[o(`label`,{htmlFor:`location-description-${e}`,className:`block text-[10px] font-medium uppercase tracking-wide text-foreground-subtle`,children:`What is there`}),o(`textarea`,{id:`location-description-${e}`,value:c,onChange:e=>l(e.target.value),onBlur:()=>{let e=c.trim();e!==(n??``)&&i(e.length===0?null:e)},disabled:r,rows:2,maxLength:400,placeholder:`Surfaces, boundaries, what is normally parked or stored here.`,className:`mt-1 w-full resize-y rounded border border-border bg-background px-1.5 py-1 text-[11px] text-foreground placeholder:text-foreground-subtle disabled:opacity-50`}),o(`p`,{className:`mt-0.5 text-[10px] text-foreground-subtle`,children:`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 Xe(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0||n.description.length===0?null:n.description}var Q=` none`;function Ze({name:e,zones:n,zoneKey:r,busy:i,onChange:a}){return n.length===0?null:t(`div`,{className:`flex items-center gap-2 border-t border-border px-3 py-1.5`,children:[o(`label`,{htmlFor:`location-zone-${e}`,className:`text-[10px] font-medium uppercase tracking-wide text-foreground-subtle`,children:`Zone`}),t(`select`,{id:`location-zone-${e}`,value:r??Q,disabled:i,onChange:e=>{let t=e.target.value;if(t===Q){a(null);return}let r=n.find(e=>e.zoneKey===t);r!==void 0&&a(r.label)},className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground disabled:opacity-50`,children:[o(`option`,{value:Q,children:`— none —`}),n.map(e=>o(`option`,{value:e.zoneKey,children:e.label},e.zoneKey))]})]})}function Qe(e,t){return e.find(e=>e.locationKeys.includes(t))?.zoneKey??null}var $e={"map-pin":{icon:U,label:`Pin`},house:{icon:Ne,label:`Home`},"door-open":{icon:m,label:`Entrance`},sofa:{icon:p,label:`Living room`},utensils:{icon:Ee,label:`Kitchen`},"bed-double":{icon:Te,label:`Bedroom`},bath:{icon:pe,label:`Bathroom`},briefcase:{icon:Se,label:`Office`},car:{icon:ke,label:`Garage`},"circle-parking":{icon:ie,label:`Parking`},route:{icon:Oe,label:`Street`},trees:{icon:H,label:`Garden`},umbrella:{icon:Me,label:`Terrace`},"waves-ladder":{icon:ye,label:`Pool`},fence:{icon:M,label:`Gate`},package:{icon:se,label:`Storage`},warehouse:{icon:je,label:`Warehouse`},store:{icon:C,label:`Shop`},sun:{icon:R,label:`Outdoor`},radar:{icon:V,label:`Perimeter`}},et=J.map(e=>({id:e,...$e[e]}));function tt(e){return $e[Y(e)].icon}var nt=new Map(et.map(e=>[e.id,[e.label]])),rt=new Map(et.map(e=>[e.id,e.label])),it=new Set(J);function at(e){return it.has(e)?tt(e):void 0}function ot({name:e,icon:t,busy:n,onPick:r}){return o(E,{value:t,onPick:e=>r(e===null?null:Y(e)),resolveGlyph:at,fallbackGlyph:U,clearGlyph:oe,labelFor:e=>rt.get(e),labels:{trigger:`Change the icon of ${e}`,panel:`Icon for ${e}`,close:`Close icon picker`,searchPlaceholder:`Search icons`,clear:`No icon`,noMatches:`No icon matches that`,groups:{device:`Devices`,lighting:`Lights and climate`,sensing:`Sensors and weather`,place:`Rooms and places`,life:`Vehicles, animals and people`}},only:J,extraWords:nt,disabled:n})}function st(e,t){let n=e?.find(e=>e.locationKey===t);return n===void 0?null:Y(n.icon)}function $(e){if(e==null)return null;let t=e.trim();return t.length===0?null:t.toLowerCase()}function ct(e,t){let n=$(t);return n===null?[]:e.filter(e=>$(e.location)===n)}function lt(e,t){let n=ct(e,t),r=new Set(n.map(e=>e.id));return n.filter(e=>e.parentDeviceId===null||!r.has(e.parentDeviceId))}function ut(e,t){let n=$(e.location);return n===null||new Set(t.map(e=>$(e))).has(n)?null:e.location?.trim()??null}function dt(e,t){let n=$(e.location);return n!==null&&t.has(n)}function ft(e,t){let n=new Set(t.map(e=>$(e))),r=new Set(e.filter(e=>dt(e,n)).map(e=>e.id));return e.filter(e=>!(dt(e,n)||e.parentDeviceId!==null&&r.has(e.parentDeviceId)))}function pt(e,t){return ft(e,t).filter(e=>e.parentDeviceId===null)}function mt(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 ht(e,t){return mt(e,t).length}function gt(e,t){return e.filter(e=>!e.isCamera&&e.parentDeviceId===t)}function _t(e,t){return t.map(t=>({name:t,members:lt(e,t)}))}function vt(e){return`${e.kind}:${String(e.device.id)}`}function yt(e,t,n){return e.flatMap(e=>{let r=gt(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}))]})}e();function bt({name:e,members:i,devices:s,busy:c,icon:l,description:u,onRename:f,onDelete:p,onRebuildLinks:m,onPickIcon:h,onSaveDescription:g,zones:_,zoneKey:v,onChangeZone:y}){let{t:x}=Ue(),[C,T]=a(!1),[E,D]=a(e),k=S(i,n(()=>({searchText:e=>[e.name,...gt(s,e.id).map(e=>e.name)],facetValue:e=>e.type}),[s])),[A,j]=a(()=>new Set),M=e=>j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),ee=n(()=>yt(k.rows,s,A),[k.rows,s,A]),N=[{key:`name`,header:x(`locations.columns.device`),notSortableReason:x(`locations.columns.noSort`),render:e=>e.kind===`member`?o(xt,{row:e,onToggle:()=>M(e.device.id)}):o(St,{row:e})},{key:`type`,header:x(`locations.columns.type`),notSortableReason:x(`locations.columns.noSort`),render:e=>o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.device.type})},{key:`status`,header:x(`locations.columns.status`),notSortableReason:x(`locations.columns.noSort`),render:e=>t(`span`,{className:`flex items-center gap-1.5`,children:[o(Je,{online:e.device.online,deviceName:e.device.name}),o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.device.online?`online`:`offline`})]})}],P=()=>{D(e),T(!1)},F=async()=>{let t=E.trim();if(t.length===0||t===e){P();return}await f(t),T(!1)};return t(`section`,{className:`min-w-0 rounded-md border border-border bg-surface`,children:[t(`header`,{className:`flex items-center gap-1.5 border-b border-border px-3 py-1.5`,children:[o(ot,{name:e,icon:l,busy:c,onPick:h}),C?t(r,{children:[o(`input`,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&F(),e.key===`Escape`&&P()},"aria-label":`Rename ${e}`,className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-sm font-semibold text-foreground`,autoFocus:!0}),o(`button`,{type:`button`,onClick:()=>void F(),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Save`}),o(`button`,{type:`button`,onClick:P,"aria-label":`Cancel rename`,className:`p-0.5 text-foreground-subtle hover:text-foreground`,children:o(W,{className:`h-3.5 w-3.5`})})]}):t(r,{children:[o(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e}),o(O,{items:[{id:`rename`,label:`Rename`,icon:me,disabled:c,onClick:()=>{D(e),T(!0)}},{id:`rebuild-links`,label:`Rebuild linked devices`,icon:ae,separatorBefore:!0,disabled:c,onClick:()=>void m()},{id:`delete`,label:`Delete`,icon:d,danger:!0,separatorBefore:!0,disabled:c,onClick:()=>void p()}],title:`Actions for ${e}`,triggerClassName:`p-1`})]})]}),o(Ze,{name:e,zones:_,zoneKey:v,busy:c,onChange:y}),o(Ye,{name:e,description:u,busy:c,onSave:g}),i.length>0&&o(`div`,{className:`border-b border-border px-3 py-1.5`,children:o(b,{state:k.state,facets:k.facets,labels:{searchPlaceholder:x(`locations.filter.searchPlaceholder`),searchLabel:x(`locations.room.searchLabel`,{room:e}),facetsLabel:x(`locations.filter.typesLabel`),clearLabel:x(`locations.filter.clear`)},onSearch:k.setSearch,onToggleFacet:k.toggleFacet,onClear:k.clear})}),i.length===0?o(`p`,{className:`px-3 py-3 text-[11px] text-foreground-subtle`,children:`Nothing here yet — assign a device from the table below.`}):o(w,{columns:N,rows:ee,rowKey:vt,bordered:!1,minWidthPx:360,mobileMode:`scroll`,emptyMessage:x(`locations.filter.noMatch`)})]})}function xt({row:e,onToggle:n}){let{device:r,accessories:i,open:a}=e,s=a?l:u;return t(`span`,{className:`flex items-center gap-1.5`,children:[i.length>0?t(`button`,{type:`button`,onClick:n,"aria-expanded":a,"aria-label":`${a?`Collapse`:`Expand`} ${String(i.length)} companion device(s) of ${r.name}`,className:`flex shrink-0 items-center gap-0.5 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:[o(s,{className:`h-3 w-3`}),o(`span`,{className:`text-[10px] tabular-nums`,children:i.length})]}):o(`span`,{"aria-hidden":`true`,className:`w-[1.35rem] shrink-0`}),o(Z,{type:r.type}),o(X,{to:`/devices/${String(r.id)}`,className:`min-w-0 truncate text-xs text-foreground hover:underline`,children:r.name})]})}function St({row:e}){let{device:n}=e;return t(`span`,{className:`flex items-center gap-1.5 pl-6`,children:[o(`span`,{"aria-hidden":`true`,className:`text-[10px] text-foreground-subtle`,children:`└`}),o(Z,{type:n.type,className:`h-3 w-3 shrink-0 text-foreground-subtle`}),o(X,{to:`/devices/${String(n.id)}`,className:`min-w-0 truncate text-[11px] text-foreground-muted hover:underline`,children:n.name})]})}e();function Ct({zones:e,busy:n,onCreate:r,onRename:i,onDelete:s,onPickIcon:c}){let[l,u]=a(!1),[f,p]=a(``),[m,h]=a(null),[g,_]=a(``),v=async()=>{let e=f.trim();e.length!==0&&(await r(e),p(``),u(!1))},y=async e=>{let t=g.trim();h(null),!(t.length===0||t===e)&&await i(e,t)};return t(`section`,{className:`rounded-md border border-border bg-surface`,children:[t(`header`,{className:`flex items-center gap-2 border-b border-border px-3 py-1.5`,children:[o(`h2`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Zones`}),l?null:t(`button`,{type:`button`,onClick:()=>u(!0),disabled:n,className:`flex items-center gap-1 text-[11px] text-foreground-muted hover:text-foreground disabled:opacity-50`,children:[o(G,{className:`h-3 w-3`}),` New zone`]})]}),l&&t(`div`,{className:`flex items-center gap-1.5 border-b border-border px-3 py-1.5`,children:[o(`input`,{value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&v(),e.key===`Escape`&&(p(``),u(!1))},placeholder:`Zona notte`,"aria-label":`New zone name`,autoFocus:!0,className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`}),o(`button`,{type:`button`,onClick:()=>void v(),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Add`}),o(`button`,{type:`button`,onClick:()=>{p(``),u(!1)},"aria-label":`Cancel new zone`,className:`p-0.5 text-foreground-subtle hover:text-foreground`,children:o(W,{className:`h-3.5 w-3.5`})})]}),e.length===0?o(`p`,{className:`px-3 py-2 text-[11px] text-foreground-subtle`,children:`No zones yet. A zone groups rooms — “Zona notte” for the bedrooms — and shows up before them in the app’s camera filter.`}):o(`ul`,{className:`py-0.5`,children:e.map(e=>t(`li`,{className:`flex items-center gap-1.5 px-3 py-1`,children:[o(ot,{name:e.label,icon:e.icon,busy:n,onPick:t=>c(e.label,t)}),m===e.label?o(`input`,{value:g,onChange:e=>_(e.target.value),onKeyDown:t=>{t.key===`Enter`&&y(e.label),t.key===`Escape`&&h(null)},onBlur:()=>void y(e.label),"aria-label":`Rename ${e.label}`,autoFocus:!0,className:`min-w-0 flex-1 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`}):o(`button`,{type:`button`,onClick:()=>{_(e.label),h(e.label)},disabled:n,className:`min-w-0 flex-1 truncate text-left text-xs text-foreground hover:underline disabled:opacity-50`,children:e.label}),o(`span`,{className:`shrink-0 text-[10px] tabular-nums text-foreground-subtle`,children:e.locationKeys.length===0?`empty`:`${String(e.locationKeys.length)} rooms`}),o(`button`,{type:`button`,onClick:()=>void s(e.label),disabled:n,"aria-label":`Delete ${e.label}`,title:`Delete the zone — the rooms in it are kept`,className:`shrink-0 p-0.5 text-foreground-subtle hover:text-danger disabled:opacity-50`,children:o(d,{className:`h-3.5 w-3.5`})})]},e.zoneKey))})]})}e();function wt({busy:e,onCreate:n}){let[r,i]=a(!1),[s,c]=a(``),l=()=>{c(``),i(!1)},u=async()=>{let e=s.trim();e.length!==0&&(await n(e),l())};return r?t(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),u()},children:[o(`input`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Escape`&&l()},placeholder:`Ingresso, Salone, Cucina…`,"aria-label":`New location name`,className:`min-w-[16rem] flex-1 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,autoFocus:!0}),t(`button`,{type:`submit`,disabled:s.trim().length===0||e,className:`inline-flex items-center gap-1 rounded border border-border bg-surface px-2 py-1.5 text-xs font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[o(G,{className:`h-3.5 w-3.5`}),`Add`]}),o(`button`,{type:`button`,onClick:l,"aria-label":`Cancel new location`,className:`p-1 text-foreground-subtle hover:text-foreground`,children:o(W,{className:`h-3.5 w-3.5`})})]}):t(`button`,{type:`button`,onClick:()=>i(!0),className:`inline-flex w-fit items-center gap-1 rounded border border-border bg-surface px-2 py-1.5 text-xs font-medium text-foreground hover:bg-surface-hover`,children:[o(G,{className:`h-3.5 w-3.5`}),`New location`]})}e();var Tt={searchText:e=>[e.name],facetValue:e=>e.type};function Et({rows:e,fleet:r,locations:i,busy:s,emptyMessage:c,onAssign:l}){let{t:u}=Ue(),[d,f]=a([]),[p,m]=a(``),h=S(e,Tt),g=h.rows,_=n(()=>g.map(e=>e.id),[g]),v=n(()=>d.filter(e=>_.includes(e)),[d,_]),y=g.length>0&&v.length===g.length,x=n(()=>{let t=new Map;for(let n of e)t.set(n.id,ht(r,n.id));return t},[e,r]),C=v.reduce((e,t)=>e+(x.get(t)??0),0),T=e=>f(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),E=()=>f(y?[]:_);return t(`section`,{className:`space-y-2`,children:[t(`header`,{className:`flex flex-wrap items-baseline gap-2`,children:[o(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Not in a room`}),o(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Top-level devices only — accessories move with their parent.`})]}),e.length>0&&o(b,{state:h.state,facets:h.facets,labels:{searchPlaceholder:u(`locations.filter.searchPlaceholder`),searchLabel:u(`locations.unassigned.searchLabel`),facetsLabel:u(`locations.filter.typesLabel`),clearLabel:u(`locations.filter.clear`)},onSearch:h.setSearch,onToggleFacet:h.toggleFacet,onClear:h.clear}),v.length>0&&t(`div`,{role:`group`,"aria-label":`Bulk assignment`,className:`flex flex-wrap items-center gap-2 rounded border border-primary/40 bg-primary/5 px-2 py-1.5`,children:[t(`span`,{className:`text-[11px] text-foreground`,children:[v.length,` selected`,C>0&&` · ${String(C)} accessories in tow`]}),t(`select`,{"aria-label":`Assign selected devices to`,value:p,onChange:e=>m(e.target.value),className:`rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground`,children:[o(`option`,{value:``,children:`Assign to…`}),i.map(e=>o(`option`,{value:e,children:e},e))]}),o(`button`,{type:`button`,onClick:()=>{p.length===0||v.length===0||(l(v,p),f([]),m(``))},disabled:s||p.length===0,className:`rounded border border-border bg-surface px-2 py-0.5 text-[11px] font-medium text-foreground hover:bg-surface-hover disabled:opacity-50`,children:`Assign`}),o(`button`,{type:`button`,onClick:()=>f([]),className:`text-[11px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),o(w,{columns:[{key:`select`,width:`w-8`,headerRender:()=>o(K,{checked:y,onChange:E,"aria-label":y?`Clear selection`:`Select all unassigned devices`}),render:e=>o(K,{checked:v.includes(e.id),onChange:()=>T(e.id),"aria-label":`Select ${e.name}`})},{key:`name`,header:`Device`,sortValue:e=>e.name.toLowerCase(),render:e=>{let n=ut(e,i);return t(`span`,{className:`flex items-center gap-1.5`,children:[o(Z,{type:e.type}),o(X,{to:`/devices/${String(e.id)}`,className:`truncate text-xs text-foreground hover:underline`,children:e.name}),n!==null&&t(`span`,{className:`rounded-full border border-warning/40 px-1.5 py-px text-[10px] text-warning`,children:[`unknown room “`,n,`”`]})]})}},{key:`type`,header:`Type`,sortValue:e=>e.type,render:e=>o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.type})},{key:`status`,header:`Status`,sortValue:e=>+!!e.online,render:e=>t(`span`,{className:`flex items-center gap-1.5`,children:[o(Je,{online:e.online,deviceName:e.name}),o(`span`,{className:`text-[11px] text-foreground-muted`,children:e.online?`online`:`offline`})]})},{key:`followers`,header:`Accessories in tow`,align:`right`,sortValue:e=>x.get(e.id)??0,render:e=>o(`span`,{className:`tabular-nums text-[11px] text-foreground-muted`,children:x.get(e.id)??0})},{key:`assign`,header:`Assign to`,align:`right`,notSortableReason:`This column is a control, not a value.`,render:e=>t(`select`,{"aria-label":`Location for ${e.name}`,value:``,disabled:s||i.length===0,onChange:t=>{let n=t.target.value;n.length!==0&&l([e.id],n)},className:`max-w-[11rem] rounded border border-border bg-background px-1.5 py-0.5 text-[11px] text-foreground disabled:opacity-50`,children:[o(`option`,{value:``,children:`—`}),i.map(e=>o(`option`,{value:e,children:e},e))]})}],rows:g,rowKey:e=>e.id,minWidthPx:720,mobileMode:`scroll`,emptyMessage:h.active?u(`locations.filter.noMatch`):c})]})}function Dt(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.role!==void 0&&e.role!==null?{role:e.role}:{},name:e.name}}function Ot(e,t){let n=t.map(Dt),r=[];for(let i of t)i.isCamera&&i.location===e&&r.push({deviceId:i.id,name:i.name,ids:He({selfId:i.id,selfLocation:i.location,candidates:n})});return{entries:r}}var kt=`device-manager:linked-devices`;function At(e){return{deviceId:e.deviceId,slotRef:kt,value:{slot:`linked-devices`,deviceIds:[...e.ids]}}}e();function jt(){let e=i(),r=De(),{data:a,isLoading:s}=we(),{data:c}=fe(),{data:l}=ue(),{data:u}=be(),{data:d,isLoading:f}=_e({projection:`slim`}),p=()=>{e.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listLocationIcons`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listLocationDescriptions`]]}),e.invalidateQueries({queryKey:[[`deviceManager`,`listSiteZones`]]})},m=h({onSuccess:p}),g=Le({onSuccess:p}),_=re({onSuccess:p}),v=Fe({onSuccess:p}),b=y({onSuccess:p}),S=x({onSuccess:p}),C=j({onSuccess:p}),w=ce({onSuccess:p}),T=te({onSuccess:p}),E=ee({onSuccess:p}),D=ze(),O=n(()=>(d??[]).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})),[d]),k=a??[],A=n(()=>_t(O,k),[O,k]),[M,N]=We(),P=M.get(`room`),F=P!==null&&A.some(e=>e.name===P)?P:A[0]?.name??null,I=A.find(e=>e.name===F)??null,ne=e=>{N(t=>{let n=new URLSearchParams(t);return n.set(`room`,e),n},{replace:!0})},L=n(()=>pt(O,k),[O,k]),R=s||f,z=_.isPending||g.isPending||m.isPending||b.isPending,B=async e=>{await m.mutateAsync({name:e})},ie=async(e,t)=>{let n=t.trim();n.length===0||n===e||await v.mutateAsync({from:e,to:n})},ae=async e=>{let t=Ot(e,O);if(t.entries.length===0){await r({title:`Rebuild linked devices`,message:`No camera is assigned to “${e}”.`,confirmLabel:`OK`});return}if(!await r({title:`Rebuild linked devices`,message:`Replace the linked-device list of every camera in “${e}” with what the room contains?\n\n${t.entries.map(e=>`• ${e.name}: ${String(e.ids.length)} device(s)`).join(`
2
2
  `)}\n\nAnything linked by hand that is not in this room is lost.`,confirmLabel:`Rebuild`,variant:`danger`}))return;let n=[];for(let e of t.entries)try{await D.mutateAsync(At(e))}catch(t){n.push(`• ${e.name}: ${t instanceof Error?t.message:String(t)}`)}p(),n.length>0&&await r({title:`Rebuild linked devices`,message:`Not rebuilt:\n\n${n.join(`
3
3
  `)}`,confirmLabel:`OK`})},V=async(e,t)=>{await r({title:`Delete location`,message:`Delete the location “${e}”?${t>0?` ${String(t)} device(s) will become unassigned.`:``}`,confirmLabel:`Delete`,variant:`danger`})&&await g.mutateAsync({name:e,cascade:!0})},oe=async(e,t)=>{await b.mutateAsync({location:e,icon:t})},se=async(e,t)=>{await S.mutateAsync({location:e,description:t})},H=u??[],le=async(e,t)=>{await E.mutateAsync({location:e,zone:t})};return t(Ge,{icon:U,title:`Locations`,subtitle:`Rooms and areas of the site. Assign any device here — storage disks are under Data → Storage.`,children:[o(wt,{busy:m.isPending,onCreate:B}),o(Ct,{zones:H,busy:z,onCreate:e=>C.mutateAsync({name:e}),onRename:(e,t)=>T.mutateAsync({from:e,to:t}),onDelete:e=>w.mutateAsync({name:e}),onPickIcon:(e,t)=>C.mutateAsync({name:e,icon:t})}),R&&o(`p`,{className:`text-xs text-foreground-subtle`,children:`Loading locations and devices…`}),A.length>0&&o(`div`,{role:`tablist`,"aria-label":`Locations`,className:`-mx-1 flex gap-1 overflow-x-auto px-1 pb-1`,children:A.map(e=>{let n=e.name===F,r=tt(st(c,q(e.name)));return t(`button`,{type:`button`,role:`tab`,"aria-selected":n,onClick:()=>ne(e.name),className:n?`shrink-0 whitespace-nowrap rounded-full border border-primary bg-primary/10 px-3 py-1 text-xs text-foreground`:`shrink-0 whitespace-nowrap rounded-full border border-border px-3 py-1 text-xs text-foreground-muted hover:bg-surface-hover`,children:[o(r,{className:`mr-1 inline h-3.5 w-3.5 align-text-bottom`}),e.name,` `,o(`span`,{className:`text-foreground-subtle tabular-nums`,children:e.members.length})]},e.name)})}),I!==null&&o(bt,{name:I.name,members:I.members,devices:O,busy:z,icon:st(c,q(I.name)),onPickIcon:e=>oe(I.name,e),description:Xe(l,q(I.name)),onSaveDescription:e=>se(I.name,e),zones:H,zoneKey:Qe(H,q(I.name)),onChangeZone:e=>le(I.name,e),onRename:e=>ie(I.name,e),onDelete:()=>V(I.name,ct(O,I.name).length),onRebuildLinks:()=>ae(I.name)},I.name),k.length===0&&!R&&o(`p`,{className:`text-xs text-foreground-subtle`,children:`No locations yet. Add Ingresso, Salone, Cucina…`}),o(Et,{rows:L,fleet:O,locations:k,busy:z,emptyMessage:R?`Loading…`:`Every top-level device has a room.`,onAssign:(e,t)=>{for(let n of e)_.mutate({deviceId:n,location:t})}})]})}export{jt as LocationsPage};
@@ -1 +1 @@
1
- import{Q as e,S as t,W as n,q as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as a,vt as o}from"./player-overlays-B7T46vDu.js";import{$c as s,Cr as c,Sr as l,Tf as u,Uu as d,Zl as f,gd as p,nf as m,tl as h,vt as g}from"./src-BTQcUQJz.js";import{t as _}from"./layers-DSe93_v-.js";import{t as v}from"./useTranslation-Bc5yH9V9.js";import{c as y,et as b,s as x}from"./index-BlaisiEj.js";import{t as S}from"./AdminPage-BSFohA3i.js";import{t as C}from"./AdminTabs-2smlNAE_.js";import{r as w,t as T}from"./AddonIntegrationBody-CLBlTXCr.js";import{n as E,t as D}from"./addon-display-names-BkwMrExv.js";var O=o(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),k=o(`timer-reset`,[[`path`,{d:`M10 2h4`,key:`n1abiw`}],[`path`,{d:`M12 14v-4`,key:`1evpnu`}],[`path`,{d:`M4 13a8 8 0 0 1 8-7 8 8 0 1 1-5.3 14L4 17.6`,key:`1ts96g`}],[`path`,{d:`M9 17H4v5`,key:`8t5av`}]]);e();var A=5e3,j=`log-destination`,M={"winston-logging":`Rotated log files on this node’s disk.`,"console-logging":`stdout / stderr of the node process.`,"loki-logging":`Pushes to a Grafana Loki instance. Off until enabled with a URL.`,"hub-forwarder":`Agent-only — forwards this node’s entries to the hub.`};function N(){let e=c({capName:`log-destination`},{refetchInterval:A}),t=l(void 0,{refetchInterval:A}),r=n(()=>D(t.data??[]),[t.data]),a=n(()=>{let e=new Map;for(let n of t.data??[]){let t=n.description,r=n.id;typeof r==`string`&&typeof t==`string`&&t.length>0&&e.set(r,t)}return e},[t.data]),o=n(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive,caption:a.get(e.addonId)??M[e.addonId]??``})),[e.data,r,a]);return i(w,{icon:d,title:`Destinations`,subtitle:`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another.`,groups:[{id:j,label:`Log destinations`,install:{capability:j,label:`Add destination`},entries:o.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:O,...E(e.isActive),render:()=>i(T,{addonId:e.addonId,displayName:e.displayName,capName:j,isActive:e.isActive,badges:e.caption.length>0?i(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.caption}):null})}))}],isLoading:e.isLoading,emptyTitle:`No log destinations registered`,emptyDescription:`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`})}e();var P=[12e4,3e5,6e5,18e5],F={"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 I(){let{t:e}=v(),n=s({},{refetchInterval:5e3}),a=h(),[o,c]=r(null),l=(e,t)=>{c(e),a.mutate({patch:{diagnostics:[{id:e,armMs:t}]}},{onSettled:()=>{c(null),n.refetch()}})},d=n.data?.activeWindows??[],f=n.data?.channels??[],m=n.data?.activeChannels??[],g=(e,t,r)=>{c(e),a.mutate({patch:{channels:[{channel:e,armMs:t,deviceIds:r}]}},{onSettled:()=>{c(null),n.refetch()}})};return t(S,{icon:u,title:e(`logging.diagnostics.title`,`Diagnostics`),subtitle:e(`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?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(p,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:d.map(e=>i(R,{window:e,busy:o===e.id,onArm:t=>l(e.id,t)},e.id))}),i(`h3`,{className:`mt-6 text-sm font-medium text-foreground`,children:e(`logging.diagnostics.channels`,`Component channels`)}),i(`p`,{className:`mb-2 max-w-3xl text-[11px] text-foreground-subtle`,children:e(`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?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.noChannels`,`No addon on this cluster declares a log channel, or none could be reached right now.`)}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:f.map(e=>i(L,{channel:e,state:m.find(t=>t.channel===e.name),busy:o===e.name,onArm:(t,n)=>g(e.name,t,n)},e.name))})]})}function L({channel:e,state:n,busy:o,onArm:s}){let{t:c}=v(),[l,u]=r(``),d=n?.armed===!0,f=()=>{let e=l.split(/[\s,+]+/).filter(e=>/^\d+$/.test(e)).map(e=>Number(e));return e.length>0?e:null};return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.name}),d?t(`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:[i(k,{className:`h-3 w-3`}),c(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:z(n?.remainingMs??0)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:c(`logging.diagnostics.disarmed`,`disarmed`)}),d&&n?.deviceIds!==null&&n?.deviceIds!==void 0&&t(`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:[i(a,{className:`h-3 w-3`}),n.deviceIds.join(`, `)]}),!e.perDevice&&i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:c(`logging.diagnostics.notPerCamera`,`not filterable per camera`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:e.description})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[e.perDevice&&i(`input`,{type:`text`,inputMode:`numeric`,value:l,disabled:o,onChange:e=>u(e.target.value),placeholder:c(`logging.diagnostics.camerasPlaceholder`,`all cameras`),className:`w-28 rounded border border-border bg-surface px-2 py-1 text-[11px] text-foreground`}),P.map(e=>i(`button`,{type:`button`,disabled:o,onClick:()=>s(e,f()),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:z(e)},e)),i(`button`,{type:`button`,disabled:o||!d,onClick:()=>s(0,null),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:c(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function R({window:e,busy:n,onArm:r}){let{t:a}=v();return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.id}),e.armed?t(`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:[i(k,{className:`h-3 w-3`}),a(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:z(e.remainingMs)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:a(`logging.diagnostics.disarmed`,`disarmed`)}),e.armed&&!e.persisted&&i(`span`,{className:`text-[10px] text-warning`,children:a(`logging.diagnostics.notPersisted`,`not persisted — will not survive a restart`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:F[e.id]??``})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[P.map(e=>i(`button`,{type:`button`,disabled:n,onClick:()=>r(e),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:z(e)},e)),i(`button`,{type:`button`,disabled:n||!e.armed,onClick:()=>r(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 z(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`}e();var B=[`debug`,`info`,`warn`,`error`],V=``,H=``;function U(){let{t:e}=v(),[a,o]=r(V),[c,l]=r(H),{nodes:u}=f(),d=n(()=>u.map(e=>({id:e.id,label:e.name||e.id})),[u]),m=s({...a===V?{}:{scopeNodeId:a},...c===H?{}:{scopeComponent:c}},{refetchInterval:15e3}),g=h(),y=m.data,b=g.isPending||m.isFetching,x=y?.channels??[],C=(e,t)=>{g.mutate({...e.nodeId===null?{}:{scopeNodeId:e.nodeId},...e.component===null?{}:{scopeComponent:e.component},patch:{level:t}},{onSuccess:()=>void m.refetch()})};return i(S,{icon:_,title:e(`logging.levels.title`,`Levels`),subtitle:e(`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:t(`div`,{className:`flex flex-wrap items-center gap-3`,children:[t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.scope`,`Scope`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground disabled:opacity-50`,value:a,disabled:c!==H,onChange:e=>o(e.target.value),children:[i(`option`,{value:V,children:e(`logging.levels.cluster`,`Cluster`)}),d.map(e=>i(`option`,{value:e.id,children:e.label},e.id))]})]}),t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.component`,`Component`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground`,value:c,onChange:e=>l(e.target.value),children:[i(`option`,{value:H,children:e(`logging.levels.noComponent`,`None`)}),x.map(e=>i(`option`,{value:e.name,children:e.name},e.name))]})]})]}),children:m.isLoading||y===void 0?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(p,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):t(`div`,{className:`space-y-3`,children:[i(G,{level:y.effective.level,source:y.effective.levelSource,persisted:y.persisted}),i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:y.explicit.layers.map(e=>i(K,{layer:e,inForce:e.scope===y.effective.levelSource,busy:b,onSet:t=>C(e,t),onClear:()=>C(e,null)},`${e.scope}:${e.nodeId??e.component??`cluster`}`))}),c!==H&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:x.find(e=>e.name===c)?.description??``}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`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.`)}),i(W,{days:y.opsLogRetentionDays,busy:b,onSet:e=>g.mutate({patch:{opsLogRetentionDays:e}},{onSuccess:()=>void m.refetch()})})]})})}function W({days:e,busy:n,onSet:r}){let{t:a}=v();return t(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-1`,children:[t(`label`,{className:`flex items-center justify-between gap-3`,children:[i(`span`,{className:`text-xs font-medium`,children:a(`logging.levels.opsLogRetention`,`Retention audit trail`)}),t(`span`,{className:`flex items-center gap-1.5`,children:[i(`input`,{type:`number`,min:0,max:3650,step:1,defaultValue:e,disabled:n,onBlur:t=>{let n=Number.parseInt(t.target.value,10);Number.isFinite(n)&&n!==e&&r(n)},className:`w-20 rounded border border-border bg-surface px-2 py-1 text-xs`}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`common.days`,`days`)})]})]}),i(`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 G({level:e,source:n,persisted:r}){let{t:a}=v();return t(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-xs text-foreground-subtle`,children:a(`logging.levels.effective`,`In force here`)}),i(`span`,{className:`rounded bg-primary/10 px-2 py-0.5 text-xs font-semibold text-primary`,children:e}),i(`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})})]}),!r&&i(`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 K({layer:e,inForce:n,busy:r,onSet:a,onClear:o}){let{t:s}=v();return t(`div`,{className:`flex flex-col gap-2 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.scope===`cluster`?s(`logging.levels.cluster`,`Cluster`):e.scope===`component`?e.component??``:e.nodeId??``}),n&&t(`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:[i(m,{className:`h-3 w-3`}),s(`logging.levels.inForce`,`in force`)]})]}),i(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:e.level===null?s(`logging.levels.inherits`,`inherits — nothing set at this layer`):s(`logging.levels.setHere`,`set here: {{level}}`,{level:e.level})})]}),t(`div`,{className:`flex shrink-0 items-center gap-1`,children:[B.map(t=>i(`button`,{type:`button`,disabled:r,onClick:()=>a(t),className:`rounded px-2 py-1 text-[11px] font-medium transition-colors disabled:opacity-50 ${e.level===t?`bg-primary text-primary-foreground`:`border border-border text-foreground-subtle hover:text-foreground`}`,children:t},t)),i(`button`,{type:`button`,disabled:r||e.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(){return i(S,{children:i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:i(g,{limit:500,maxHeight:`max-h-[calc(100vh-310px)]`,showScope:!0,showFilters:!0})})})}function J(){return i(`div`,{className:`flex flex-col p-4`,children:i(C,{tabs:[{id:`viewer`,label:`Viewer`,icon:b,content:i(q,{})},{id:y.logging.tab,label:`Destinations`,icon:d,content:i(N,{}),ownedParams:x},{id:`levels`,label:`Levels`,icon:_,content:i(U,{})},{id:`diagnostics`,label:`Diagnostics`,icon:u,content:i(I,{})}]})})}export{J as LogsPage};
1
+ import{Q as e,S as t,W as n,q as r,x as i}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{_t as a,vt as o}from"./player-overlays-B7T46vDu.js";import{$c as s,Cr as c,Sr as l,Tf as u,Uu as d,Zl as f,gd as p,nf as m,tl as h,vt as g}from"./src-QOexoM_4.js";import{t as _}from"./layers-DSe93_v-.js";import{t as v}from"./useTranslation-Bc5yH9V9.js";import{c as y,et as b,s as x}from"./index-Wd9AuQ7z.js";import{t as S}from"./AdminPage-BSFohA3i.js";import{t as C}from"./AdminTabs-C1o_WGDw.js";import{r as w,t as T}from"./AddonIntegrationBody-WZ-GmbiU.js";import{n as E,t as D}from"./addon-display-names-BkwMrExv.js";var O=o(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),k=o(`timer-reset`,[[`path`,{d:`M10 2h4`,key:`n1abiw`}],[`path`,{d:`M12 14v-4`,key:`1evpnu`}],[`path`,{d:`M4 13a8 8 0 0 1 8-7 8 8 0 1 1-5.3 14L4 17.6`,key:`1ts96g`}],[`path`,{d:`M9 17H4v5`,key:`8t5av`}]]);e();var A=5e3,j=`log-destination`,M={"winston-logging":`Rotated log files on this node’s disk.`,"console-logging":`stdout / stderr of the node process.`,"loki-logging":`Pushes to a Grafana Loki instance. Off until enabled with a URL.`,"hub-forwarder":`Agent-only — forwards this node’s entries to the hub.`};function N(){let e=c({capName:`log-destination`},{refetchInterval:A}),t=l(void 0,{refetchInterval:A}),r=n(()=>D(t.data??[]),[t.data]),a=n(()=>{let e=new Map;for(let n of t.data??[]){let t=n.description,r=n.id;typeof r==`string`&&typeof t==`string`&&t.length>0&&e.set(r,t)}return e},[t.data]),o=n(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive,caption:a.get(e.addonId)??M[e.addonId]??``})),[e.data,r,a]);return i(w,{icon:d,title:`Destinations`,subtitle:`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another.`,groups:[{id:j,label:`Log destinations`,install:{capability:j,label:`Add destination`},entries:o.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:O,...E(e.isActive),render:()=>i(T,{addonId:e.addonId,displayName:e.displayName,capName:j,isActive:e.isActive,badges:e.caption.length>0?i(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.caption}):null})}))}],isLoading:e.isLoading,emptyTitle:`No log destinations registered`,emptyDescription:`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`})}e();var P=[12e4,3e5,6e5,18e5],F={"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 I(){let{t:e}=v(),n=s({},{refetchInterval:5e3}),a=h(),[o,c]=r(null),l=(e,t)=>{c(e),a.mutate({patch:{diagnostics:[{id:e,armMs:t}]}},{onSettled:()=>{c(null),n.refetch()}})},d=n.data?.activeWindows??[],f=n.data?.channels??[],m=n.data?.activeChannels??[],g=(e,t,r)=>{c(e),a.mutate({patch:{channels:[{channel:e,armMs:t,deviceIds:r}]}},{onSettled:()=>{c(null),n.refetch()}})};return t(S,{icon:u,title:e(`logging.diagnostics.title`,`Diagnostics`),subtitle:e(`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?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(p,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:d.map(e=>i(R,{window:e,busy:o===e.id,onArm:t=>l(e.id,t)},e.id))}),i(`h3`,{className:`mt-6 text-sm font-medium text-foreground`,children:e(`logging.diagnostics.channels`,`Component channels`)}),i(`p`,{className:`mb-2 max-w-3xl text-[11px] text-foreground-subtle`,children:e(`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?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`logging.diagnostics.noChannels`,`No addon on this cluster declares a log channel, or none could be reached right now.`)}):i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:f.map(e=>i(L,{channel:e,state:m.find(t=>t.channel===e.name),busy:o===e.name,onArm:(t,n)=>g(e.name,t,n)},e.name))})]})}function L({channel:e,state:n,busy:o,onArm:s}){let{t:c}=v(),[l,u]=r(``),d=n?.armed===!0,f=()=>{let e=l.split(/[\s,+]+/).filter(e=>/^\d+$/.test(e)).map(e=>Number(e));return e.length>0?e:null};return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.name}),d?t(`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:[i(k,{className:`h-3 w-3`}),c(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:z(n?.remainingMs??0)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:c(`logging.diagnostics.disarmed`,`disarmed`)}),d&&n?.deviceIds!==null&&n?.deviceIds!==void 0&&t(`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:[i(a,{className:`h-3 w-3`}),n.deviceIds.join(`, `)]}),!e.perDevice&&i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:c(`logging.diagnostics.notPerCamera`,`not filterable per camera`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:e.description})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[e.perDevice&&i(`input`,{type:`text`,inputMode:`numeric`,value:l,disabled:o,onChange:e=>u(e.target.value),placeholder:c(`logging.diagnostics.camerasPlaceholder`,`all cameras`),className:`w-28 rounded border border-border bg-surface px-2 py-1 text-[11px] text-foreground`}),P.map(e=>i(`button`,{type:`button`,disabled:o,onClick:()=>s(e,f()),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:z(e)},e)),i(`button`,{type:`button`,disabled:o||!d,onClick:()=>s(0,null),className:`rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-40`,children:c(`logging.diagnostics.disarm`,`Disarm`)})]})]})}function R({window:e,busy:n,onArm:r}){let{t:a}=v();return t(`div`,{className:`flex flex-col gap-2 p-3 lg:flex-row lg:items-center lg:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.id}),e.armed?t(`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:[i(k,{className:`h-3 w-3`}),a(`logging.diagnostics.expiresIn`,`expires in {{left}}`,{left:z(e.remainingMs)})]}):i(`span`,{className:`rounded border border-border px-1.5 py-0.5 text-[10px] text-foreground-subtle`,children:a(`logging.diagnostics.disarmed`,`disarmed`)}),e.armed&&!e.persisted&&i(`span`,{className:`text-[10px] text-warning`,children:a(`logging.diagnostics.notPersisted`,`not persisted — will not survive a restart`)})]}),i(`p`,{className:`mt-0.5 max-w-2xl text-[11px] text-foreground-subtle`,children:F[e.id]??``})]}),t(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[P.map(e=>i(`button`,{type:`button`,disabled:n,onClick:()=>r(e),className:`rounded border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground disabled:opacity-50`,children:z(e)},e)),i(`button`,{type:`button`,disabled:n||!e.armed,onClick:()=>r(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 z(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`}e();var B=[`debug`,`info`,`warn`,`error`],V=``,H=``;function U(){let{t:e}=v(),[a,o]=r(V),[c,l]=r(H),{nodes:u}=f(),d=n(()=>u.map(e=>({id:e.id,label:e.name||e.id})),[u]),m=s({...a===V?{}:{scopeNodeId:a},...c===H?{}:{scopeComponent:c}},{refetchInterval:15e3}),g=h(),y=m.data,b=g.isPending||m.isFetching,x=y?.channels??[],C=(e,t)=>{g.mutate({...e.nodeId===null?{}:{scopeNodeId:e.nodeId},...e.component===null?{}:{scopeComponent:e.component},patch:{level:t}},{onSuccess:()=>void m.refetch()})};return i(S,{icon:_,title:e(`logging.levels.title`,`Levels`),subtitle:e(`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:t(`div`,{className:`flex flex-wrap items-center gap-3`,children:[t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.scope`,`Scope`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground disabled:opacity-50`,value:a,disabled:c!==H,onChange:e=>o(e.target.value),children:[i(`option`,{value:V,children:e(`logging.levels.cluster`,`Cluster`)}),d.map(e=>i(`option`,{value:e.id,children:e.label},e.id))]})]}),t(`label`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[e(`logging.levels.component`,`Component`),t(`select`,{className:`rounded border border-border bg-surface px-2 py-1 text-xs text-foreground`,value:c,onChange:e=>l(e.target.value),children:[i(`option`,{value:H,children:e(`logging.levels.noComponent`,`None`)}),x.map(e=>i(`option`,{value:e.name,children:e.name},e.name))]})]})]}),children:m.isLoading||y===void 0?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(p,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}):t(`div`,{className:`space-y-3`,children:[i(G,{level:y.effective.level,source:y.effective.levelSource,persisted:y.persisted}),i(`div`,{className:`rounded-lg border border-border bg-surface divide-y divide-border`,children:y.explicit.layers.map(e=>i(K,{layer:e,inForce:e.scope===y.effective.levelSource,busy:b,onSet:t=>C(e,t),onClear:()=>C(e,null)},`${e.scope}:${e.nodeId??e.component??`cluster`}`))}),c!==H&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:x.find(e=>e.name===c)?.description??``}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`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.`)}),i(W,{days:y.opsLogRetentionDays,busy:b,onSet:e=>g.mutate({patch:{opsLogRetentionDays:e}},{onSuccess:()=>void m.refetch()})})]})})}function W({days:e,busy:n,onSet:r}){let{t:a}=v();return t(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-1`,children:[t(`label`,{className:`flex items-center justify-between gap-3`,children:[i(`span`,{className:`text-xs font-medium`,children:a(`logging.levels.opsLogRetention`,`Retention audit trail`)}),t(`span`,{className:`flex items-center gap-1.5`,children:[i(`input`,{type:`number`,min:0,max:3650,step:1,defaultValue:e,disabled:n,onBlur:t=>{let n=Number.parseInt(t.target.value,10);Number.isFinite(n)&&n!==e&&r(n)},className:`w-20 rounded border border-border bg-surface px-2 py-1 text-xs`}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`common.days`,`days`)})]})]}),i(`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 G({level:e,source:n,persisted:r}){let{t:a}=v();return t(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-xs text-foreground-subtle`,children:a(`logging.levels.effective`,`In force here`)}),i(`span`,{className:`rounded bg-primary/10 px-2 py-0.5 text-xs font-semibold text-primary`,children:e}),i(`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})})]}),!r&&i(`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 K({layer:e,inForce:n,busy:r,onSet:a,onClear:o}){let{t:s}=v();return t(`div`,{className:`flex flex-col gap-2 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:e.scope===`cluster`?s(`logging.levels.cluster`,`Cluster`):e.scope===`component`?e.component??``:e.nodeId??``}),n&&t(`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:[i(m,{className:`h-3 w-3`}),s(`logging.levels.inForce`,`in force`)]})]}),i(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:e.level===null?s(`logging.levels.inherits`,`inherits — nothing set at this layer`):s(`logging.levels.setHere`,`set here: {{level}}`,{level:e.level})})]}),t(`div`,{className:`flex shrink-0 items-center gap-1`,children:[B.map(t=>i(`button`,{type:`button`,disabled:r,onClick:()=>a(t),className:`rounded px-2 py-1 text-[11px] font-medium transition-colors disabled:opacity-50 ${e.level===t?`bg-primary text-primary-foreground`:`border border-border text-foreground-subtle hover:text-foreground`}`,children:t},t)),i(`button`,{type:`button`,disabled:r||e.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(){return i(S,{children:i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:i(g,{limit:500,maxHeight:`max-h-[calc(100vh-310px)]`,showScope:!0,showFilters:!0})})})}function J(){return i(`div`,{className:`flex flex-col p-4`,children:i(C,{tabs:[{id:`viewer`,label:`Viewer`,icon:b,content:i(q,{})},{id:y.logging.tab,label:`Destinations`,icon:d,content:i(N,{}),ownedParams:x},{id:`levels`,label:`Levels`,icon:_,content:i(U,{})},{id:`diagnostics`,label:`Diagnostics`,icon:u,content:i(I,{})}]})})}export{J as LogsPage};